You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2007/12/27 13:22:12 UTC

svn commit: r607051 - in /harmony/enhanced/drlvm/trunk/vm: include/open/hythread_ext.h thread/src/hythr.def thread/src/hythr.exp thread/src/thread_native_basic.c vmcore/src/init/vm_shutdown.cpp

Author: gshimansky
Date: Thu Dec 27 04:22:11 2007
New Revision: 607051

URL: http://svn.apache.org/viewvc?rev=607051&view=rev
Log:
Applied patch from HARMONY-5349
[drlvm][thread] Thread.join() refactoring


Modified:
    harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h
    harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def
    harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h?rev=607051&r1=607050&r2=607051&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h Thu Dec 27 04:22:11 2007
@@ -309,11 +309,6 @@
     hycond_t condition;
 
     /**
-     * Event reserved for threads that invoke join.
-     */
-    hylatch_t join_event;
-
-    /**
      * Current conditional variable thread is waiting on (used for interrupting)
      */
     hycond_t *current_condition;
@@ -425,9 +420,6 @@
 IDATA VMCALL hythread_remove_from_group(hythread_t thread);
 void VMCALL hythread_set_self(hythread_t thread);
 UDATA VMCALL hythread_clear_interrupted_other(hythread_t thread);
-IDATA VMCALL hythread_join(hythread_t t);
-IDATA VMCALL hythread_join_timed(hythread_t t, I_64 millis, IDATA nanos);
-IDATA VMCALL hythread_join_interruptable(hythread_t t, I_64 millis, IDATA nanos);
 void VMCALL hythread_yield_other(hythread_t thread);
 IDATA VMCALL hythread_get_self_id();
 IDATA VMCALL hythread_get_id(hythread_t t);

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def?rev=607051&r1=607050&r2=607051&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def Thu Dec 27 04:22:11 2007
@@ -48,9 +48,6 @@
 hythread_global_unlock
 hythread_create_ex
 hythread_clear_interrupted_other
-hythread_join
-hythread_join_timed
-hythread_join_interruptable
 hythread_get_self_id
 hythread_get_id
 hythread_get_thread

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp?rev=607051&r1=607050&r2=607051&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp Thu Dec 27 04:22:11 2007
@@ -50,9 +50,6 @@
 hythread_global_unlock;
 hythread_create_ex;
 hythread_clear_interrupted_other;
-hythread_join;
-hythread_join_timed;
-hythread_join_interruptable;
 hythread_get_self_id;
 hythread_get_id;
 hythread_get_thread;

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c?rev=607051&r1=607050&r2=607051&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c Thu Dec 27 04:22:11 2007
@@ -276,10 +276,6 @@
     // Detach if thread is attached to group.
     hythread_remove_from_group(thread);
 
-    // Send join event to those threads who called join on this thread.
-    status = hylatch_count_down(thread->join_event);
-    assert(status == TM_ERROR_NONE);
-
     // FIXME - uncomment after TM state transition complete
     // release thread data
     //hythread_struct_release(thread);
@@ -289,40 +285,6 @@
 }
 
 /**
- * Waits until the selected thread finishes execution.
- *
- * @param[in] t thread to join
- */
-IDATA VMCALL hythread_join(hythread_t t) { 
-    return hylatch_wait(t->join_event);
-}
-/**
- * Waits until the selected thread finishes with specific timeout.
- *
- * @param[in] t a thread to wait for
- * @param[in] millis timeout in milliseconds to wait
- * @param[in] nanos timeout in nanoseconds to wait
- * @return TM_THREAD_TIMEOUT or 0 in case thread
- * was successfully joined.
- */
-IDATA VMCALL hythread_join_timed(hythread_t t, I_64 millis, IDATA nanos) { 
-    return hylatch_wait_timed(t->join_event, millis, nanos);
-}
-
-/**
- * Waits until the selected thread finishes with specific timeout.
- *
- * @param[in] t a thread to wait for
- * @param[in] millis timeout in milliseconds to wait
- * @param[in] nanos timeout in nanoseconds to wait
- * @return TM_THREAD_TIMEOUT or TM_THREAD_INTERRUPTED or 0 in case thread
- * was successfully joined.
- */
-IDATA VMCALL hythread_join_interruptable(hythread_t t, I_64 millis, IDATA nanos) { 
-    return hylatch_wait_interruptable(t->join_event, millis, nanos);
-}
-
-/**
  * Yield the processor.
  * 
  * @return none
@@ -638,8 +600,6 @@
     assert(new_thread);
     if (!new_thread->os_handle) {
         // Create thread primitives
-        status = hylatch_create(&new_thread->join_event, 1);
-        assert(status == TM_ERROR_NONE);
         status = hysem_create(&new_thread->resume_event, 0, 1);
         assert(status == TM_ERROR_NONE);
         status = hymutex_create(&new_thread->mutex, TM_MUTEX_NESTED);
@@ -666,8 +626,6 @@
     new_thread->state = TM_THREAD_STATE_NEW;
     hymutex_unlock(&new_thread->mutex);
 
-    status = hylatch_set(new_thread->join_event, 1);
-    assert(status == TM_ERROR_NONE);
     status = hysem_set(new_thread->resume_event, 0);
     assert(status == TM_ERROR_NONE);
 
@@ -683,9 +641,7 @@
 
     assert(thread);
 
-    // Eelease thread primitives
-    status = hylatch_destroy(thread->join_event);
-    assert(status == TM_ERROR_NONE);
+    // Release thread primitives
     status = hysem_destroy(thread->resume_event);
     assert(status == TM_ERROR_NONE);
     status = hymutex_destroy(&thread->mutex);

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?rev=607051&r1=607050&r2=607051&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp Thu Dec 27 04:22:11 2007
@@ -296,20 +296,16 @@
     return JNI_OK;
 }
 
+static hylatch_t shutdown_end;
+
 static IDATA vm_interrupt_process(void * data) {
-    vm_thread_t * threadBuf;
-    int i;
+    IDATA status = hylatch_wait(shutdown_end);
+    assert(status == TM_ERROR_NONE);
 
-    threadBuf = (vm_thread_t *)data;
-    i = 0;
-    // Join all threads.
-    while (threadBuf[i] != NULL) {
-        hythread_join((hythread_t)threadBuf[i]);
-        STD_FREE(threadBuf[i]);
-        i++;
-    }
+    status = hylatch_destroy(shutdown_end);
+    assert(status == TM_ERROR_NONE);
 
-    STD_FREE(threadBuf);
+    STD_FREE(data);
 
     // Return 130 to be compatible with RI.
     exit(130);
@@ -319,21 +315,19 @@
  * Initiates VM shutdown sequence.
  */
 static IDATA vm_interrupt_entry_point(void * data) {
-    JNIEnv * jni_env;
-    JavaVMAttachArgs args;
-    JavaVM * java_vm;
-    jint status;
-
-    java_vm = (JavaVM *)data;
-    args.version = JNI_VERSION_1_2;
-    args.group = NULL;
-    args.name = "InterruptionHandler";
+    JavaVM * java_vm = (JavaVM *)data;
+    JavaVMAttachArgs vm_args = {JNI_VERSION_1_2, "InterruptionHandler", NULL};
 
-    status = AttachCurrentThread(java_vm, (void **)&jni_env, &args);
+    JNIEnv * jni_env;
+    jint status = AttachCurrentThread(java_vm, (void **)&jni_env, &vm_args);
     if (status == JNI_OK) {
         exec_shutdown_sequence(jni_env);
         DetachCurrentThread(java_vm);
     }
+
+    IDATA hy_status = hylatch_count_down(shutdown_end);
+    assert(hy_status == TM_ERROR_NONE);
+
     return status;
 }
 
@@ -341,18 +335,13 @@
  * Release allocated resourses.
  */
 static IDATA vm_dump_process(void * data) {
-    vm_thread_t * threadBuf;
-    int i;
+    IDATA status = hylatch_wait(shutdown_end);
+    assert(status == TM_ERROR_NONE);
 
-    threadBuf = (vm_thread_t *)data;
-    i = 0;
-    // Join all threads and release allocated resources.
-    while (threadBuf[i] != NULL) {
-        hythread_join((hythread_t)threadBuf[i]);
-        STD_FREE(threadBuf[i]);
-        i++;
-    }
-    STD_FREE(threadBuf);
+    status = hylatch_destroy(shutdown_end);
+    assert(status == TM_ERROR_NONE);
+
+    STD_FREE(data);
 
     return TM_ERROR_NONE;
 }
@@ -361,23 +350,21 @@
  * Dumps all java stacks.
  */
 static IDATA vm_dump_entry_point(void * data) {
-    JNIEnv * jni_env;
-    JavaVMAttachArgs args;
-    JavaVM * java_vm;
-    jint status;
-
-    java_vm = (JavaVM *)data;
-    args.version = JNI_VERSION_1_2;
-    args.group = NULL;
-    args.name = "DumpHandler";
+    JavaVM * java_vm = (JavaVM *)data;
+    JavaVMAttachArgs vm_args = {JNI_VERSION_1_2, "DumpHandler", NULL};
 
-    status = AttachCurrentThread(java_vm, (void **)&jni_env, &args);
+    JNIEnv * jni_env;
+    jint status = AttachCurrentThread(java_vm, (void **)&jni_env, &vm_args);
     if (status == JNI_OK) {
         // TODO: specify particular VM to notify.
         jvmti_notify_data_dump_request();
         st_print_all(stdout);
         DetachCurrentThread(java_vm);
     }
+
+    IDATA hy_status = hylatch_count_down(shutdown_end);
+    assert(hy_status == TM_ERROR_NONE);
+
     return status;
 }
 
@@ -386,28 +373,32 @@
  * Shutdown all running VMs and terminate the process.
  */
 void vm_interrupt_handler(int UNREF x) {
-    JavaVM ** vmBuf;
-    vm_thread_t * threadBuf;
     int nVMs;
-    IDATA status;
-
-    status = JNI_GetCreatedJavaVMs(NULL, 0, &nVMs);
+    IDATA status = JNI_GetCreatedJavaVMs(NULL, 0, &nVMs);
     assert(nVMs <= 1);
-    if (status != JNI_OK)
+    if (status != JNI_OK) {
         return;
+    }
 
-    vmBuf = (JavaVM **) STD_MALLOC(nVMs * sizeof(JavaVM *));
+    JavaVM ** vmBuf = (JavaVM **) STD_MALLOC(nVMs * sizeof(JavaVM *)
+        + (nVMs + 1) * sizeof(vm_thread_t));
+    assert(vmBuf);
     status = JNI_GetCreatedJavaVMs(vmBuf, nVMs, &nVMs);
     assert(nVMs <= 1);
-    if (status != JNI_OK)
-        goto cleanup;
+    if (status != JNI_OK) {
+        STD_FREE(vmBuf);
+        return;
+    }
 
-    threadBuf = (vm_thread_t*) STD_MALLOC((nVMs + 1) * sizeof(vm_thread_t));
-    assert(threadBuf);
+    vm_thread_t *threadBuf = (vm_thread_t*)((char*)vmBuf + (nVMs * sizeof(JavaVM *)));
+
+    status = hylatch_create(&shutdown_end, nVMs);
+    assert(status == TM_ERROR_NONE);
 
     // Create a new thread for each VM to avoid scalability and deadlock problems.
     for (int i = 0; i < nVMs; i++) {
         threadBuf[i] = jthread_allocate_thread();
+        assert(threadBuf[i]);
         status = hythread_create_ex((hythread_t)threadBuf[i], NULL, 0, 0, NULL,
             vm_interrupt_entry_point, (void *)vmBuf[i]);
         assert(status == TM_ERROR_NONE);
@@ -415,14 +406,11 @@
 
     // spawn a new thread which will terminate the process.
     status = hythread_create(NULL, 0, 0, 0,
-        vm_interrupt_process, (void *)threadBuf);
+        vm_interrupt_process, (void *)vmBuf);
     assert(status == TM_ERROR_NONE);
 
     // set a NULL terminator
     threadBuf[nVMs] = NULL;
-
-cleanup:
-    STD_FREE(vmBuf);
 }
 
 /**
@@ -431,28 +419,31 @@
  */
 void vm_dump_handler(int UNREF x) {
     int nVMs;
-    vm_thread_t *threadBuf;
-
     jint status = JNI_GetCreatedJavaVMs(NULL, 0, &nVMs);
     assert(nVMs <= 1);
     if (status != JNI_OK)
         return;
 
-    JavaVM ** vmBuf = (JavaVM **) STD_MALLOC(nVMs * sizeof(JavaVM *));
+    JavaVM** vmBuf = (JavaVM **) STD_MALLOC(nVMs * sizeof(JavaVM *)
+        + (nVMs + 1) * sizeof(vm_thread_t));
+    assert(vmBuf);
     status = JNI_GetCreatedJavaVMs(vmBuf, nVMs, &nVMs);
     assert(nVMs <= 1);
     if (status != JNI_OK) {
-        goto cleanup;
+        STD_FREE(vmBuf);
+        return;
     }
 
-    threadBuf =
-        (vm_thread_t*)STD_MALLOC((nVMs + 1) * sizeof(vm_thread_t));
-    assert(threadBuf);
+    vm_thread_t *threadBuf = (vm_thread_t*)((char*)vmBuf + (nVMs * sizeof(JavaVM *)));
+
+    status = hylatch_create(&shutdown_end, nVMs);
+    assert(status == TM_ERROR_NONE);
 
     // Create a new thread for each VM to avoid scalability and deadlock problems.
     IDATA UNUSED hy_status;
     for (int i = 0; i < nVMs; i++) {
         threadBuf[i] = jthread_allocate_thread();
+        assert(threadBuf[i]);
         hy_status = hythread_create_ex((hythread_t)threadBuf[i],
             NULL, 0, 0, NULL, vm_dump_entry_point, (void *)vmBuf[i]);
         assert(hy_status == TM_ERROR_NONE);
@@ -462,9 +453,6 @@
 
     // spawn a new thread which will release resources.
     hy_status = hythread_create(NULL, 0, 0, 0,
-        vm_dump_process, (void *)threadBuf);
+        vm_dump_process, (void *)vmBuf);
     assert(hy_status == TM_ERROR_NONE);
-
-cleanup:
-    STD_FREE(vmBuf);
 }