Skip to content

Commit

Permalink
8246585: ForkJoin updates
Browse files Browse the repository at this point in the history
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 5cfa8c9
Show file tree
Hide file tree
Showing 9 changed files with 2,674 additions and 2,177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -663,7 +668,7 @@ public final CountedCompleter<?> firstComplete() {
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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -756,6 +764,7 @@ protected final boolean exec() {
*
* @return the result of the computation
*/
@Override
public T getRawResult() { return null; }

/**
Expand All @@ -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
Expand Down
3,042 changes: 1,635 additions & 1,407 deletions src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Large diffs are not rendered by default.

Loading

3 comments on commit 5cfa8c9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sendaoYan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 5cfa8c9 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sendaoYan Could not automatically backport 5cfa8c94 to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-sendaoYan-5cfa8c94-master

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 5cfa8c94d6765b93f910fc01cd1ac2a56b16d78a

# Backport the commit
$ git cherry-pick --no-commit 5cfa8c94d6765b93f910fc01cd1ac2a56b16d78a
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 5cfa8c94d6765b93f910fc01cd1ac2a56b16d78a'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 5cfa8c94d6765b93f910fc01cd1ac2a56b16d78a.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5cfa8c94 from the openjdk/jdk repository.

The commit being backported was authored by Martin Buchholz on 9 Jan 2021 and was reviewed by Doug Lea.

Thanks!

Please sign in to comment.