Skip to content

Conversation

@stefank
Copy link
Member

@stefank stefank commented Nov 25, 2025

While rewriting some of the heap size initialization code we hit a corner-case where the setting of ShenandoahMaxRegionSize to something that isn't a power-of-2 will hit an assert in max_heap_for_compressed_oops.

When running with:

java -XX:+UseShenandoahGC -XX:+UnlockExperimentalVMOptions -XX:ShenandoahMaxRegionSize=33m -version

The following code:

  size_t displacement_due_to_null_page = align_up(os::vm_page_size(),
                                                  _conservative_max_heap_alignment)

triggers:

# assert(is_power_of_2(alignment)) failed: must be a power of 2: 34603008

because _conservative_max_heap_alignment is not a power-of-2.

This happens because Shenandoah's conservative_max_heap_alignment()
returns a potentially unaligned ShenandoahMaxRegionSize value.

size_t ShenandoahArguments::conservative_max_heap_alignment() {
  size_t align = ShenandoahMaxRegionSize;
  if (UseLargePages) {
    align = MAX2(align, os::large_page_size());
  }
  return align;
}

I propose a small fix to adjust align to be a power-of-2. I've also added an earlier assert about this in set_conservative_max_heap_alignment and added an additional test-case in TestRegionSizeArgs.java

WDYT, is this an OK fix for this corner-case?


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-8372513: Shenandoah: ShenandoahMaxRegionSize can produce an unaligned heap alignment (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28492

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 25, 2025

👋 Welcome back stefank! 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 Nov 25, 2025

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

8372513: Shenandoah: ShenandoahMaxRegionSize can produce an unaligned heap alignment

Reviewed-by: jsikstro, eosterlund, shade

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 4 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 hotspot hotspot-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Nov 25, 2025
@openjdk
Copy link

openjdk bot commented Nov 25, 2025

@stefank The following labels will be automatically applied to this pull request:

  • hotspot
  • shenandoah

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

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 25, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 25, 2025

Webrevs

Copy link
Member

@jsikstro jsikstro left a comment

Choose a reason for hiding this comment

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

I think this looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 25, 2025
@stefank
Copy link
Member Author

stefank commented Nov 25, 2025

I realized that having an unconstrained flag like this can cause overflows and asserts because of that. If we want to fix that we could do something like the following:

stefank/jdk@8372513_shenandoah_max_region_size...stefank:jdk:8372513_shenandoah_max_region_size_constraints

Then running

 java -XX:+UseShenandoahGC -XX:+UnlockExperimentalVMOptions -XX:ShenandoahMaxRegionSize=9223372036854775808 -version

Will give this error message instead of an assert:

$ java -XX:+UseShenandoahGC -XX:+UnlockExperimentalVMOptions -XX:ShenandoahMaxRegionSize=9223372036854775808 -version
ShenandoahMaxRegionSize 8589934592G should be lower than (8589934592G).
Improperly specified VM option 'ShenandoahMaxRegionSize=9223372036854775808'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Yes, this is the correct fix. Thanks for handling this!

@stefank
Copy link
Member Author

stefank commented Nov 26, 2025

Thanks, Aleksey!

What do you think about the issue with an extreme user-specified value as described in:
#28492 (comment)

Do you want that change or not?

@shipilev
Copy link
Member

What do you think about the issue with an extreme user-specified value as described in: #28492 (comment)
Do you want that change or not?

Feel free to submit a bug and let Shenandoah folks handle it.

This PR stands on its own, and I think it unblocks some of the pending work, so ship it.

@stefank
Copy link
Member Author

stefank commented Nov 26, 2025

Sounds good. Thanks again!

@stefank
Copy link
Member Author

stefank commented Nov 26, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Nov 26, 2025

Going to push as commit 5291e1c.
Since your change was applied there have been 15 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 Nov 26, 2025
@openjdk openjdk bot closed this Nov 26, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 26, 2025
@openjdk
Copy link

openjdk bot commented Nov 26, 2025

@stefank Pushed as commit 5291e1c.

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

Development

Successfully merging this pull request may close these issues.

4 participants