harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Salikh Zakirov <Salikh.Zaki...@Intel.com>
Subject Re: [drlvm] stress.Mix / MegaSpawn threading bug
Date Thu, 11 Jan 2007 18:30:43 GMT
Gregory Shimansky wrote:
> Today investigation of the hanging threads at shutdown have 2 different
> reasons. 1st one was found by Salikh and he wrote his comments in
> HARMONY-2963. The bug happened because the counter of non-daemon threads
> increased before a thread was created. If a thread failed to be created
> because of no memory, this counter was not updated.
> 
> Another reason for hanging threads is that they wait in Thread.start().
> When a new thread is started, it has to notify a lock object, in order
> to signal the parent thread that it has been created. This notification
> is sent from java code of the Thread before user code is executed.
> 
> But thread manager has some native code too which is ran before java
> code of the newly started thread. This native code tried to set up some
> thread state like new JNI environment and other stuff, and this requires
> allocation of new memory. If allocation of new memory fails, this native
> code of the newly created thread tries to return an error which is not
> seen anywhere (since this is the code which is the first function of the
> new thread), so it is not noticed. But since native code of the new
> thread finishes silently, it never runs the Java code which should do
> monitor notification, so monitor is not notified. So the parent thread
> just waits infinitely.

For the record, the following fix changes VM behaviour from silently
ignoring errors during late thread startup to assertion.
(so the MegaSpawn test crashes instead of hanging due to wait() which will
never be notified)

--- vm/thread/src/thread_java_basic.c
+++ vm/thread/src/thread_java_basic.c
@@ -81,7 +81,7 @@ int wrapper_proc(void *arg) {
     java_thread = jvmti_thread->thread_object;

     status = vm_attach(data->java_vm, &jni_env);
-    if (status != JNI_OK) return TM_ERROR_INTERNAL;
+    assert(status == JNI_OK); // XXX

     jvmti_thread->jenv = jni_env;
     jvmti_thread->daemon = data->daemon;



Mime
View raw message