56 |
|
* maximum number of running threads to 32767. Attempts to create |
57 |
|
* pools with greater than the maximum result in |
58 |
|
* IllegalArgumentExceptions. |
59 |
+ |
* |
60 |
+ |
* @since 1.7 |
61 |
+ |
* @author Doug Lea |
62 |
|
*/ |
63 |
|
public class ForkJoinPool extends AbstractExecutorService { |
64 |
|
|
219 |
|
* threads, packed into one int to ensure consistent snapshot when |
220 |
|
* making decisions about creating and suspending spare |
221 |
|
* threads. Updated only by CAS. Note: CASes in |
222 |
< |
* updateRunningCount and preJoin running active count is in low |
223 |
< |
* word, so need to be modified if this changes |
222 |
> |
* updateRunningCount and preJoin assume that running active count |
223 |
> |
* is in low word, so need to be modified if this changes. |
224 |
|
*/ |
225 |
|
private volatile int workerCounts; |
226 |
|
|
433 |
|
|
434 |
|
/** |
435 |
|
* Creates or resizes array if necessary to hold newLength. |
436 |
< |
* Call only under exclusion or lock. |
436 |
> |
* Call only under exclusion. |
437 |
> |
* |
438 |
|
* @return the array |
439 |
|
*/ |
440 |
|
private ForkJoinWorkerThread[] ensureWorkerArrayCapacity(int newLength) { |
1822 |
|
|
1823 |
|
private static long fieldOffset(String fieldName) |
1824 |
|
throws NoSuchFieldException { |
1825 |
< |
return _unsafe.objectFieldOffset |
1825 |
> |
return UNSAFE.objectFieldOffset |
1826 |
|
(ForkJoinPool.class.getDeclaredField(fieldName)); |
1827 |
|
} |
1828 |
|
|
1829 |
< |
static final Unsafe _unsafe; |
1829 |
> |
static final Unsafe UNSAFE; |
1830 |
|
static final long eventCountOffset; |
1831 |
|
static final long workerCountsOffset; |
1832 |
|
static final long runControlOffset; |
1835 |
|
|
1836 |
|
static { |
1837 |
|
try { |
1838 |
< |
_unsafe = getUnsafe(); |
1838 |
> |
UNSAFE = getUnsafe(); |
1839 |
|
eventCountOffset = fieldOffset("eventCount"); |
1840 |
|
workerCountsOffset = fieldOffset("workerCounts"); |
1841 |
|
runControlOffset = fieldOffset("runControl"); |
1847 |
|
} |
1848 |
|
|
1849 |
|
private boolean casEventCount(long cmp, long val) { |
1850 |
< |
return _unsafe.compareAndSwapLong(this, eventCountOffset, cmp, val); |
1850 |
> |
return UNSAFE.compareAndSwapLong(this, eventCountOffset, cmp, val); |
1851 |
|
} |
1852 |
|
private boolean casWorkerCounts(int cmp, int val) { |
1853 |
< |
return _unsafe.compareAndSwapInt(this, workerCountsOffset, cmp, val); |
1853 |
> |
return UNSAFE.compareAndSwapInt(this, workerCountsOffset, cmp, val); |
1854 |
|
} |
1855 |
|
private boolean casRunControl(int cmp, int val) { |
1856 |
< |
return _unsafe.compareAndSwapInt(this, runControlOffset, cmp, val); |
1856 |
> |
return UNSAFE.compareAndSwapInt(this, runControlOffset, cmp, val); |
1857 |
|
} |
1858 |
|
private boolean casSpareStack(WaitQueueNode cmp, WaitQueueNode val) { |
1859 |
< |
return _unsafe.compareAndSwapObject(this, spareStackOffset, cmp, val); |
1859 |
> |
return UNSAFE.compareAndSwapObject(this, spareStackOffset, cmp, val); |
1860 |
|
} |
1861 |
|
private boolean casBarrierStack(WaitQueueNode cmp, WaitQueueNode val) { |
1862 |
< |
return _unsafe.compareAndSwapObject(this, syncStackOffset, cmp, val); |
1862 |
> |
return UNSAFE.compareAndSwapObject(this, syncStackOffset, cmp, val); |
1863 |
|
} |
1864 |
|
} |