1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166y; |
8 |
|
|
9 |
|
import java.io.Serializable; |
10 |
|
import java.util.Collection; |
11 |
– |
import java.util.Collections; |
11 |
|
import java.util.List; |
12 |
|
import java.util.RandomAccess; |
14 |
– |
import java.util.Map; |
13 |
|
import java.lang.ref.WeakReference; |
14 |
|
import java.lang.ref.ReferenceQueue; |
15 |
|
import java.util.concurrent.Callable; |
16 |
|
import java.util.concurrent.CancellationException; |
17 |
|
import java.util.concurrent.ExecutionException; |
20 |
– |
import java.util.concurrent.Executor; |
21 |
– |
import java.util.concurrent.ExecutorService; |
18 |
|
import java.util.concurrent.Future; |
19 |
|
import java.util.concurrent.RejectedExecutionException; |
20 |
|
import java.util.concurrent.RunnableFuture; |
380 |
|
* periods. However, since we do not know when the last joiner |
381 |
|
* completes, we must use weak references and expunge them. We do |
382 |
|
* so on each operation (hence full locking). Also, some thread in |
383 |
< |
* any ForkJoinPool will call helpExpunge when its pool becomes |
384 |
< |
* isQuiescent. |
383 |
> |
* any ForkJoinPool will call helpExpungeStaleExceptions when its |
384 |
> |
* pool becomes isQuiescent. |
385 |
|
*/ |
386 |
|
static final class ExceptionNode extends WeakReference<ForkJoinTask<?>>{ |
387 |
|
final Throwable ex; |
388 |
|
ExceptionNode next; |
389 |
< |
final long thrower; |
389 |
> |
final long thrower; // use id not ref to avoid weak cycles |
390 |
|
ExceptionNode(ForkJoinTask<?> task, Throwable ex, ExceptionNode next) { |
391 |
|
super(task, exceptionTableRefQueue); |
392 |
|
this.ex = ex; |
402 |
|
*/ |
403 |
|
private int setExceptionalCompletion(Throwable ex) { |
404 |
|
int h = System.identityHashCode(this); |
405 |
< |
ReentrantLock lock = exceptionTableLock; |
405 |
> |
final ReentrantLock lock = exceptionTableLock; |
406 |
|
lock.lock(); |
407 |
|
try { |
408 |
|
expungeStaleExceptions(); |
427 |
|
*/ |
428 |
|
private void clearExceptionalCompletion() { |
429 |
|
int h = System.identityHashCode(this); |
430 |
< |
ReentrantLock lock = exceptionTableLock; |
430 |
> |
final ReentrantLock lock = exceptionTableLock; |
431 |
|
lock.lock(); |
432 |
|
try { |
433 |
|
ExceptionNode[] t = exceptionTable; |
472 |
|
return null; |
473 |
|
int h = System.identityHashCode(this); |
474 |
|
ExceptionNode e; |
475 |
< |
ReentrantLock lock = exceptionTableLock; |
475 |
> |
final ReentrantLock lock = exceptionTableLock; |
476 |
|
lock.lock(); |
477 |
|
try { |
478 |
|
expungeStaleExceptions(); |
487 |
|
if (e == null || (ex = e.ex) == null) |
488 |
|
return null; |
489 |
|
if (e.thrower != Thread.currentThread().getId()) { |
490 |
< |
Class ec = ex.getClass(); |
490 |
> |
Class<? extends Throwable> ec = ex.getClass(); |
491 |
|
try { |
492 |
|
Constructor<?> noArgCtor = null; |
493 |
|
Constructor<?>[] cs = ec.getConstructors();// public ctors only |
538 |
|
} |
539 |
|
|
540 |
|
/** |
541 |
< |
* If lock is available, poll any stale refs and remove them. |
541 |
> |
* If lock is available, poll stale refs and remove them. |
542 |
|
* Called from ForkJoinPool when pools become quiescent. |
543 |
|
*/ |
544 |
|
static final void helpExpungeStaleExceptions() { |
545 |
< |
ReentrantLock lock = exceptionTableLock; |
545 |
> |
final ReentrantLock lock = exceptionTableLock; |
546 |
|
if (lock.tryLock()) { |
547 |
|
try { |
548 |
|
expungeStaleExceptions(); |