--- old/src/java.base/share/classes/java/util/concurrent/CountedCompleter.java 2021-01-09 11:34:54.925417639 -0800 +++ new/src/java.base/share/classes/java/util/concurrent/CountedCompleter.java 2021-01-09 11:34:54.473421198 -0800 @@ -357,7 +357,7 @@ * within this method to ensure thread safety of accesses to fields of * this task or other completed tasks. * - *

Completion Traversals. If using {@code onCompletion} to + *

Completion Traversals. If using {@code onCompletion} to * process completions is inapplicable or inconvenient, you can use * methods {@link #firstComplete} and {@link #nextComplete} to create * custom traversals. For example, to define a MapReducer that only @@ -553,6 +553,11 @@ return PENDING.compareAndSet(this, expected, count); } + // internal-only weak version + final boolean weakCompareAndSetPendingCount(int expected, int count) { + return PENDING.weakCompareAndSet(this, expected, count); + } + /** * If the pending count is nonzero, (atomically) decrements it. * @@ -562,7 +567,7 @@ public final int decrementPendingCountUnlessZero() { int c; do {} while ((c = pending) != 0 && - !PENDING.weakCompareAndSet(this, c, c - 1)); + !weakCompareAndSetPendingCount(c, c - 1)); return c; } @@ -595,7 +600,7 @@ return; } } - else if (PENDING.weakCompareAndSet(a, c, c - 1)) + else if (a.weakCompareAndSetPendingCount(c, c - 1)) return; } } @@ -618,7 +623,7 @@ return; } } - else if (PENDING.weakCompareAndSet(a, c, c - 1)) + else if (a.weakCompareAndSetPendingCount(c, c - 1)) return; } } @@ -663,7 +668,7 @@ for (int c;;) { if ((c = pending) == 0) return this; - else if (PENDING.weakCompareAndSet(this, c, c - 1)) + else if (weakCompareAndSetPendingCount(c, c - 1)) return null; } } @@ -718,30 +723,33 @@ * processed. */ public final void helpComplete(int maxTasks) { - Thread t; ForkJoinWorkerThread wt; - if (maxTasks > 0 && status >= 0) { - if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) - (wt = (ForkJoinWorkerThread)t).pool. - helpComplete(wt.workQueue, this, maxTasks); - else - ForkJoinPool.common.externalHelpComplete(this, maxTasks); - } + ForkJoinPool.WorkQueue q; Thread t; boolean owned; + if (owned = (t = Thread.currentThread()) instanceof ForkJoinWorkerThread) + q = ((ForkJoinWorkerThread)t).workQueue; + else + q = ForkJoinPool.commonQueue(); + if (q != null && maxTasks > 0) + q.helpComplete(this, owned, maxTasks); } + // ForkJoinTask overrides + /** * Supports ForkJoinTask exception propagation. */ - void internalPropagateException(Throwable ex) { - CountedCompleter a = this, s = a; - while (a.onExceptionalCompletion(ex, s) && - (a = (s = a).completer) != null && a.status >= 0 && - isExceptionalStatus(a.recordExceptionalCompletion(ex))) - ; + @Override + final int trySetException(Throwable ex) { + CountedCompleter a = this, p = a; + do {} while (isExceptionalStatus(a.trySetThrown(ex)) && + a.onExceptionalCompletion(ex, p) && + (a = (p = a).completer) != null && a.status >= 0); + return status; } /** * Implements execution conventions for CountedCompleters. */ + @Override protected final boolean exec() { compute(); return false; @@ -756,6 +764,7 @@ * * @return the result of the computation */ + @Override public T getRawResult() { return null; } /** @@ -765,6 +774,7 @@ * overridden to update existing objects or fields, then it must * in general be defined to be thread-safe. */ + @Override protected void setRawResult(T t) { } // VarHandle mechanics