Skip to content

8373695: G1: Using a value near integer max for ActiveProcessorCount causes fatal crash#28831

Closed
JonasNorlinder wants to merge 4 commits intoopenjdk:masterfrom
JonasNorlinder:JDK-8373695
Closed

8373695: G1: Using a value near integer max for ActiveProcessorCount causes fatal crash#28831
JonasNorlinder wants to merge 4 commits intoopenjdk:masterfrom
JonasNorlinder:JDK-8373695

Conversation

@JonasNorlinder
Copy link
Member

@JonasNorlinder JonasNorlinder commented Dec 15, 2025

G1ConcRefinementThreads default value depends on ParallelGCThreads which in turn may depend on ActiveProcessorCount. These have different ranges that are valid. Patch will ensure argument setup code never try to assign a value larger than what G1ConcRefinementThreads expects.


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-8373695: G1: Using a value near integer max for ActiveProcessorCount causes fatal crash (Bug - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28831

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 15, 2025

👋 Welcome back jnorlinder! 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 Dec 15, 2025

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

8373695: G1: Using a value near integer max for ActiveProcessorCount causes fatal crash

Reviewed-by: stefank, tschatzl

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 238 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@stefank, @tschatzl) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Dec 15, 2025
@openjdk
Copy link

openjdk bot commented Dec 15, 2025

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

  • hotspot-gc

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.

@JonasNorlinder JonasNorlinder marked this pull request as ready for review December 16, 2025 17:24
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 16, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 16, 2025

Webrevs

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

Could an alternative be to limit ParallelGCThreads?

@JonasNorlinder
Copy link
Member Author

Thanks for the suggestion Stefan. Thomas had the same comment and I’m open to it. But are we OK with using the upper bound limited by G1ConcRefinementThreads?

@tschatzl
Copy link
Contributor

Thanks for the suggestion Stefan. Thomas had the same comment and I’m open to it. But are we OK with using the upper bound limited by G1ConcRefinementThreads?

Not sure what the question is, but limiting ParallelGCThreads by max_jint / 8 is an extremely generous limit anyway which should not give issues. The constant needs to be moved somewhere else though.

@JonasNorlinder
Copy link
Member Author

FYI; I noticed that applying a limit on ParallelGCThreads still makes it possible to sneak in a larger value with ActiveProcessorCount. Looking into the interaction with ActiveProcessorCount with the rest of the code

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

I propose that you just add (max_jint - 1) / wordSize to the ParallelGCThread line, and let that be the entire fix.

I'm always hesitant to adding globals, functions, and classes to CollectedHeap. It requires extra motivation and acceptance from devs for all GCs. Often the proposal isn't a perfect fit for all GCs and we'll have to clean it out later. Here it is not clear if "WorkerThreadLimit" applies to all GCs. For example, ZGC could theoretically use more worker threads via ConcGCThreads. Not that anyone would, but I'm bringing this up to show a point that messing with CollectedHeap will likely make your PR a bit controversial and delay its review.

Another concern about this is that we haven't figured out a good, and unified way to bring constants into our GC flag cross-macros. I'd prefer if we could figure that out in a context of a separate RFE/discussion instead of in a bug fix.

Then we can see if our prioritize to figure out a good way to specify constants for our flag ranges rise to the level where we can sit down and figure out a clean way to do that.

@JonasNorlinder
Copy link
Member Author

Thanks for that heads up! FWIW; At least from my side there is no rushing on getting this one accepted so we can take our time.

I propose that you just add (max_jint - 1) / wordSize to the ParallelGCThread line, and let that be the entire fix.

Did you mean this?

  product(uint, ParallelGCThreads, 0,                                       \
          "Number of parallel threads parallel gc will use")                \
          range(0, (max_jint-1)/wordSize)                                   \

I don't think that will not solve this bug when ParallelGCThreads is heuristically determined and may (i.e. it is defined) depend on ActiveProcessorCount. Applying the above patch and running with java -XX:+UseG1GC -XX:ActiveProcessorCount=2147483647 results in a fatal crash on my machine. That being said, it do solve the fatal crash that can be triggered with java -XX:+UseG1GC -XX:ParallelGCThreads=2147483646.

@stefank
Copy link
Member

stefank commented Dec 19, 2025

Did you mean this?

  product(uint, ParallelGCThreads, 0,                                       \
          "Number of parallel threads parallel gc will use")                \
          range(0, (max_jint-1)/wordSize)                                   \

Yes.

I don't think that will not solve this bug when ParallelGCThreads is heuristically determined and may (i.e. it is defined) depend on ActiveProcessorCount. Applying the above patch and running with java -XX:+UseG1GC -XX:ActiveProcessorCount=2147483647 results in a fatal crash on my machine. That being said, it do solve the fatal crash that can be triggered with java -XX:+UseG1GC -XX:ParallelGCThreads=2147483646.

My comment was made in the context provided before you found that issue.

Comment on lines +193 to +194
constexpr uint MaxG1ConcRefinementThreads = (max_jint - 1) / wordSize; // Derived from flag declaration
FLAG_SET_ERGO(G1ConcRefinementThreads, MIN2(ParallelGCThreads, MaxG1ConcRefinementThreads));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use the flags API to programmatically get the maximum instead of hardcoding the value, something like this:

    const JVMTypedFlagLimit<uint>* conc_refinement_threads_limits = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(G1ConcRefinementThreads))->cast<uint>();
    FLAG_SET_ERGO(G1ConcRefinementThreads, MIN2(ParallelGCThreads, conc_refinement_threads_limits->max()));

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 7, 2026
@JonasNorlinder
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jan 8, 2026
@openjdk
Copy link

openjdk bot commented Jan 8, 2026

@JonasNorlinder
Your change (at version 62f78a1) is now ready to be sponsored by a Committer.

@tschatzl
Copy link
Contributor

tschatzl commented Jan 9, 2026

/sponsor

@openjdk
Copy link

openjdk bot commented Jan 9, 2026

Going to push as commit a855224.
Since your change was applied there have been 260 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 Jan 9, 2026
@openjdk openjdk bot closed this Jan 9, 2026
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jan 9, 2026
@openjdk openjdk bot removed rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jan 9, 2026
@openjdk
Copy link

openjdk bot commented Jan 9, 2026

@tschatzl @JonasNorlinder Pushed as commit a855224.

💡 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-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants