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); |
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 |
|
*/ |
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 |
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; |
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 |
|
} |