Skip to content

Conversation

@shipilev
Copy link
Member

@shipilev shipilev commented Apr 30, 2025

There is an unfortunate limitation with default tiered policy that we would have at least 2 threads on 1 CPU machine: 1 thread for C1, and 1 thread for C2.

But if we select C1-only or C2-only modes, we also get 2 compiler threads, for which we have no good reason. These threads would just step on each other toes. The fix changes the behavior for 1..3 CPU hosts in C1/C2-only configurations, by using 1 thread instead of 2 threads. The change for 1 CPU config is what we really need. The change in 2..3 CPU configs is an additional effect, but I think it is still good not to use 100%/66% of the CPUs in those configurations as well.

$ for I in `seq 1 8`; do build/linux-x86_64-server-release/images/jdk/bin/java \
  -XX:-TieredCompilation -XX:ActiveProcessorCount=${I} \
  -XX:+PrintFlagsFinal 2>&1 | grep "CICompilerCount "; done

# Before
     intx CICompilerCount                          = 2
     intx CICompilerCount                          = 2
     intx CICompilerCount                          = 2
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 4

# After
     intx CICompilerCount                          = 1
     intx CICompilerCount                          = 1
     intx CICompilerCount                          = 1
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 3
     intx CICompilerCount                          = 4

It is a minor bug in CompilationPolicy::initialize, but it gets in the way studying Leyden in tight CPU scenarios.

Additional testing:

  • New regression test passes with the fix, fails without it
  • GHA
  • Linux AArch64 server fastdebug, all

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-8356000: C1/C2-only modes use 2 compiler threads on low CPU count machines (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24972

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 30, 2025

👋 Welcome back shade! 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 Apr 30, 2025

@shipilev 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:

8356000: C1/C2-only modes use 2 compiler threads on low CPU count machines

Reviewed-by: kvn, dfenacci, galder

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 5 new commits pushed to the master branch:

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 openjdk bot added the rfr Pull request is ready for review label Apr 30, 2025
@openjdk
Copy link

openjdk bot commented Apr 30, 2025

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

  • hotspot-compiler

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.

@mlbridge
Copy link

mlbridge bot commented Apr 30, 2025

Webrevs

@shipilev shipilev changed the title 8356000: C1/C2-only modes use 2 compiler threads on 1 CPU machine 8356000: C1/C2-only modes use 2 compiler threads on low CPU count machines May 1, 2025
Copy link
Contributor

@dafedafe dafedafe left a comment

Choose a reason for hiding this comment

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

Thanks @shipilev for fixing this (it might be a minor bug but still... inconsistent 🙂)

@shipilev
Copy link
Member Author

Update: Added the test that verifies heuristics performs as expected. This test also explores what happens with explicit CICompilerCount setting, varying the CPU sizes, etc. This allowed me to simplify the actual VM code: what we used to assert, we now directly test.

I also had to add CICompilerCount=0 for Xint mode, so that test is straightforward.

@shipilev
Copy link
Member Author

shipilev commented Jun 2, 2025

Any further comments / testing? Thanks.

Copy link
Contributor

@galderz galderz left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and expanding the test case.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Looks fine. I submitted testing.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Testing mostly passed. Only macOS-aarch64 left (linux-aarch64 passed). I think it is fine to integrate without waiting.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 4, 2025
@vnkozlov
Copy link
Contributor

vnkozlov commented Jun 4, 2025

All my testing passed.

Copy link
Contributor

@dafedafe dafedafe left a comment

Choose a reason for hiding this comment

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

Very thorough test! Thanks a lot @shipilev!

@shipilev
Copy link
Member Author

shipilev commented Jun 4, 2025

During the final pre-integration checks, I noticed that this PR still has buffer adjustments for c2_only case. That adjustment is, strictly speaking, outside the scope of this improvement. So I reverted that hunk. Tests still pass.

I see JDK-8354727 was filed to figure out what happens when we are scarce on code cache, so I would feel better to put it on @mhaessig to mix c43b18a into his work :)

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 4, 2025
@mhaessig
Copy link
Contributor

mhaessig commented Jun 4, 2025

I see JDK-8354727 was filed to figure out what happens when we are scarce on code cache, so I would feel better to put it on @mhaessig to mix c43b18a into his work :)

Will do. Thanks for the heads up!

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Re-approved

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 4, 2025
@shipilev
Copy link
Member Author

shipilev commented Jun 4, 2025

Excellent, thanks for reviews! Here goes.

/integrate

@openjdk
Copy link

openjdk bot commented Jun 4, 2025

Going to push as commit 4e314cb.
Since your change was applied there have been 7 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 4, 2025

@shipilev Pushed as commit 4e314cb.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants