RFR: 8372513: Shenandoah: ShenandoahMaxRegionSize can produce an unaligned heap alignment
Aleksey Shipilev
shade at openjdk.org
Tue Nov 25 15:57:39 UTC 2025
On Tue, 25 Nov 2025 14:19:53 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> 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?
Yes, this is the correct fix. Thanks for handling this!
-------------
Marked as reviewed by shade (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/28492#pullrequestreview-3505760160
More information about the hotspot-dev
mailing list