55 |
|
* minimize other blocking synchronization apart from joining other |
56 |
|
* tasks or using synchronizers such as Phasers that are advertised to |
57 |
|
* cooperate with fork/join scheduling. Subdividable tasks should also |
58 |
< |
* not perform blocking IO, and should ideally access variables that |
58 |
> |
* not perform blocking I/O, and should ideally access variables that |
59 |
|
* are completely independent of those accessed by other running |
60 |
|
* tasks. These guidelines are loosely enforced by not permitting |
61 |
|
* checked exceptions such as {@code IOExceptions} to be |
73 |
|
* <p>It is possible to define and use ForkJoinTasks that may block, |
74 |
|
* but doing do requires three further considerations: (1) Completion |
75 |
|
* of few if any <em>other</em> tasks should be dependent on a task |
76 |
< |
* that blocks on external synchronization or IO. Event-style async |
76 |
> |
* that blocks on external synchronization or I/O. Event-style async |
77 |
|
* tasks that are never joined (for example, those subclassing {@link |
78 |
|
* CountedCompleter}) often fall into this category. (2) To minimize |
79 |
|
* resource impact, tasks should be small; ideally performing only the |
134 |
|
* (DAG). Otherwise, executions may encounter a form of deadlock as |
135 |
|
* tasks cyclically wait for each other. However, this framework |
136 |
|
* supports other methods and techniques (for example the use of |
137 |
< |
* {@link Phaser}, {@link #helpQuiesce}, and {@link #complete}) that |
137 |
> |
* {@link java.util.concurrent.Phaser}, {@link #helpQuiesce}, and |
138 |
> |
* {@link #complete}) that |
139 |
|
* may be of use in constructing custom subclasses for problems that |
140 |
|
* are not statically structured as DAGs. To support such usages a |
141 |
|
* ForkJoinTask may be atomically <em>tagged</em> with a {@code short} |
436 |
|
} |
437 |
|
|
438 |
|
/** |
439 |
< |
* Records exception and possibly propagates |
439 |
> |
* Records exception and possibly propagates. |
440 |
|
* |
441 |
|
* @return status on exit |
442 |
|
*/ |
469 |
|
} |
470 |
|
|
471 |
|
/** |
472 |
< |
* Removes exception node and clears status |
472 |
> |
* Removes exception node and clears status. |
473 |
|
*/ |
474 |
|
private void clearExceptionalCompletion() { |
475 |
|
int h = System.identityHashCode(this); |
607 |
|
throw (Error)ex; |
608 |
|
if (ex instanceof RuntimeException) |
609 |
|
throw (RuntimeException)ex; |
610 |
< |
throw uncheckedThrowable(ex, RuntimeException.class); |
610 |
> |
ForkJoinTask.<RuntimeException>uncheckedThrow(ex); |
611 |
|
} |
612 |
|
} |
613 |
|
|
617 |
|
* unchecked exceptions |
618 |
|
*/ |
619 |
|
@SuppressWarnings("unchecked") static <T extends Throwable> |
620 |
< |
T uncheckedThrowable(final Throwable t, final Class<T> c) { |
621 |
< |
return (T)t; // rely on vacuous cast |
620 |
> |
void uncheckedThrow(Throwable t) throws T { |
621 |
> |
if (t != null) |
622 |
> |
throw (T)t; // rely on vacuous cast |
623 |
|
} |
624 |
|
|
625 |
|
/** |
654 |
|
if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) |
655 |
|
((ForkJoinWorkerThread)t).workQueue.push(this); |
656 |
|
else |
657 |
< |
ForkJoinPool.commonPool.externalPush(this); |
657 |
> |
ForkJoinPool.common.externalPush(this); |
658 |
|
return this; |
659 |
|
} |
660 |
|
|
980 |
|
if (Thread.interrupted()) |
981 |
|
throw new InterruptedException(); |
982 |
|
// Messy in part because we measure in nanosecs, but wait in millisecs |
983 |
< |
int s; long ns, ms; |
984 |
< |
if ((s = status) >= 0 && (ns = unit.toNanos(timeout)) > 0L) { |
983 |
> |
int s; long ms; |
984 |
> |
long ns = unit.toNanos(timeout); |
985 |
> |
if ((s = status) >= 0 && ns > 0L) { |
986 |
|
long deadline = System.nanoTime() + ns; |
987 |
|
ForkJoinPool p = null; |
988 |
|
ForkJoinPool.WorkQueue w = null; |
1078 |
|
wt.pool.helpQuiescePool(wt.workQueue); |
1079 |
|
} |
1080 |
|
else |
1081 |
< |
ForkJoinPool.externalHelpQuiescePool(); |
1081 |
> |
ForkJoinPool.quiesceCommonPool(); |
1082 |
|
} |
1083 |
|
|
1084 |
|
/** |
1486 |
|
private static sun.misc.Unsafe getUnsafe() { |
1487 |
|
try { |
1488 |
|
return sun.misc.Unsafe.getUnsafe(); |
1489 |
< |
} catch (SecurityException se) { |
1490 |
< |
try { |
1491 |
< |
return java.security.AccessController.doPrivileged |
1492 |
< |
(new java.security |
1493 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1494 |
< |
public sun.misc.Unsafe run() throws Exception { |
1495 |
< |
java.lang.reflect.Field f = sun.misc |
1496 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
1497 |
< |
f.setAccessible(true); |
1498 |
< |
return (sun.misc.Unsafe) f.get(null); |
1499 |
< |
}}); |
1500 |
< |
} catch (java.security.PrivilegedActionException e) { |
1501 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
1502 |
< |
e.getCause()); |
1503 |
< |
} |
1489 |
> |
} catch (SecurityException tryReflectionInstead) {} |
1490 |
> |
try { |
1491 |
> |
return java.security.AccessController.doPrivileged |
1492 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1493 |
> |
public sun.misc.Unsafe run() throws Exception { |
1494 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
1495 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
1496 |
> |
f.setAccessible(true); |
1497 |
> |
Object x = f.get(null); |
1498 |
> |
if (k.isInstance(x)) |
1499 |
> |
return k.cast(x); |
1500 |
> |
} |
1501 |
> |
throw new NoSuchFieldError("the Unsafe"); |
1502 |
> |
}}); |
1503 |
> |
} catch (java.security.PrivilegedActionException e) { |
1504 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1505 |
> |
e.getCause()); |
1506 |
|
} |
1507 |
|
} |
1508 |
|
} |