ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinPool.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.4 by dl, Mon Jan 12 17:16:18 2009 UTC vs.
Revision 1.5 by jsr166, Thu Mar 19 05:10:42 2009 UTC

# Line 1302 | Line 1302 | public class ForkJoinPool extends Abstra
1302              long prev = w.lastEventCount;
1303              WaitQueueNode node = null;
1304              WaitQueueNode h;
1305 <            while (eventCount == prev &&
1305 >            while (eventCount == prev &&
1306                     ((h = syncStack) == null || h.count == prev)) {
1307                  if (node == null)
1308                      node = new WaitQueueNode(prev, w);
# Line 1324 | Line 1324 | public class ForkJoinPool extends Abstra
1324       *  - on signal (thread == null)
1325       *  - on event count advance (winning race to notify vs signaller)
1326       *  - on Interrupt
1327 <     *  - if the first queued node, we find work available
1328 <     * If node was not signalled and event count not advanced on exit,
1327 >     *  - if the first queued node, we find work available
1328 >     * If node was not signalled and event count not advanced on exit,
1329       * then we also help advance event count.
1330       * @return true if node can be released
1331       */
# Line 1446 | Line 1446 | public class ForkJoinPool extends Abstra
1446          return (tc < maxPoolSize &&
1447                  (rc == 0 || totalSurplus < 0 ||
1448                   (maintainParallelism &&
1449 <                  runningDeficit > totalSurplus &&
1449 >                  runningDeficit > totalSurplus &&
1450                    ForkJoinWorkerThread.hasQueuedTasks(workers))));
1451      }
1452 <    
1452 >
1453      /**
1454       * Add a spare worker if lock available and no more than the
1455       * expected numbers of threads exist
# Line 1696 | Line 1696 | public class ForkJoinPool extends Abstra
1696  
1697  
1698      // Temporary Unsafe mechanics for preliminary release
1699 +    private static Unsafe getUnsafe() throws Throwable {
1700 +        try {
1701 +            return Unsafe.getUnsafe();
1702 +        } catch (SecurityException se) {
1703 +            try {
1704 +                return java.security.AccessController.doPrivileged
1705 +                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
1706 +                        public Unsafe run() throws Exception {
1707 +                            return getUnsafePrivileged();
1708 +                        }});
1709 +            } catch (java.security.PrivilegedActionException e) {
1710 +                throw e.getCause();
1711 +            }
1712 +        }
1713 +    }
1714 +
1715 +    private static Unsafe getUnsafePrivileged()
1716 +            throws NoSuchFieldException, IllegalAccessException {
1717 +        Field f = Unsafe.class.getDeclaredField("theUnsafe");
1718 +        f.setAccessible(true);
1719 +        return (Unsafe) f.get(null);
1720 +    }
1721 +
1722 +    private static long fieldOffset(String fieldName)
1723 +            throws NoSuchFieldException {
1724 +        return _unsafe.objectFieldOffset
1725 +            (ForkJoinPool.class.getDeclaredField(fieldName));
1726 +    }
1727  
1728      static final Unsafe _unsafe;
1729      static final long eventCountOffset;
# Line 1706 | Line 1734 | public class ForkJoinPool extends Abstra
1734  
1735      static {
1736          try {
1737 <            if (ForkJoinPool.class.getClassLoader() != null) {
1738 <                Field f = Unsafe.class.getDeclaredField("theUnsafe");
1739 <                f.setAccessible(true);
1740 <                _unsafe = (Unsafe)f.get(null);
1741 <            }
1742 <            else
1743 <                _unsafe = Unsafe.getUnsafe();
1716 <            eventCountOffset = _unsafe.objectFieldOffset
1717 <                (ForkJoinPool.class.getDeclaredField("eventCount"));
1718 <            workerCountsOffset = _unsafe.objectFieldOffset
1719 <                (ForkJoinPool.class.getDeclaredField("workerCounts"));
1720 <            runControlOffset = _unsafe.objectFieldOffset
1721 <                (ForkJoinPool.class.getDeclaredField("runControl"));
1722 <            syncStackOffset = _unsafe.objectFieldOffset
1723 <                (ForkJoinPool.class.getDeclaredField("syncStack"));
1724 <            spareStackOffset = _unsafe.objectFieldOffset
1725 <                (ForkJoinPool.class.getDeclaredField("spareStack"));
1726 <        } catch (Exception e) {
1737 >            _unsafe = getUnsafe();
1738 >            eventCountOffset = fieldOffset("eventCount");
1739 >            workerCountsOffset = fieldOffset("workerCounts");
1740 >            runControlOffset = fieldOffset("runControl");
1741 >            syncStackOffset = fieldOffset("syncStack");
1742 >            spareStackOffset = fieldOffset("spareStack");
1743 >        } catch (Throwable e) {
1744              throw new RuntimeException("Could not initialize intrinsics", e);
1745          }
1746      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines