7037436: CR 7035020 fails to check shutdown
authordl
Mon, 18 Apr 2011 15:50:18 +0100
changeset 9278 f4672926fe4c
parent 9277 92ecd6edb959
child 9279 5f5d493d30a0
7037436: CR 7035020 fails to check shutdown Reviewed-by: chegar
jdk/src/share/classes/java/util/concurrent/ForkJoinPool.java
jdk/src/share/classes/java/util/concurrent/ForkJoinWorkerThread.java
--- a/jdk/src/share/classes/java/util/concurrent/ForkJoinPool.java	Mon Apr 18 11:14:28 2011 +0100
+++ b/jdk/src/share/classes/java/util/concurrent/ForkJoinPool.java	Mon Apr 18 15:50:18 2011 +0100
@@ -824,7 +824,8 @@
             else if (w.eventCount != v)
                 return true;                      // update next time
         }
-        if ((int)c != 0 && parallelism + (int)(nc >> AC_SHIFT) == 0 &&
+        if ((!shutdown || !tryTerminate(false)) &&
+            (int)c != 0 && parallelism + (int)(nc >> AC_SHIFT) == 0 &&
             blockedCount == 0 && quiescerCount == 0)
             idleAwaitWork(w, nc, c, v);           // quiescent
         for (boolean rescanned = false;;) {
@@ -1024,8 +1025,8 @@
         do {} while (!UNSAFE.compareAndSwapLong(this, ctlOffset,  // no mask
                                                 c = ctl, c + AC_UNIT));
         int b;
-        do {} while(!UNSAFE.compareAndSwapInt(this, blockedCountOffset,
-                                              b = blockedCount, b - 1));
+        do {} while (!UNSAFE.compareAndSwapInt(this, blockedCountOffset,
+                                               b = blockedCount, b - 1));
     }
 
     /**
@@ -1177,7 +1178,7 @@
                         ws[k] = w;
                         nextWorkerIndex = k + 1;
                         int m = g & SMASK;
-                        g = k > m? ((m << 1) + 1) & SMASK : g + (SG_UNIT<<1);
+                        g = (k > m) ? ((m << 1) + 1) & SMASK : g + (SG_UNIT<<1);
                     }
                 } finally {
                     scanGuard = g;
@@ -1360,8 +1361,8 @@
      */
     final void addQuiescerCount(int delta) {
         int c;
-        do {} while(!UNSAFE.compareAndSwapInt(this, quiescerCountOffset,
-                                              c = quiescerCount, c + delta));
+        do {} while (!UNSAFE.compareAndSwapInt(this, quiescerCountOffset,
+                                               c = quiescerCount, c + delta));
     }
 
     /**
@@ -1714,7 +1715,7 @@
      */
     public int getRunningThreadCount() {
         int r = parallelism + (int)(ctl >> AC_SHIFT);
-        return r <= 0? 0 : r; // suppress momentarily negative values
+        return (r <= 0) ? 0 : r; // suppress momentarily negative values
     }
 
     /**
@@ -1726,7 +1727,7 @@
      */
     public int getActiveThreadCount() {
         int r = parallelism + (int)(ctl >> AC_SHIFT) + blockedCount;
-        return r <= 0? 0 : r; // suppress momentarily negative values
+        return (r <= 0) ? 0 : r; // suppress momentarily negative values
     }
 
     /**
@@ -1881,9 +1882,9 @@
         int ac = rc + blockedCount;
         String level;
         if ((c & STOP_BIT) != 0)
-            level = (tc == 0)? "Terminated" : "Terminating";
+            level = (tc == 0) ? "Terminated" : "Terminating";
         else
-            level = shutdown? "Shutting down" : "Running";
+            level = shutdown ? "Shutting down" : "Running";
         return super.toString() +
             "[" + level +
             ", parallelism = " + pc +
--- a/jdk/src/share/classes/java/util/concurrent/ForkJoinWorkerThread.java	Mon Apr 18 11:14:28 2011 +0100
+++ b/jdk/src/share/classes/java/util/concurrent/ForkJoinWorkerThread.java	Mon Apr 18 15:50:18 2011 +0100
@@ -361,7 +361,7 @@
     protected void onStart() {
         queue = new ForkJoinTask<?>[INITIAL_QUEUE_CAPACITY];
         int r = pool.workerSeedGenerator.nextInt();
-        seed = (r == 0)? 1 : r; //  must be nonzero
+        seed = (r == 0) ? 1 : r; //  must be nonzero
     }
 
     /**
@@ -724,7 +724,7 @@
                         Thread.yield();        // for politeness
                 }
                 else
-                    retries = helpJoinTask(joinMe)? MAX_HELP : retries - 1;
+                    retries = helpJoinTask(joinMe) ? MAX_HELP : retries - 1;
             }
             else {
                 retries = MAX_HELP;           // restart if not done
@@ -955,7 +955,7 @@
                     p.addActiveCount(1);
                 }
                 if ((t = (v != this) ? v.deqTask() :
-                     locallyFifo? locallyDeqTask() : popTask()) != null) {
+                     locallyFifo ? locallyDeqTask() : popTask()) != null) {
                     currentSteal = t;
                     t.doExec();
                     currentSteal = ps;