83 |
|
/* |
84 |
|
* Overview: |
85 |
|
* |
86 |
< |
* 1. Non-nullness of field result (set via CAS) indicates |
87 |
< |
* done. An AltResult is used to box null as a result, as well as |
88 |
< |
* to hold exceptions. Using a single field makes completion fast |
86 |
> |
* 1. Non-nullness of field result (set via CAS) indicates done. |
87 |
> |
* An AltResult is used to box null as a result, as well as to |
88 |
> |
* hold exceptions. Using a single field makes completion fast |
89 |
|
* and simple to detect and trigger, at the expense of a lot of |
90 |
|
* encoding and decoding that infiltrates many methods. One minor |
91 |
|
* simplification relies on the (static) NIL (to box null results) |
287 |
|
else if (q.thread != null && result == null) { |
288 |
|
try { |
289 |
|
ForkJoinPool.managedBlock(q); |
290 |
< |
} catch(InterruptedException ex){ |
290 |
> |
} catch (InterruptedException ex) { |
291 |
|
q.interruptControl = -1; |
292 |
|
} |
293 |
|
} |
320 |
|
if (nanos <= 0L) |
321 |
|
throw new TimeoutException(); |
322 |
|
long d = System.nanoTime() + nanos; |
323 |
< |
q = new WaitNode(true, nanos, d == 0L? 1L : d); // avoid 0 |
323 |
> |
q = new WaitNode(true, nanos, d == 0L ? 1L : d); // avoid 0 |
324 |
|
} |
325 |
|
else if (!queued) |
326 |
|
queued = UNSAFE.compareAndSwapObject(this, WAITERS, |
338 |
|
else if (q.thread != null && result == null) { |
339 |
|
try { |
340 |
|
ForkJoinPool.managedBlock(q); |
341 |
< |
} catch(InterruptedException ex){ |
341 |
> |
} catch (InterruptedException ex) { |
342 |
|
q.interruptControl = -1; |
343 |
|
} |
344 |
|
} |
388 |
|
} |
389 |
|
|
390 |
|
/** Base class can act as either FJ or plain Runnable */ |
391 |
< |
static abstract class Async extends ForkJoinTask<Void> |
391 |
> |
abstract static class Async extends ForkJoinTask<Void> |
392 |
|
implements Runnable, AsynchronousCompletionTask { |
393 |
|
public final Void getRawResult() { return null; } |
394 |
|
public final void setRawResult(Void v) { } |
557 |
|
} |
558 |
|
|
559 |
|
// Opportunistically subclass AtomicInteger to use compareAndSet to claim. |
560 |
< |
static abstract class Completion extends AtomicInteger implements Runnable { |
560 |
> |
abstract static class Completion extends AtomicInteger implements Runnable { |
561 |
|
} |
562 |
|
|
563 |
|
static final class ApplyCompletion<T,U> extends Completion { |
2449 |
|
* then the returned CompletableFuture also does so, with a |
2450 |
|
* CompletionException holding this exception as its cause. |
2451 |
|
* |
2452 |
< |
* @param fn the function returning a new CompletableFuture. |
2452 |
> |
* @param fn the function returning a new CompletableFuture |
2453 |
|
* @return the CompletableFuture, that {@code isDone()} upon |
2454 |
|
* return if completed by the given function, or an exception |
2455 |
< |
* occurs. |
2455 |
> |
* occurs |
2456 |
|
*/ |
2457 |
|
public <U> CompletableFuture<U> thenCompose(Fun<? super T, |
2458 |
|
CompletableFuture<U>> fn) { |
2640 |
|
|
2641 |
|
/** |
2642 |
|
* Forcibly sets or resets the value subsequently returned by |
2643 |
< |
* method get() and related methods, whether or not already |
2644 |
< |
* completed. This method is designed for use only in error |
2645 |
< |
* recovery actions, and even in such situations may result in |
2646 |
< |
* ongoing dependent completions using established versus |
2643 |
> |
* method {@link #get()} and related methods, whether or not |
2644 |
> |
* already completed. This method is designed for use only in |
2645 |
> |
* error recovery actions, and even in such situations may result |
2646 |
> |
* in ongoing dependent completions using established versus |
2647 |
|
* overwritten outcomes. |
2648 |
|
* |
2649 |
|
* @param value the completion value |
2654 |
|
} |
2655 |
|
|
2656 |
|
/** |
2657 |
< |
* Forcibly causes subsequent invocations of method get() and |
2658 |
< |
* related methods to throw the given exception, whether or not |
2659 |
< |
* already completed. This method is designed for use only in |
2657 |
> |
* Forcibly causes subsequent invocations of method {@link #get()} |
2658 |
> |
* and related methods to throw the given exception, whether or |
2659 |
> |
* not already completed. This method is designed for use only in |
2660 |
|
* recovery actions, and even in such situations may result in |
2661 |
|
* ongoing dependent completions using established versus |
2662 |
|
* overwritten outcomes. |
2700 |
|
private static sun.misc.Unsafe getUnsafe() { |
2701 |
|
try { |
2702 |
|
return sun.misc.Unsafe.getUnsafe(); |
2703 |
< |
} catch (SecurityException se) { |
2704 |
< |
try { |
2705 |
< |
return java.security.AccessController.doPrivileged |
2706 |
< |
(new java.security |
2707 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
2708 |
< |
public sun.misc.Unsafe run() throws Exception { |
2709 |
< |
java.lang.reflect.Field f = sun.misc |
2710 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
2711 |
< |
f.setAccessible(true); |
2712 |
< |
return (sun.misc.Unsafe) f.get(null); |
2713 |
< |
}}); |
2714 |
< |
} catch (java.security.PrivilegedActionException e) { |
2715 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
2716 |
< |
e.getCause()); |
2717 |
< |
} |
2703 |
> |
} catch (SecurityException tryReflectionInstead) {} |
2704 |
> |
try { |
2705 |
> |
return java.security.AccessController.doPrivileged |
2706 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
2707 |
> |
public sun.misc.Unsafe run() throws Exception { |
2708 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
2709 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
2710 |
> |
f.setAccessible(true); |
2711 |
> |
Object x = f.get(null); |
2712 |
> |
if (k.isInstance(x)) |
2713 |
> |
return k.cast(x); |
2714 |
> |
} |
2715 |
> |
throw new NoSuchFieldError("the Unsafe"); |
2716 |
> |
}}); |
2717 |
> |
} catch (java.security.PrivilegedActionException e) { |
2718 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
2719 |
> |
e.getCause()); |
2720 |
|
} |
2721 |
|
} |
2720 |
– |
|
2722 |
|
} |