From 42b73306488cfebdfc00f28bb585045156d138f6 Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Thu, 13 Sep 2007 17:09:28 +0400 Subject: [PATCH] Fix of isAlive during JVM TI THREAD_START event processing. Source of the bug is in independent java isAlive thread state and JVMTI, hythread state. This issue is planed to fix see HARMONY-4716 and HARMONY-4644. To fix test noted in the JIRA patch synchronizes java isAlive state with JVMTI, hythread state, before invoke jvmti_send_thread_start_end_event(1). --- .../kernel_classes/javasrc/java/lang/Thread.java | 8 ++++++++ vm/vmcore/src/thread/thread_java_basic.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java b/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java index ad7caff..d89a3db 100644 --- a/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java +++ b/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java @@ -294,6 +294,7 @@ public class Thread implements Runnable { long oldPointer = (oldRef == null) ? 0 : oldRef.getNativeAddr(); long newPointer = VMThreadManager.init(this, newRef, oldPointer); + if (newPointer == 0) { throw new OutOfMemoryError("Failed to create new thread"); } @@ -663,6 +664,13 @@ public class Thread implements Runnable { } } + void setAlive(boolean alive) { + synchronized (lock) { + this.isAlive = true; + lock.notifyAll(); + } + } + void runImpl() { synchronized (lock) { this.isAlive = true; diff --git a/vm/vmcore/src/thread/thread_java_basic.cpp b/vm/vmcore/src/thread/thread_java_basic.cpp index 842304b..66099ca 100644 --- a/vm/vmcore/src/thread/thread_java_basic.cpp +++ b/vm/vmcore/src/thread/thread_java_basic.cpp @@ -30,6 +30,7 @@ #include "cxxlog.h" static jmethodID jthread_get_run_method(JNIEnv * env, jthread java_thread); +static jmethodID jthread_get_set_alive_method(JNIEnv * env, jthread java_thread); static IDATA jthread_associate_native_and_java_thread(JNIEnv * env, jthread java_thread, hythread_t native_thread, jobject weak_ref); @@ -81,6 +82,9 @@ static IDATA HYTHREAD_PROC jthread_wrapper_proc(void *arg) } // Send Thread Start event. + assert(hythread_is_alive(native_thread)); + jni_env->CallVoidMethod(java_thread, + jthread_get_set_alive_method(jni_env, java_thread), true); jvmti_send_thread_start_end_event(1); jthread_start_count(); @@ -202,6 +206,7 @@ IDATA jthread_attach(JNIEnv *jni_env, jthread java_thread, jboolean daemon) } // Send Thread Start event. + assert(hythread_is_alive(native_thread)); jvmti_send_thread_start_end_event(1); jthread_start_count(); @@ -667,3 +672,16 @@ static jmethodID jthread_get_run_method(JNIEnv * env, jthread java_thread) return run_method; } // jthread_get_run_method +static jmethodID jthread_get_set_alive_method(JNIEnv * env, jthread java_thread) +{ + static jmethodID set_alive_method = NULL; + + TRACE("run method find enter"); + if (!set_alive_method) { + jclass clazz = env->GetObjectClass(java_thread); + set_alive_method = env->GetMethodID(clazz, "setAlive", "(Z)V"); + } + TRACE("run method find exit"); + return set_alive_method; +} // jthread_get_run_method + -- 1.5.0.3