harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r485888 - in /harmony/enhanced/drlvm/trunk/vm/vmcore: include/ src/init/ src/jni/ src/jvmti/ src/thread/ src/util/win/
Date Mon, 11 Dec 2006 21:47:03 GMT
Author: gshimansky
Date: Mon Dec 11 13:47:02 2006
New Revision: 485888

URL: http://svn.apache.org/viewvc?view=rev&rev=485888
Log:
Applied HARMONY-2539 [drlvm][jvmti] DataDumpRequest event implementation

Tests passed on ubuntu6 x86, windows XP and Gentoo x86_64


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_direct.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_direct.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_direct.h?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_direct.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_direct.h Mon Dec 11 13:47:02 2006
@@ -132,6 +132,9 @@
 VMEXPORT void jvmti_process_native_method_bind_event(jmethodID method, 
     NativeCodePtr address, NativeCodePtr* new_address_ptr);
 void jvmti_clean_reclaimed_object_tags();
+void jvmti_create_event_thread();
+void jvmti_destroy_event_thread();
+void jvmti_notify_data_dump_request();
 
 #ifdef __cplusplus
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h Mon Dec 11 13:47:02 2006
@@ -149,10 +149,13 @@
     public:
         jint agent_counter;
         Lock_Manager TIenvs_lock;
-        Lock_Manager dcList_lock;
         VMBreakPoints* vm_brpt;
         hythread_tls_key_t TL_ti_enabled; //thread local TI flag
 
+        // TI event thread data
+        hythread_t event_thread;
+        hycond_t event_cond;
+
         DebugUtilsTI();
 
         ~DebugUtilsTI();
@@ -167,6 +170,10 @@
         void setEnabled();
         void setDisabled();
 
+        bool needCreateEventThread();
+        void enableEventThreadCreation();
+        void disableEventThreadCreation();
+
         bool isLocallyEnabled();
         void setLocallyEnabled();
         void setLocallyDisabled();
@@ -327,6 +334,7 @@
         Watch *access_watch_list;
         Watch *modification_watch_list;
         bool status;
+        bool need_create_event_thread;
         Agent* agents;
         TIEnv* p_TIenvs;
         jvmtiPhase phase;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp Mon Dec 11 13:47:02 2006
@@ -791,6 +791,12 @@
     } else {
         vm_env->finalizer_thread = NULL;
     }
+    if(vm_env->TI->isEnabled() && vm_env->TI->needCreateEventThread()
) {
+        vm_env->TI->TIenvs_lock._lock();
+        jvmti_create_event_thread();
+        vm_env->TI->disableEventThreadCreation();
+        vm_env->TI->TIenvs_lock._unlock();
+    }
 
     TRACE("initialization of system classes completed");
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp Mon Dec 11 13:47:02 2006
@@ -181,10 +181,11 @@
 }
 
 void quit_handler(int UNREF x) {
+    jvmti_notify_data_dump_request();
     if (interpreter_enabled()) {
-            dump_all_java_stacks();
+        dump_all_java_stacks();
     } else {
-            td_dump_all_threads(stderr); 
+        td_dump_all_threads(stderr);
     }
 }
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp Mon Dec 11 13:47:02 2006
@@ -1519,11 +1519,13 @@
     assert(jthread_self() != NULL);
 
     // Now JVMTIThread keeps global reference. Discared temporary global reference.
-   jni_env->DeleteGlobalRef(java_thread);
+    jni_env->DeleteGlobalRef(java_thread);
 
     // Send thread start event.
     // TODO: Thread start event should be sent before its initial method executes.
-    jvmti_send_thread_start_end_event(1);
+    // 20061207: psrebriy: ThreadStart event is already started in
+    //                     jthread_attach function
+    // jvmti_send_thread_start_end_event(1);
 
     return status == TM_ERROR_NONE ? JNI_OK : JNI_ERR;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp Mon Dec 11 13:47:02 2006
@@ -308,10 +308,13 @@
 }
 
 DebugUtilsTI::DebugUtilsTI() :
+    event_thread(NULL),
+    event_cond(NULL),
     agent_counter(1),
     access_watch_list(NULL),
     modification_watch_list(NULL),
     status(false),
+    need_create_event_thread(false),
     agents(NULL),
     p_TIenvs(NULL),
     MAX_NOTIFY_LIST(1000),
@@ -339,6 +342,7 @@
     ReleaseNotifyLists();
     hythread_tls_free(TL_ti_enabled);
     delete vm_brpt;
+    jvmti_destroy_event_thread();
     return;
 }
 
@@ -731,6 +735,20 @@
 
 void DebugUtilsTI::setDisabled() {
     this->status = false;
+    return;
+}
+
+bool DebugUtilsTI::needCreateEventThread() {
+    return need_create_event_thread;
+}
+
+void DebugUtilsTI::enableEventThreadCreation() {
+    need_create_event_thread = true;
+    return;
+}
+
+void DebugUtilsTI::disableEventThreadCreation() {
+    need_create_event_thread = false;
     return;
 }
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp Mon Dec 11 13:47:02 2006
@@ -164,6 +164,22 @@
     return false;
 }
 
+static inline bool
+check_event_is_disable( jvmtiEvent event_type,
+                        DebugUtilsTI *ti)
+{
+    for (TIEnv *ti_env = ti->getEnvironments(); ti_env;
+         ti_env = ti_env->next)
+    {
+        if (ti_env->global_events[event_type - JVMTI_MIN_EVENT_TYPE_VAL]
+            || ti_env->event_threads[event_type - JVMTI_MIN_EVENT_TYPE_VAL])
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
 /*
  * Set Event Notification Mode
  *
@@ -308,6 +324,7 @@
     else
         return JVMTI_ERROR_ILLEGAL_ARGUMENT;
 
+    DebugUtilsTI *ti = ((TIEnv *)env)->vm->vm_env->TI;
     if (event_enabled(event_type) != (jboolean)old_state) {
         if (interpreter_enabled())
             interpreter.interpreter_ti_set_notification_mode(event_type, !old_state);
@@ -315,8 +332,6 @@
         {
             if (JVMTI_EVENT_SINGLE_STEP == event_type)
             {
-                DebugUtilsTI *ti = ((TIEnv *)env)->vm->vm_env->TI;
-
                 if (JVMTI_ENABLE == mode && !ti->is_single_step_enabled())
                 {
                     TRACE2("jvmti.break.ss", "SingleStep event is enabled");
@@ -329,35 +344,32 @@
                 {
                     // Check that no environment has SingleStep enabled
                     LMAutoUnlock lock(&ti->TIenvs_lock);
-                    bool disable = true;
                     TRACE2("jvmti.break.ss",
                         "SingleStep event is disabled locally for env: "
                         << env);
-
-                    for (TIEnv *ti_env = ti->getEnvironments(); ti_env;
-                         ti_env = ti_env->next)
-                    {
-                        if (ti_env->global_events[JVMTI_EVENT_SINGLE_STEP -
-                                JVMTI_MIN_EVENT_TYPE_VAL] ||
-                            NULL != ti_env->event_threads[JVMTI_EVENT_SINGLE_STEP -
-                                JVMTI_MIN_EVENT_TYPE_VAL])
-                        {
-                            disable = false;
-                            break;
-                        }
-                    }
-
-                    if (disable)
-                    {
+                    bool disable = check_event_is_disable(JVMTI_EVENT_SINGLE_STEP, ti);
+                    if (disable) {
                         TRACE2("jvmti.break.ss", "SingleStep event is disabled");
                         jvmtiError errorCode = ti->jvmti_single_step_stop();
-
                         if (JVMTI_ERROR_NONE != errorCode)
                             return errorCode;
                     }
                 }
             }
         }
+        if( JVMTI_EVENT_DATA_DUMP_REQUEST == event_type ) {
+            if(JVMTI_ENABLE == mode) {
+                LMAutoUnlock lock(&ti->TIenvs_lock);
+                jvmti_create_event_thread();
+            } else {
+                LMAutoUnlock lock(&ti->TIenvs_lock);
+                bool disable =
+                    check_event_is_disable(JVMTI_EVENT_DATA_DUMP_REQUEST, ti);
+                if (disable) {
+                    jvmti_destroy_event_thread();
+                }
+            }
+        }
     }
 
     return JVMTI_ERROR_NONE;
@@ -2014,4 +2026,162 @@
         }
         ti_env = next_env;
     }
+}
+
+static void
+jvmti_process_data_dump_request()
+{
+    assert(hythread_is_suspend_enabled());
+    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
+    if( !ti->isEnabled() ) {
+        return;
+    }
+
+    //Checking current phase
+    jvmtiPhase phase = ti->getPhase();
+    if( ti->getPhase() != JVMTI_PHASE_LIVE ) {
+        return;
+    }
+    hythread_t thread = hythread_self();
+
+    TIEnv* next_env;
+    for (TIEnv* env = ti->getEnvironments(); env; env = next_env) {
+        next_env = env->next;
+
+        jvmtiEventDataDumpRequest callback = env->event_table.DataDumpRequest;
+
+        if( NULL == callback ) {
+            continue;
+        }
+
+        if( env->global_events[JVMTI_EVENT_DATA_DUMP_REQUEST
+                               - JVMTI_MIN_EVENT_TYPE_VAL] )
+        {
+            TRACE2("jvmti.event", "Calling global DataDumpRequest event");
+            callback((jvmtiEnv*)env);
+            continue;
+        }
+
+        TIEventThread *first_et =
+            env->event_threads[JVMTI_EVENT_DATA_DUMP_REQUEST - JVMTI_MIN_EVENT_TYPE_VAL];
+        for( TIEventThread *et = first_et; NULL != et; et = et->next )
+        {
+            if( et->thread == thread ) {
+                TRACE2("jvmti.event", "Calling local DataDumpRequest event");
+                callback((jvmtiEnv*)env);
+            }
+        }
+    }
+}
+
+static int VMCALL
+jvmti_event_thread_function(void *args)
+{
+    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
+    JNIEnv* jni_env = (JNIEnv*)args;
+    JavaVM* java_vm;
+    jni_env->GetJavaVM(&java_vm);
+
+    // attaching native thread to VM
+    JavaVMAttachArgs vm_args = {JNI_VERSION_1_2, "TIEventThread", NULL};
+    int status = AttachCurrentThreadAsDaemon(java_vm, (void**)&jni_env, &vm_args);
+    if(status != JNI_OK) {
+        DIE("jvmti_event_thread_function: cannot attach current thread");
+    }
+
+    assert(hythread_is_suspend_enabled());
+
+    // create wait loop environment
+    hymutex_t event_mutex;
+    UNREF IDATA stat = hymutex_create(&event_mutex, TM_MUTEX_NESTED);
+    assert(stat == TM_ERROR_NONE);
+    hycond_t event_cond;
+    stat = hycond_create(&event_cond);
+    assert(stat == TM_ERROR_NONE);
+    ti->event_cond = event_cond;
+
+    // event thread loop
+    while(true) {
+        hymutex_lock(event_mutex);
+        hycond_wait(event_cond, event_mutex);
+        hymutex_unlock(event_mutex);
+
+        if(!ti->event_thread) {
+            // event thread is NULL,
+            // it's time to terminate the current thread
+            break;
+        }
+
+        // process data dump request
+        jvmti_process_data_dump_request();
+    }
+
+    // release wait loop environment
+    stat = hymutex_destroy(event_mutex);
+    assert(stat == TM_ERROR_NONE);
+    stat = hycond_destroy(event_cond);
+    assert(stat == TM_ERROR_NONE);
+
+    return 0;
+}
+
+void
+jvmti_create_event_thread()
+{
+    // IMPORTANT: The function is called under TIenvs_lock
+    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
+    if(ti->event_thread) {
+        // event thread is already created
+        return;
+    }
+
+    if(ti->getPhase() < JVMTI_PHASE_LIVE) {
+        ti->enableEventThreadCreation();
+        return;
+    }
+
+    // create TI event thread
+    JNIEnv *jni_env = p_TLS_vmthread->jni_env;
+    IDATA status = hythread_create(&ti->event_thread, 0, 0, 0,
+        jvmti_event_thread_function, jni_env);
+    if( status != TM_ERROR_NONE ) {
+        DIE("jvmti_create_event_thread: creating thread is failed!");
+    }
+    return;
+}
+
+void
+jvmti_destroy_event_thread()
+{
+    // IMPORTANT: The function is called under TIenvs_lock
+    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
+    if(!ti->event_thread) {
+        // event thread is already destroyed
+        return;
+    }
+
+    // getting condition
+    hycond_t event_cond = ti->event_cond;
+    ti->event_thread = NULL;
+    ti->event_cond = NULL;
+
+    // notify event thread
+    assert(event_cond);
+    UNREF IDATA stat = hycond_notify(event_cond);
+    assert(stat == TM_ERROR_NONE);
+    return;
+}
+
+void
+jvmti_notify_data_dump_request()
+{
+    DebugUtilsTI *ti = VM_Global_State::loader_env->TI;
+    if( !ti->event_thread || !ti->event_cond ) {
+        // nothing to do
+        return;
+    }
+    assert(ti->event_cond);
+    UNREF IDATA stat = hycond_notify(ti->event_cond);
+    assert(stat == TM_ERROR_NONE);
+    return;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp Mon Dec 11 13:47:02
2006
@@ -149,6 +149,7 @@
 }
 
 IDATA jthread_throw_exception(char* name, char* message) {
+    assert(hythread_is_suspend_enabled());
     jobject jthe = exn_create(name);
     return jthread_throw_exception_object(jthe);
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp?view=diff&rev=485888&r1=485887&r2=485888
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp Mon Dec 11 13:47:02
2006
@@ -35,7 +35,7 @@
 #include "exception_filter.h"
 
 BOOL ctrl_handler(DWORD ctrlType) 
-{ 
+{
     switch (ctrlType) 
     { 
     case CTRL_BREAK_EVENT:



Mime
View raw message