Index: trunk/vm/gc_gen/src/common/gc_for_vm.cpp =================================================================== --- trunk/vm/gc_gen/src/common/gc_for_vm.cpp (revision 570024) +++ trunk/vm/gc_gen/src/common/gc_for_vm.cpp (working copy) @@ -195,7 +195,14 @@ void gc_force_gc() { vm_gc_lock_enum(); + // no matter how counter-intuitive, + // gc_force_gc() expects gc_enabled_status == disabled, + // but, obviously, at a GC safepoint. + // See gc-safety (aka suspend-safety) rules explained elsewhere + // -salikh 2005-05-12 + hythread_suspend_disable(); gc_reclaim_heap(p_global_gc, GC_CAUSE_RUNTIME_FORCE_GC); + hythread_suspend_enable(); vm_gc_unlock_enum(); } Index: trunk/vm/include/open/hythread_ext.h =================================================================== --- trunk/vm/include/open/hythread_ext.h (revision 570024) +++ trunk/vm/include/open/hythread_ext.h (working copy) @@ -412,6 +412,8 @@ thread = tm_self_tls; ((HyThread_public *)thread)->disable_count++; + + apr_memory_rw_barrier(); if (((HyThread_public *)thread)->request && ((HyThread_public *)thread)->disable_count == 1) { Index: trunk/vm/thread/src/thread_init.c =================================================================== --- trunk/vm/thread/src/thread_init.c (revision 570024) +++ trunk/vm/thread/src/thread_init.c (working copy) @@ -229,7 +229,7 @@ // meaning that the thread is safe for suspension saved_count = hythread_reset_suspend_disable(); r = hymutex_lock(&TM_LIBRARY->TM_LOCK); - if (r) return r; + assert(r == TM_ERROR_NONE); // make sure we do not get a global thread lock // while being requested to suspend @@ -237,15 +237,15 @@ // give up global thread lock before safepoint, // because this thread can be suspended at a safepoint r = hymutex_unlock(&TM_LIBRARY->TM_LOCK); - if (r) return r; + assert(r == TM_ERROR_NONE); hythread_safe_point(); r = hymutex_lock(&TM_LIBRARY->TM_LOCK); - if (r) return r; + assert(r == TM_ERROR_NONE); } // do not use hythread_set_suspend_disable() as we do not // want safe points happening under global lock - self->disable_count = saved_count; + hythread_set_suspend_disable(saved_count); return 0; } Index: trunk/vm/thread/src/thread_native_suspend.c =================================================================== --- trunk/vm/thread/src/thread_native_suspend.c (revision 570024) +++ trunk/vm/thread/src/thread_native_suspend.c (working copy) @@ -141,7 +141,7 @@ } while (thread->suspend_count); // restore disable_count value - thread->disable_count = gc_disable_count; + hythread_set_suspend_disable(gc_disable_count); return; } // thread_safe_point_impl @@ -392,7 +392,7 @@ } hythread_iterator_reset(&iter); - hythread_iterator_release(&iter); + //hythread_iterator_release(&iter); if (iter_ptr) { *iter_ptr = iter; } @@ -412,9 +412,13 @@ hythread_t self = tm_self_tls; hythread_t next; hythread_iterator_t iter; - iter = hythread_iterator_create(group); + //iter = hythread_iterator_create(group); + group = group == NULL ? TM_DEFAULT_GROUP : group; + iter = (hythread_iterator_t)group->thread_list->next; TRACE(("resume all threads")); + hythread_iterator_reset(&iter); + // send suspend requests to all threads while ((next = hythread_iterator_next(&iter)) != NULL) { if (next != self) { @@ -454,6 +458,8 @@ assert(count >= 0); self->disable_count = count; + apr_memory_rw_barrier(); + if (count && self->suspend_count) { thread_safe_point_impl(self); } Index: trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp =================================================================== --- trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp (revision 570024) +++ trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp (working copy) @@ -129,13 +129,6 @@ (JNIEnv *, jclass) { assert(hythread_is_suspend_enabled()); - // no matter how counter-intuitive, - // gc_force_gc() expects gc_enabled_status == disabled, - // but, obviously, at a GC safepoint. - // See gc-safety (aka suspend-safety) rules explained elsewhere - // -salikh 2005-05-12 - tmn_suspend_disable(); gc_force_gc(); - tmn_suspend_enable(); return; } Index: trunk/vm/vmcore/src/thread/thread_java_basic.cpp =================================================================== --- trunk/vm/vmcore/src/thread/thread_java_basic.cpp (revision 570024) +++ trunk/vm/vmcore/src/thread/thread_java_basic.cpp (working copy) @@ -57,6 +57,8 @@ jthread_threadattr_t data = *(jthread_threadattr_t*) arg; STD_FREE(arg); + hythread_global_lock(); + // Association should be already done. hythread_t native_thread = hythread_self(); assert(native_thread); @@ -84,6 +86,8 @@ jvmti_send_thread_start_end_event(1); jthread_start_count(); + hythread_global_unlock(); + if (data.proc != NULL) { data.proc(data.jvmti_env, jni_env, (void*)data.arg); } else { @@ -92,8 +96,12 @@ jthread_get_run_method(jni_env, java_thread), NULL); } + hythread_global_lock(); + status = jthread_detach(java_thread); + hythread_global_unlock(); + TRACE(("TM: Java thread finished: id=%d OS_handle=%p", hythread_get_id(native_thread), apr_os_thread_current()));