harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r596372 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: kernel_classes/javasrc/java/lang/Thread.java thread/thread_java_basic.cpp
Date Mon, 19 Nov 2007 17:18:53 GMT
Author: wjwashburn
Date: Mon Nov 19 09:18:50 2007
New Revision: 596372

URL: http://svn.apache.org/viewvc?rev=596372&view=rev
Log:
Harmony-3267:  this fixes several bugs with Thread.stop()

Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java?rev=596372&r1=596371&r2=596372&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
Mon Nov 19 09:18:50 2007
@@ -586,38 +586,28 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    public final void join() throws InterruptedException {
-        synchronized (lock) {
-            while (isAlive()) {
-                // 2000msec timeout added to provide graceful degradation
-                // in case there is a race condition where lock.wait somehow
-                // misses the "detach() lock.notifyAll()"
-                // Or, more likely, does not see this.isAlive = false 
-                // because this.isAlive is still stuck in a CPU's store buffer
-                // the only drawback is if there are 100's of threads doing join()'s
-                // and the overhead of the continual timeouts may be a problem
-                // Let's first see a big money workload that waits on 100's of threads
-                // simultaneously before we worry
-                lock.wait(2000);
-            }
+    public final synchronized void join() throws InterruptedException {
+        notifyAll();
+        while (isAlive()) {
+            wait();
         }
     }
 
     /**
      * @com.intel.drl.spec_ref
      */
-    public final void join(long millis) throws InterruptedException {
+    public final synchronized void join(long millis) throws InterruptedException {
         if (millis == 0) {
             join();
-            return;
-        }
-        
-        synchronized (lock) {
+        } else {
+            notifyAll();
             long end = System.currentTimeMillis() + millis;
             while(isAlive()) {
-            lock.wait(millis);
+                wait(millis);
                 millis = end - System.currentTimeMillis();
-                if (millis <= 0) return;
+                if (millis <= 0) {
+                   break;
+                }
             }
         }
     }
@@ -625,23 +615,21 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    public final void join(long millis, int nanos)
+    public final synchronized void join(long millis, int nanos)
         throws InterruptedException {
-        if (millis < 0 || nanos < 0 || nanos > 999999)
+        if (millis < 0 || nanos < 0 || nanos > 999999) {
             throw new IllegalArgumentException();
-
-        if (millis == 0 && nanos == 0) {
+        } else if (millis == 0 && nanos == 0) {
             join();
-            return;
-        }
-        
-        synchronized (lock) {
+        } else {
+            notifyAll();
             long end = System.nanoTime() + 1000000*millis + (long)nanos;
             long rest;
             while (isAlive()) {
-            lock.wait(millis, nanos);
+                wait(millis, nanos);
                 rest = end - System.nanoTime();
-                if (rest <= 0) return;
+                if (rest <= 0)
+                   break;
                 nanos  = (int)(rest % 1000000);
                 millis = rest / 1000000;
             }
@@ -792,9 +780,9 @@
             }
         } finally {
             group.remove(this);
-            synchronized(lock) {
-                this.isAlive = false;
-                lock.notifyAll();
+            synchronized(this) {
+                isAlive = false;
+                notifyAll();
             }
         }
     }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp?rev=596372&r1=596371&r2=596372&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp Mon Nov 19 09:18:50
2007
@@ -469,22 +469,6 @@
 
     // Does not return if the exception could be thrown straight away
     jthread_throw_exception_object(excn);
-
-    // getting here means top stack frame is non-unwindable.
-    if (hythread_get_state(native_thread) &
-            (TM_THREAD_STATE_SLEEPING | TM_THREAD_STATE_WAITING_WITH_TIMEOUT
-                | TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT
-                | TM_THREAD_STATE_WAITING_INDEFINITELY | TM_THREAD_STATE_PARKED))
-    {
-        // 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 function returning TM_ERROR_INTERRUPT.
-        // (though, in case of parked thread, it will not be cleared)
-        hythread_interrupt(native_thread);
-    }
 } // stop_callback
 
 /**



Mime
View raw message