584 |
|
|
585 |
|
public void execute(Runnable task) { |
586 |
|
ForkJoinTask<?> job; |
587 |
< |
if (task instanceof ForkJoinTask) // avoid re-wrap |
588 |
< |
job = (ForkJoinTask<?>)task; |
587 |
> |
if (task instanceof ForkJoinTask<?>) // avoid re-wrap |
588 |
> |
job = (ForkJoinTask<?>) task; |
589 |
|
else |
590 |
|
job = new AdaptedRunnable<Void>(task, null); |
591 |
|
doSubmit(job); |
605 |
|
|
606 |
|
public ForkJoinTask<?> submit(Runnable task) { |
607 |
|
ForkJoinTask<?> job; |
608 |
< |
if (task instanceof ForkJoinTask) // avoid re-wrap |
609 |
< |
job = (ForkJoinTask<?>)task; |
608 |
> |
if (task instanceof ForkJoinTask<?>) // avoid re-wrap |
609 |
> |
job = (ForkJoinTask<?>) task; |
610 |
|
else |
611 |
|
job = new AdaptedRunnable<Void>(task, null); |
612 |
|
doSubmit(job); |
1874 |
|
return new AdaptedCallable<T>(callable); |
1875 |
|
} |
1876 |
|
|
1877 |
– |
|
1877 |
|
// Unsafe mechanics |
1879 |
– |
private static long fieldOffset(String fieldName, Class<?> klazz) { |
1880 |
– |
try { |
1881 |
– |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName)); |
1882 |
– |
} catch (NoSuchFieldException e) { |
1883 |
– |
// Convert Exception to Error |
1884 |
– |
NoSuchFieldError error = new NoSuchFieldError(fieldName); |
1885 |
– |
error.initCause(e); |
1886 |
– |
throw error; |
1887 |
– |
} |
1888 |
– |
} |
1878 |
|
|
1879 |
|
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
1880 |
|
private static final long eventCountOffset = |
1881 |
< |
fieldOffset("eventCount", ForkJoinPool.class); |
1881 |
> |
objectFieldOffset("eventCount", ForkJoinPool.class); |
1882 |
|
private static final long workerCountsOffset = |
1883 |
< |
fieldOffset("workerCounts", ForkJoinPool.class); |
1883 |
> |
objectFieldOffset("workerCounts", ForkJoinPool.class); |
1884 |
|
private static final long runControlOffset = |
1885 |
< |
fieldOffset("runControl", ForkJoinPool.class); |
1885 |
> |
objectFieldOffset("runControl", ForkJoinPool.class); |
1886 |
|
private static final long syncStackOffset = |
1887 |
< |
fieldOffset("syncStack",ForkJoinPool.class); |
1887 |
> |
objectFieldOffset("syncStack",ForkJoinPool.class); |
1888 |
|
private static final long spareStackOffset = |
1889 |
< |
fieldOffset("spareStack", ForkJoinPool.class); |
1889 |
> |
objectFieldOffset("spareStack", ForkJoinPool.class); |
1890 |
|
|
1891 |
|
private boolean casEventCount(long cmp, long val) { |
1892 |
|
return UNSAFE.compareAndSwapLong(this, eventCountOffset, cmp, val); |
1903 |
|
private boolean casBarrierStack(WaitQueueNode cmp, WaitQueueNode val) { |
1904 |
|
return UNSAFE.compareAndSwapObject(this, syncStackOffset, cmp, val); |
1905 |
|
} |
1906 |
+ |
|
1907 |
+ |
private static long objectFieldOffset(String field, Class<?> klazz) { |
1908 |
+ |
try { |
1909 |
+ |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); |
1910 |
+ |
} catch (NoSuchFieldException e) { |
1911 |
+ |
// Convert Exception to corresponding Error |
1912 |
+ |
NoSuchFieldError error = new NoSuchFieldError(field); |
1913 |
+ |
error.initCause(e); |
1914 |
+ |
throw error; |
1915 |
+ |
} |
1916 |
+ |
} |
1917 |
|
} |