harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Salikh Zakirov (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-3267) [drlvm][thread] Thread.stop() implementation is broken
Date Wed, 28 Feb 2007 17:53:57 GMT
[drlvm][thread] Thread.stop() implementation is broken

                 Key: HARMONY-3267
                 URL: https://issues.apache.org/jira/browse/HARMONY-3267
             Project: Harmony
          Issue Type: Bug
          Components: DRLVM
            Reporter: Salikh Zakirov
            Priority: Minor
         Attachments: StopBlocked.java, StopWaiting.java

The current implementation of Thread.stop() in DRLVM is completely broken.
The attached tests StopWaiting.java and StopBlocked.java demonstrate current incorrect behaviour:
DRLVM can't stop the thread which is blocked either waiting or entering monitor.

The waiting case can be fixed by checking the thread state, setting some checked status and
waking thread up, like the patch below.
However, the blocking case cannot fixed in this way, as we have no easy way to wake up a thread
which is blocked on a pthread_mutex_lock or EnterCriticalSection OS call.

It looks like a correct implementation of stopping blocked thread will require either pthread_kill()
or SuspendThread() and modifying thread context (like throwing an exception or longjmp).

Both tests pass on competition VMs (Sun, Bea, Ibm).


A limited fix for a waiting case only.

--- vm/thread/src/thread_java_basic.c
+++ vm/thread/src/thread_java_basic.c
@@ -416,7 +416,23 @@ void stop_callback(void) {
     tm_native_thread->suspend_request = 0;
+    // Does not return if the exception could be thrown straight away
+    // getting here means top stack frame is non-unwindable.
+    if (tm_native_thread->state &
+        // This is needed for correct stopping of a thread blocked on monitor_wait.
+        // The thread needs some flag to exit its waiting loop.
+        // We piggy-back on interrupted status. A correct exception from TLS
+        // will be thrown because the check of exception status on leaving
+        // JNI frame comes before checking return status in Object.wait().
+        // Interrupted status will be cleared by 
+        hythread_interrupt(tm_native_thread);
+    }

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message