9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
|
import java.util.concurrent.atomic.*; |
12 |
– |
import sun.misc.Unsafe; |
13 |
– |
import java.lang.reflect.*; |
12 |
|
|
13 |
|
/** |
14 |
|
* Abstract base class for tasks that run within a {@link |
79 |
|
* class. While these methods have {@code public} access (to allow |
80 |
|
* instances of different task subclasses to call each others |
81 |
|
* methods), some of them may only be called from within other |
82 |
< |
* ForkJoinTasks. Attempts to invoke them in other contexts result in |
83 |
< |
* exceptions or errors possibly including ClassCastException. |
82 |
> |
* ForkJoinTasks (as may be determined using method {@link |
83 |
> |
* #inForkJoinPool}). Attempts to invoke them in other contexts |
84 |
> |
* result in exceptions or errors, possibly including |
85 |
> |
* ClassCastException. |
86 |
|
* |
87 |
|
* <p>Most base support methods are {@code final} because their |
88 |
|
* implementations are intrinsically tied to the underlying |
160 |
|
*/ |
161 |
|
static ForkJoinWorkerThread getWorker() { |
162 |
|
Thread t = Thread.currentThread(); |
163 |
< |
return ((t instanceof ForkJoinWorkerThread)? |
164 |
< |
(ForkJoinWorkerThread)t : null); |
163 |
> |
return ((t instanceof ForkJoinWorkerThread) ? |
164 |
> |
(ForkJoinWorkerThread) t : null); |
165 |
|
} |
166 |
|
|
167 |
|
final boolean casStatus(int cmp, int val) { |
187 |
|
ForkJoinPool pool = getPool(); |
188 |
|
if (pool != null) { |
189 |
|
int s; // Clear signal bits while setting completion status |
190 |
< |
do;while ((s = status) >= 0 && !casStatus(s, completion)); |
190 |
> |
do {} while ((s = status) >= 0 && !casStatus(s, completion)); |
191 |
|
|
192 |
|
if ((s & SIGNAL_MASK) != 0) { |
193 |
|
if ((s &= INTERNAL_SIGNAL_MASK) != 0) |
194 |
|
pool.updateRunningCount(s); |
195 |
< |
synchronized(this) { notifyAll(); } |
195 |
> |
synchronized (this) { notifyAll(); } |
196 |
|
} |
197 |
|
} |
198 |
|
else |
205 |
|
*/ |
206 |
|
private void externallySetCompletion(int completion) { |
207 |
|
int s; |
208 |
< |
do;while ((s = status) >= 0 && |
209 |
< |
!casStatus(s, (s & SIGNAL_MASK) | completion)); |
210 |
< |
synchronized(this) { notifyAll(); } |
208 |
> |
do {} while ((s = status) >= 0 && |
209 |
> |
!casStatus(s, (s & SIGNAL_MASK) | completion)); |
210 |
> |
synchronized (this) { notifyAll(); } |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
< |
* Sets status to indicate normal completion |
214 |
> |
* Sets status to indicate normal completion. |
215 |
|
*/ |
216 |
|
final void setNormalCompletion() { |
217 |
|
// Try typical fast case -- single CAS, no signal, not already done. |
223 |
|
// internal waiting and notification |
224 |
|
|
225 |
|
/** |
226 |
< |
* Performs the actual monitor wait for awaitDone |
226 |
> |
* Performs the actual monitor wait for awaitDone. |
227 |
|
*/ |
228 |
|
private void doAwaitDone() { |
229 |
|
// Minimize lock bias and in/de-flation effects by maximizing |
230 |
|
// chances of waiting inside sync |
231 |
|
try { |
232 |
|
while (status >= 0) |
233 |
< |
synchronized(this) { if (status >= 0) wait(); } |
233 |
> |
synchronized (this) { if (status >= 0) wait(); } |
234 |
|
} catch (InterruptedException ie) { |
235 |
|
onInterruptedWait(); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
< |
* Performs the actual monitor wait for awaitDone |
240 |
> |
* Performs the actual timed monitor wait for awaitDone. |
241 |
|
*/ |
242 |
|
private void doAwaitDone(long startTime, long nanos) { |
243 |
< |
synchronized(this) { |
243 |
> |
synchronized (this) { |
244 |
|
try { |
245 |
|
while (status >= 0) { |
246 |
|
long nt = nanos - System.nanoTime() - startTime; |
247 |
|
if (nt <= 0) |
248 |
|
break; |
249 |
< |
wait(nt / 1000000, (int)(nt % 1000000)); |
249 |
> |
wait(nt / 1000000, (int) (nt % 1000000)); |
250 |
|
} |
251 |
|
} catch (InterruptedException ie) { |
252 |
|
onInterruptedWait(); |
262 |
|
* |
263 |
|
* @return status upon exit |
264 |
|
*/ |
265 |
< |
private int awaitDone(ForkJoinWorkerThread w, boolean maintainParallelism) { |
266 |
< |
ForkJoinPool pool = w == null? null : w.pool; |
265 |
> |
private int awaitDone(ForkJoinWorkerThread w, |
266 |
> |
boolean maintainParallelism) { |
267 |
> |
ForkJoinPool pool = (w == null) ? null : w.pool; |
268 |
|
int s; |
269 |
|
while ((s = status) >= 0) { |
270 |
< |
if (casStatus(s, pool == null? s|EXTERNAL_SIGNAL : s+1)) { |
270 |
> |
if (casStatus(s, (pool == null) ? s|EXTERNAL_SIGNAL : s+1)) { |
271 |
|
if (pool == null || !pool.preJoin(this, maintainParallelism)) |
272 |
|
doAwaitDone(); |
273 |
|
if (((s = status) & INTERNAL_SIGNAL_MASK) != 0) |
280 |
|
|
281 |
|
/** |
282 |
|
* Timed version of awaitDone |
283 |
+ |
* |
284 |
|
* @return status upon exit |
285 |
|
*/ |
286 |
|
private int awaitDone(ForkJoinWorkerThread w, long nanos) { |
287 |
< |
ForkJoinPool pool = w == null? null : w.pool; |
287 |
> |
ForkJoinPool pool = (w == null) ? null : w.pool; |
288 |
|
int s; |
289 |
|
while ((s = status) >= 0) { |
290 |
< |
if (casStatus(s, pool == null? s|EXTERNAL_SIGNAL : s+1)) { |
290 |
> |
if (casStatus(s, (pool == null) ? s|EXTERNAL_SIGNAL : s+1)) { |
291 |
|
long startTime = System.nanoTime(); |
292 |
|
if (pool == null || !pool.preJoin(this, false)) |
293 |
|
doAwaitDone(startTime, nanos); |
309 |
|
*/ |
310 |
|
private void adjustPoolCountsOnUnblock(ForkJoinPool pool) { |
311 |
|
int s; |
312 |
< |
do;while ((s = status) < 0 && !casStatus(s, s & COMPLETION_MASK)); |
312 |
> |
do {} while ((s = status) < 0 && !casStatus(s, s & COMPLETION_MASK)); |
313 |
|
if (pool != null && (s &= INTERNAL_SIGNAL_MASK) != 0) |
314 |
|
pool.updateRunningCount(s); |
315 |
|
} |
364 |
|
|
365 |
|
/** |
366 |
|
* Returns result or throws exception using j.u.c.Future conventions. |
367 |
< |
* Only call when isDone known to be true. |
367 |
> |
* Only call when {@code isDone} known to be true. |
368 |
|
*/ |
369 |
|
private V reportFutureResult() |
370 |
|
throws ExecutionException, InterruptedException { |
430 |
|
try { |
431 |
|
if (!exec()) |
432 |
|
return; |
433 |
< |
} catch(Throwable rex) { |
433 |
> |
} catch (Throwable rex) { |
434 |
|
setDoneExceptionally(rex); |
435 |
|
return; |
436 |
|
} |
462 |
|
final void cancelIgnoringExceptions() { |
463 |
|
try { |
464 |
|
cancel(false); |
465 |
< |
} catch(Throwable ignore) { |
465 |
> |
} catch (Throwable ignore) { |
466 |
|
} |
467 |
|
} |
468 |
|
|
474 |
|
ForkJoinTask<?> t; |
475 |
|
while ((s = status) >= 0 && (t = w.scanWhileJoining(this)) != null) |
476 |
|
t.quietlyExec(); |
477 |
< |
return (s >= 0)? awaitDone(w, false) : s; // block if no work |
477 |
> |
return (s >= 0) ? awaitDone(w, false) : s; // block if no work |
478 |
|
} |
479 |
|
|
480 |
|
// public methods |
484 |
|
* necessarily enforced, it is a usage error to fork a task more |
485 |
|
* than once unless it has completed and been reinitialized. This |
486 |
|
* method may be invoked only from within ForkJoinTask |
487 |
< |
* computations. Attempts to invoke in other contexts result in |
488 |
< |
* exceptions or errors possibly including ClassCastException. |
487 |
> |
* computations (as may be determined using method {@link |
488 |
> |
* #inForkJoinPool}). Attempts to invoke in other contexts result |
489 |
> |
* in exceptions or errors, possibly including ClassCastException. |
490 |
|
*/ |
491 |
|
public final void fork() { |
492 |
< |
((ForkJoinWorkerThread)(Thread.currentThread())).pushTask(this); |
492 |
> |
((ForkJoinWorkerThread) Thread.currentThread()) |
493 |
> |
.pushTask(this); |
494 |
|
} |
495 |
|
|
496 |
|
/** |
526 |
|
/** |
527 |
|
* Forks both tasks, returning when {@code isDone} holds for |
528 |
|
* both of them or an exception is encountered. This method may be |
529 |
< |
* invoked only from within ForkJoinTask computations. Attempts to |
530 |
< |
* invoke in other contexts result in exceptions or errors |
529 |
> |
* invoked only from within ForkJoinTask computations (as may be |
530 |
> |
* determined using method {@link #inForkJoinPool}). Attempts to |
531 |
> |
* invoke in other contexts result in exceptions or errors, |
532 |
|
* possibly including ClassCastException. |
533 |
|
* |
534 |
|
* @param t1 one task |
546 |
|
* Forks the given tasks, returning when {@code isDone} holds |
547 |
|
* for all of them. If any task encounters an exception, others |
548 |
|
* may be cancelled. This method may be invoked only from within |
549 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
550 |
< |
* result in exceptions or errors possibly including ClassCastException. |
549 |
> |
* ForkJoinTask computations (as may be determined using method |
550 |
> |
* {@link #inForkJoinPool}). Attempts to invoke in other contexts |
551 |
> |
* result in exceptions or errors, possibly including |
552 |
> |
* ClassCastException. |
553 |
|
* |
554 |
|
* @param tasks the array of tasks |
555 |
|
* @throws NullPointerException if tasks or any element are null |
592 |
|
* Forks all tasks in the collection, returning when |
593 |
|
* {@code isDone} holds for all of them. If any task |
594 |
|
* encounters an exception, others may be cancelled. This method |
595 |
< |
* may be invoked only from within ForkJoinTask |
596 |
< |
* computations. Attempts to invoke in other contexts result in |
597 |
< |
* exceptions or errors possibly including ClassCastException. |
595 |
> |
* may be invoked only from within ForkJoinTask computations (as |
596 |
> |
* may be determined using method {@link |
597 |
> |
* #inForkJoinPool}). Attempts to invoke in other contexts result |
598 |
> |
* in exceptions or errors, possibly including ClassCastException. |
599 |
|
* |
600 |
|
* @param tasks the collection of tasks |
601 |
|
* @throws NullPointerException if tasks or any element are null |
602 |
|
* @throws RuntimeException or Error if any task did so |
603 |
|
*/ |
604 |
|
public static void invokeAll(Collection<? extends ForkJoinTask<?>> tasks) { |
605 |
< |
if (!(tasks instanceof List)) { |
606 |
< |
invokeAll(tasks.toArray(new ForkJoinTask[tasks.size()])); |
605 |
> |
if (!(tasks instanceof List<?>)) { |
606 |
> |
invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()])); |
607 |
|
return; |
608 |
|
} |
609 |
+ |
@SuppressWarnings("unchecked") |
610 |
|
List<? extends ForkJoinTask<?>> ts = |
611 |
< |
(List<? extends ForkJoinTask<?>>)tasks; |
611 |
> |
(List<? extends ForkJoinTask<?>>) tasks; |
612 |
|
Throwable ex = null; |
613 |
|
int last = ts.size() - 1; |
614 |
|
for (int i = last; i >= 0; --i) { |
683 |
|
* |
684 |
|
* @param mayInterruptIfRunning this value is ignored in the |
685 |
|
* default implementation because tasks are not in general |
686 |
< |
* cancelled via interruption. |
686 |
> |
* cancelled via interruption |
687 |
|
* |
688 |
|
* @return true if this task is now cancelled |
689 |
|
*/ |
733 |
|
*/ |
734 |
|
public void completeExceptionally(Throwable ex) { |
735 |
|
setDoneExceptionally((ex instanceof RuntimeException) || |
736 |
< |
(ex instanceof Error)? ex : |
736 |
> |
(ex instanceof Error) ? ex : |
737 |
|
new RuntimeException(ex)); |
738 |
|
} |
739 |
|
|
752 |
|
public void complete(V value) { |
753 |
|
try { |
754 |
|
setRawResult(value); |
755 |
< |
} catch(Throwable rex) { |
755 |
> |
} catch (Throwable rex) { |
756 |
|
setDoneExceptionally(rex); |
757 |
|
return; |
758 |
|
} |
782 |
|
* current task and that of any other task that might be executed |
783 |
|
* while helping. (This usually holds for pure divide-and-conquer |
784 |
|
* tasks). This method may be invoked only from within |
785 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
786 |
< |
* result in exceptions or errors possibly including ClassCastException. |
785 |
> |
* ForkJoinTask computations (as may be determined using method |
786 |
> |
* {@link #inForkJoinPool}). Attempts to invoke in other contexts |
787 |
> |
* result in exceptions or errors, possibly including |
788 |
> |
* ClassCastException. |
789 |
|
* |
790 |
|
* @return the computed result |
791 |
|
*/ |
792 |
|
public final V helpJoin() { |
793 |
< |
ForkJoinWorkerThread w = (ForkJoinWorkerThread)(Thread.currentThread()); |
793 |
> |
ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread(); |
794 |
|
if (status < 0 || !w.unpushTask(this) || !tryExec()) |
795 |
|
reportException(busyJoin(w)); |
796 |
|
return getRawResult(); |
799 |
|
/** |
800 |
|
* Possibly executes other tasks until this task is ready. This |
801 |
|
* method may be invoked only from within ForkJoinTask |
802 |
< |
* computations. Attempts to invoke in other contexts result in |
803 |
< |
* exceptions or errors possibly including ClassCastException. |
802 |
> |
* computations (as may be determined using method {@link |
803 |
> |
* #inForkJoinPool}). Attempts to invoke in other contexts result |
804 |
> |
* in exceptions or errors, possibly including ClassCastException. |
805 |
|
*/ |
806 |
|
public final void quietlyHelpJoin() { |
807 |
|
if (status >= 0) { |
808 |
|
ForkJoinWorkerThread w = |
809 |
< |
(ForkJoinWorkerThread)(Thread.currentThread()); |
809 |
> |
(ForkJoinWorkerThread) Thread.currentThread(); |
810 |
|
if (!w.unpushTask(this) || !tryQuietlyInvoke()) |
811 |
|
busyJoin(w); |
812 |
|
} |
845 |
|
* joined, instead executing them until all are processed. |
846 |
|
*/ |
847 |
|
public static void helpQuiesce() { |
848 |
< |
((ForkJoinWorkerThread)(Thread.currentThread())). |
849 |
< |
helpQuiescePool(); |
848 |
> |
((ForkJoinWorkerThread) Thread.currentThread()) |
849 |
> |
.helpQuiescePool(); |
850 |
|
} |
851 |
|
|
852 |
|
/** |
867 |
|
|
868 |
|
/** |
869 |
|
* Returns the pool hosting the current task execution, or null |
870 |
< |
* if this task is executing outside of any pool. |
870 |
> |
* if this task is executing outside of any ForkJoinPool. |
871 |
|
* |
872 |
|
* @return the pool, or null if none |
873 |
|
*/ |
874 |
|
public static ForkJoinPool getPool() { |
875 |
|
Thread t = Thread.currentThread(); |
876 |
< |
return ((t instanceof ForkJoinWorkerThread)? |
877 |
< |
((ForkJoinWorkerThread)t).pool : null); |
876 |
> |
return (t instanceof ForkJoinWorkerThread) ? |
877 |
> |
((ForkJoinWorkerThread) t).pool : null; |
878 |
> |
} |
879 |
> |
|
880 |
> |
/** |
881 |
> |
* Returns {@code true} if the current thread is executing as a |
882 |
> |
* ForkJoinPool computation. |
883 |
> |
* |
884 |
> |
* @return {@code true} if the current thread is executing as a |
885 |
> |
* ForkJoinPool computation, or false otherwise |
886 |
> |
*/ |
887 |
> |
public static boolean inForkJoinPool() { |
888 |
> |
return Thread.currentThread() instanceof ForkJoinWorkerThread; |
889 |
|
} |
890 |
|
|
891 |
|
/** |
895 |
|
* another thread. This method may be useful when arranging |
896 |
|
* alternative local processing of tasks that could have been, but |
897 |
|
* were not, stolen. This method may be invoked only from within |
898 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
899 |
< |
* result in exceptions or errors possibly including ClassCastException. |
898 |
> |
* ForkJoinTask computations (as may be determined using method |
899 |
> |
* {@link #inForkJoinPool}). Attempts to invoke in other contexts |
900 |
> |
* result in exceptions or errors, possibly including |
901 |
> |
* ClassCastException. |
902 |
|
* |
903 |
|
* @return true if unforked |
904 |
|
*/ |
905 |
|
public boolean tryUnfork() { |
906 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())).unpushTask(this); |
906 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
907 |
> |
.unpushTask(this); |
908 |
|
} |
909 |
|
|
910 |
|
/** |
916 |
|
* @return the number of tasks |
917 |
|
*/ |
918 |
|
public static int getQueuedTaskCount() { |
919 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())). |
920 |
< |
getQueueSize(); |
919 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
920 |
> |
.getQueueSize(); |
921 |
|
} |
922 |
|
|
923 |
|
/** |
933 |
|
* @return the surplus number of tasks, which may be negative |
934 |
|
*/ |
935 |
|
public static int getSurplusQueuedTaskCount() { |
936 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())) |
936 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
937 |
|
.getEstimatedSurplusTaskCount(); |
938 |
|
} |
939 |
|
|
980 |
|
* be polled or executed next. This method is designed primarily |
981 |
|
* to support extensions, and is unlikely to be useful otherwise. |
982 |
|
* This method may be invoked only from within ForkJoinTask |
983 |
< |
* computations. Attempts to invoke in other contexts result in |
984 |
< |
* exceptions or errors possibly including ClassCastException. |
983 |
> |
* computations (as may be determined using method {@link |
984 |
> |
* #inForkJoinPool}). Attempts to invoke in other contexts result |
985 |
> |
* in exceptions or errors, possibly including ClassCastException. |
986 |
|
* |
987 |
|
* @return the next task, or null if none are available |
988 |
|
*/ |
989 |
|
protected static ForkJoinTask<?> peekNextLocalTask() { |
990 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())).peekTask(); |
990 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
991 |
> |
.peekTask(); |
992 |
|
} |
993 |
|
|
994 |
|
/** |
996 |
|
* queued by the current thread but not yet executed. This method |
997 |
|
* is designed primarily to support extensions, and is unlikely to |
998 |
|
* be useful otherwise. This method may be invoked only from |
999 |
< |
* within ForkJoinTask computations. Attempts to invoke in other |
1000 |
< |
* contexts result in exceptions or errors possibly including |
999 |
> |
* within ForkJoinTask computations (as may be determined using |
1000 |
> |
* method {@link #inForkJoinPool}). Attempts to invoke in other |
1001 |
> |
* contexts result in exceptions or errors, possibly including |
1002 |
|
* ClassCastException. |
1003 |
|
* |
1004 |
|
* @return the next task, or null if none are available |
1005 |
|
*/ |
1006 |
|
protected static ForkJoinTask<?> pollNextLocalTask() { |
1007 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())).pollLocalTask(); |
1007 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
1008 |
> |
.pollLocalTask(); |
1009 |
|
} |
1010 |
|
|
1011 |
|
/** |
1017 |
|
* of the pool this task is operating in. This method is designed |
1018 |
|
* primarily to support extensions, and is unlikely to be useful |
1019 |
|
* otherwise. This method may be invoked only from within |
1020 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
1021 |
< |
* result in exceptions or errors possibly including |
1020 |
> |
* ForkJoinTask computations (as may be determined using method |
1021 |
> |
* {@link #inForkJoinPool}). Attempts to invoke in other contexts |
1022 |
> |
* result in exceptions or errors, possibly including |
1023 |
|
* ClassCastException. |
1024 |
|
* |
1025 |
|
* @return a task, or null if none are available |
1026 |
|
*/ |
1027 |
|
protected static ForkJoinTask<?> pollTask() { |
1028 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())). |
1029 |
< |
pollTask(); |
1028 |
> |
return ((ForkJoinWorkerThread) Thread.currentThread()) |
1029 |
> |
.pollTask(); |
1030 |
|
} |
1031 |
|
|
1032 |
|
// Serialization support |
1058 |
|
status |= EXTERNAL_SIGNAL; // conservatively set external signal |
1059 |
|
Object ex = s.readObject(); |
1060 |
|
if (ex != null) |
1061 |
< |
setDoneExceptionally((Throwable)ex); |
1061 |
> |
setDoneExceptionally((Throwable) ex); |
1062 |
|
} |
1063 |
|
|
1064 |
< |
// Temporary Unsafe mechanics for preliminary release |
1065 |
< |
private static Unsafe getUnsafe() throws Throwable { |
1064 |
> |
// Unsafe mechanics for jsr166y 3rd party package. |
1065 |
> |
private static sun.misc.Unsafe getUnsafe() { |
1066 |
|
try { |
1067 |
< |
return Unsafe.getUnsafe(); |
1067 |
> |
return sun.misc.Unsafe.getUnsafe(); |
1068 |
|
} catch (SecurityException se) { |
1069 |
|
try { |
1070 |
|
return java.security.AccessController.doPrivileged |
1071 |
< |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
1072 |
< |
public Unsafe run() throws Exception { |
1073 |
< |
return getUnsafePrivileged(); |
1071 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1072 |
> |
public sun.misc.Unsafe run() throws Exception { |
1073 |
> |
return getUnsafeByReflection(); |
1074 |
|
}}); |
1075 |
|
} catch (java.security.PrivilegedActionException e) { |
1076 |
< |
throw e.getCause(); |
1076 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1077 |
> |
e.getCause()); |
1078 |
|
} |
1079 |
|
} |
1080 |
|
} |
1081 |
|
|
1082 |
< |
private static Unsafe getUnsafePrivileged() |
1082 |
> |
private static sun.misc.Unsafe getUnsafeByReflection() |
1083 |
|
throws NoSuchFieldException, IllegalAccessException { |
1084 |
< |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1084 |
> |
java.lang.reflect.Field f = |
1085 |
> |
sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); |
1086 |
|
f.setAccessible(true); |
1087 |
< |
return (Unsafe) f.get(null); |
1087 |
> |
return (sun.misc.Unsafe) f.get(null); |
1088 |
|
} |
1089 |
|
|
1090 |
< |
private static long fieldOffset(String fieldName) |
1058 |
< |
throws NoSuchFieldException { |
1059 |
< |
return UNSAFE.objectFieldOffset |
1060 |
< |
(ForkJoinTask.class.getDeclaredField(fieldName)); |
1061 |
< |
} |
1062 |
< |
|
1063 |
< |
static final Unsafe UNSAFE; |
1064 |
< |
static final long statusOffset; |
1065 |
< |
|
1066 |
< |
static { |
1090 |
> |
private static long fieldOffset(String fieldName, Class<?> klazz) { |
1091 |
|
try { |
1092 |
< |
UNSAFE = getUnsafe(); |
1093 |
< |
statusOffset = fieldOffset("status"); |
1094 |
< |
} catch (Throwable e) { |
1095 |
< |
throw new RuntimeException("Could not initialize intrinsics", e); |
1092 |
> |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName)); |
1093 |
> |
} catch (NoSuchFieldException e) { |
1094 |
> |
// Convert Exception to Error |
1095 |
> |
NoSuchFieldError error = new NoSuchFieldError(fieldName); |
1096 |
> |
error.initCause(e); |
1097 |
> |
throw error; |
1098 |
|
} |
1099 |
|
} |
1100 |
|
|
1101 |
+ |
private static final sun.misc.Unsafe UNSAFE = getUnsafe(); |
1102 |
+ |
static final long statusOffset = |
1103 |
+ |
fieldOffset("status", ForkJoinTask.class); |
1104 |
+ |
|
1105 |
|
} |