Skip to content
Permalink
Browse files
8246585: ForkJoin updates
8229253: forkjoin/FJExceptionTableLeak.java fails "AssertionError: failed to satisfy condition"

Reviewed-by: dl
  • Loading branch information
Martin Buchholz committed Jan 9, 2021
1 parent 6472104 commit 5cfa8c94d6765b93f910fc01cd1ac2a56b16d78a
@@ -357,7 +357,7 @@
* within this method to ensure thread safety of accesses to fields of
* this task or other completed tasks.
*
* <p><b>Completion Traversals</b>. If using {@code onCompletion} to
* <p><b>Completion Traversals.</b> 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 @@ public final boolean compareAndSetPendingCount(int expected, int count) {
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 boolean compareAndSetPendingCount(int expected, int count) {
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 @@ public final void tryComplete() {
return;
}
}
else if (PENDING.weakCompareAndSet(a, c, c - 1))
else if (a.weakCompareAndSetPendingCount(c, c - 1))
return;
}
}
@@ -618,7 +623,7 @@ public final void propagateCompletion() {
return;
}
}
else if (PENDING.weakCompareAndSet(a, c, c - 1))
else if (a.weakCompareAndSetPendingCount(c, c - 1))
return;
}
}
@@ -663,7 +668,7 @@ public void complete(T rawResult) {
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 @@ public final void quietlyCompleteRoot() {
* 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 @@ protected final boolean exec() {
*
* @return the result of the computation
*/
@Override
public T getRawResult() { return null; }

/**
@@ -765,6 +774,7 @@ protected final boolean exec() {
* 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

Large diffs are not rendered by default.

Loading

1 comment on commit 5cfa8c9

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5cfa8c9 Jan 9, 2021

Please sign in to comment.