Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8336707: Contention of ForkJoinPool grows when stealing works #21507

Closed
wants to merge 52 commits into from

Conversation

DougLea
Copy link
Contributor

@DougLea DougLea commented Oct 14, 2024

This addresses tendencies in previous update to increase fencing, scanning, and signalling that can increase contention, and slow down performance especially on ARM platforms. It also uses more ARM-friendly constructions to reduce overhead (leading to several changes that all of the same form),


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8336707: Contention of ForkJoinPool grows when stealing works (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21507/head:pull/21507
$ git checkout pull/21507

Update a local copy of the PR:
$ git checkout pull/21507
$ git pull https://git.openjdk.org/jdk.git pull/21507/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21507

View PR using the GUI difftool:
$ git pr show -t 21507

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21507.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 14, 2024

👋 Welcome back dl! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 14, 2024

@DougLea This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8336707: Contention of ForkJoinPool grows when stealing works

Reviewed-by: vklang

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 37 new commits pushed to the master branch:

  • 93aa7e2: 8328085: C2: Use after free in PhaseChaitin::Register_Allocate()
  • 10def48: 8344236: Revisit SecurityManager usage in jdk.net after JEP 486 integration
  • 7105bb9: 8344664: Remove some un-used java/sun.security imports in the java.desktop module
  • a01aa22: 8342281: Deprecate for removal javax.sound.sampled.AudioPermission
  • 4fbf272: 8344526: RISC-V: implement -XX:+VerifyActivationFrameSize
  • 1343911: 8340334: Update jcmd VM.events max parameter to be INT
  • 400eb9b: 8344524: Remove SecurityManager related code from jdk.jlink module
  • a599c30: 8344471: Remove SecurityManager related code from java.compiler module
  • b9bf447: 8344057: Remove doPrivileged calls from unix platform sources in the java.desktop module
  • da2d7a0: 8344595: State transitions in internal VirtualThread comment needs to be updated
  • ... and 27 more: https://git.openjdk.org/jdk/compare/81e43114eca5199a0d816c02f50ecb6bc370135b...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Oct 14, 2024

@DougLea The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Oct 14, 2024
@DougLea DougLea changed the title Jdk 8336707: Contention of ForkJoinPool grows when stealing works JDK-8336707: Contention of ForkJoinPool grows when stealing works Oct 14, 2024
@openjdk openjdk bot changed the title JDK-8336707: Contention of ForkJoinPool grows when stealing works 8336707: Contention of ForkJoinPool grows when stealing works Oct 14, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 14, 2024
Comment on lines +4078 to +4082
ForkJoinPool p = common = (System.getSecurityManager() == null) ?
new ForkJoinPool((byte)0) :
AccessController.doPrivileged(new PrivilegedAction<>() {
public ForkJoinPool run() {
return new ForkJoinPool((byte)0); }});
Copy link
Contributor

Choose a reason for hiding this comment

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

@AlanBateman Any recommendation as to what is ideal here with SM removed? /cc @DougLea

Copy link
Contributor Author

@DougLea DougLea Nov 19, 2024

Choose a reason for hiding this comment

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

I moved this to end so that in next pass with SM removed, the static init will end with just:
common = new ForkJoinPool((byte)0).
(Which will be sure to be done after all the other static init finiahes.)

Copy link
Contributor

Choose a reason for hiding this comment

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

@DougLea I must've forgotten about addressing SM separately. 👍

Comment on lines +230 to +247
/**
* Clears ThreadLocals, and if necessary resets ContextClassLoader
*/
final void resetThreadLocals() {
if (U.getReference(this, THREADLOCALS) != null)
U.putReference(this, THREADLOCALS, null);
if (U.getReference(this, INHERITABLETHREADLOCALS) != null)
U.putReference(this, INHERITABLETHREADLOCALS, null);
if ((this instanceof InnocuousForkJoinWorkerThread) &&
((InnocuousForkJoinWorkerThread)this).needCCLReset())
super.setContextClassLoader(ClassLoader.getSystemClassLoader());
}

private static final Unsafe U = Unsafe.getUnsafe();
private static final long THREADLOCALS
= U.objectFieldOffset(Thread.class, "threadLocals");
private static final long INHERITABLETHREADLOCALS
= U.objectFieldOffset(Thread.class, "inheritableThreadLocals");
Copy link
Contributor

Choose a reason for hiding this comment

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

@AlanBateman Thoughts here? 🤔

Copy link
Contributor

@AlanBateman AlanBateman Nov 20, 2024

Choose a reason for hiding this comment

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

resetThreadLocals looks good although. A discussion point is whether reset should be done for all FJP instances, not just the common pool but not this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks Alan. Yes, I think it should be considered to do it for all FJP instances.

Copy link
Contributor Author

@DougLea DougLea Nov 20, 2024

Choose a reason for hiding this comment

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

Well, almost all. There is a protected FJWT constructor with explicit arg about preserving ThreadLocals,, in which case it should also not reset CCL. (Also, I just noticed that the Thread ctor with !inherit now also forces using System classLoader, so the FJWT ctor no longer needs to in this case.) Will do as part of SM-removal pr coming next.

public void setContextClassLoader(ClassLoader cl) {
if (cl != null && ClassLoader.getSystemClassLoader() != cl)
if (System.getSecurityManager() != null &&
Copy link
Contributor

Choose a reason for hiding this comment

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

@AlanBateman Alternatives for this? 🤔

Copy link
Contributor

@AlanBateman AlanBateman Nov 20, 2024

Choose a reason for hiding this comment

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

I don't think it needs an alternative, instead L270-272 will be removed as part of the SM cleanup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a good plan 👍

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Nov 20, 2024
@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 20, 2024
@bridgekeeper bridgekeeper bot removed the oca Needs verification of OCA signatory status label Nov 20, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 20, 2024
Copy link
Contributor

@viktorklang-ora viktorklang-ora left a comment

Choose a reason for hiding this comment

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

Great work, @DougLea!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 21, 2024
@DougLea
Copy link
Contributor Author

DougLea commented Nov 21, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Nov 21, 2024

Going to push as commit 18df6fd.
Since your change was applied there have been 39 commits pushed to the master branch:

  • f2b10c6: 8340422: ZGC: TestAllocateHeapAt.java should not run with transparent hugepages
  • 5ccd510: 8326369: Add test to verify bimorphic inlining happens after morphism changes
  • 93aa7e2: 8328085: C2: Use after free in PhaseChaitin::Register_Allocate()
  • 10def48: 8344236: Revisit SecurityManager usage in jdk.net after JEP 486 integration
  • 7105bb9: 8344664: Remove some un-used java/sun.security imports in the java.desktop module
  • a01aa22: 8342281: Deprecate for removal javax.sound.sampled.AudioPermission
  • 4fbf272: 8344526: RISC-V: implement -XX:+VerifyActivationFrameSize
  • 1343911: 8340334: Update jcmd VM.events max parameter to be INT
  • 400eb9b: 8344524: Remove SecurityManager related code from jdk.jlink module
  • a599c30: 8344471: Remove SecurityManager related code from java.compiler module
  • ... and 29 more: https://git.openjdk.org/jdk/compare/81e43114eca5199a0d816c02f50ecb6bc370135b...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 21, 2024
@openjdk openjdk bot closed this Nov 21, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 21, 2024
@openjdk
Copy link

openjdk bot commented Nov 21, 2024

@DougLea Pushed as commit 18df6fd.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@DougLea DougLea deleted the JDK-8336707 branch November 21, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants