RFR: 8372513: Shenandoah: ShenandoahMaxRegionSize can produce an unaligned heap alignment
Stefan Karlsson
stefank at openjdk.org
Tue Nov 25 14:29:55 UTC 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?
-------------
Commit messages:
- 8372513: Shenandoah: ShenandoahMaxRegionSize can produce an unaligned heap alignment
Changes: https://git.openjdk.org/jdk/pull/28492/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28492&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8372513
Stats: 14 lines in 3 files changed: 13 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/28492.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28492/head:pull/28492
PR: https://git.openjdk.org/jdk/pull/28492
More information about the hotspot-dev
mailing list