Index: vmcore/src/kernel_classes/javasrc/java/lang/Thread.java =================================================================== --- vmcore/src/kernel_classes/javasrc/java/lang/Thread.java (revision 574266) +++ vmcore/src/kernel_classes/javasrc/java/lang/Thread.java (working copy) @@ -97,6 +97,7 @@ */ boolean isAlive = false; + boolean alreadyDetached = false; //wjw /** * Thread's target - a Runnable object whose run * method should be invoked @@ -782,6 +783,12 @@ * @param uncaughtException uncaught exception or null */ void detach(Throwable uncaughtException) { + + synchronized (lock) + { + if (alreadyDetached) return; //wjw detach() was already called once before + } + try { if (uncaughtException != null) { getUncaughtExceptionHandler().uncaughtException(this, uncaughtException); @@ -791,6 +798,7 @@ synchronized(lock) { this.isAlive = false; lock.notifyAll(); + alreadyDetached = true; } } } Index: vmcore/src/init/vm_shutdown.cpp =================================================================== --- vmcore/src/init/vm_shutdown.cpp (revision 574297) +++ vmcore/src/init/vm_shutdown.cpp (working copy) @@ -89,6 +89,34 @@ } static void vm_shutdown_callback() { + +//wjw + int gc_disable_count; + + /// TOSS assert( !hythread_is_suspend_enabled() ); + hythread_t self = hythread_self(); + vm_thread_t vm_thread = jthread_self_vm_thread_unsafe(); + jthread jthr = vm_thread->java_thread; + + gc_disable_count = self->disable_count; + self->disable_count = 0; + apr_memory_rw_barrier(); + + jthread_detach(jthr); + + self->disable_count = gc_disable_count; + apr_memory_rw_barrier(); + +//wjw + + // TOSS /* 8888888888888888888888 + //vm_thread_t vm_thread = jthread_self_vm_thread_unsafe(); + //if (vm_thread) { + // if (vm_thread->java_thread) jthread_detach(vm_thread->java_thread); + //} + //wjw + // 88888888888888888888888888888 */ + hythread_exit(NULL); } Index: thread/src/thread_native_suspend.c =================================================================== --- thread/src/thread_native_suspend.c (revision 574266) +++ thread/src/thread_native_suspend.c (working copy) @@ -142,6 +142,7 @@ // restore disable_count value thread->disable_count = gc_disable_count; + apr_memory_rw_barrier(); //wjw return; } // thread_safe_point_impl Index: thread/src/thread_native_basic.c =================================================================== --- thread/src/thread_native_basic.c (revision 574297) +++ thread/src/thread_native_basic.c (working copy) @@ -806,27 +806,20 @@ if (lib->nondaemon_thread_count <= 0) { status = hymutex_unlock(&lib->TM_LOCK); - if (status != TM_ERROR_NONE) { - return status; - } - return TM_ERROR_ILLEGAL_STATE; + return status; } TRACE(("TM: nondaemons decreased, thread: %p count: %d\n", thread, lib->nondaemon_thread_count)); lib->nondaemon_thread_count--; - if (lib->nondaemon_thread_count - threads_to_keep <= 0) { - status = hycond_notify_all(&lib->nondaemon_thread_cond); - TRACE(("TM: nondaemons all dead, thread: %p count: %d\n", thread, - lib->nondaemon_thread_count)); - if (status != TM_ERROR_NONE) { - hymutex_unlock(&lib->TM_LOCK); - return status; - } - } status = hymutex_unlock(&lib->TM_LOCK); + + hycond_notify_all(&lib->nondaemon_thread_cond); + TRACE(("TM: nondaemons all dead, thread: %p count: %d\n", thread, + lib->nondaemon_thread_count)); + return status; } // hythread_countdown_nondaemon_threads