On Tue, 8 Sep 2026 03:30:30 GMT, Yunbo Zhang <[email protected]> wrote:
> Please review this small fix.
>
> **Problem:**
>
> G1 only supports region sizes from 1 MiB up to 32 MiB on 32-bit platforms or
> 512 MiB on 64-bit platforms. However, an invalid value such as `16` is
> silently adjusted to 1 MiB before the constraint is checked:
>
>
> $ java -XX:G1HeapRegionSize=16 -XX:+PrintFlagsFinal -version | grep
> G1HeapRegionSize
> size_t G1HeapRegionSize = 1048576
> {product} {command line, ergonomic}
> openjdk version "28-internal" 2027-03-23
> OpenJDK Runtime Environment (build 28-internal-adhoc.zhangyunbo)
> OpenJDK 64-Bit Server VM (build 28-internal-adhoc.zhangyunbo, mixed mode,
> sharing)
>
>
> **Fix:**
>
> - Move the `G1HeapRegionSize` constraint from `AfterMemoryInit` to
> `AfterErgo`, so it is checked after GC selection but before the value is
> adjusted during heap initialization.
> - Keep `0` as the valid ergonomic value and reject non-zero values below 1
> MiB.
> - Update `MemoryManagement.java` to use the valid minimum value `1m` instead
> of relying on an invalid value being adjusted.
>
> **Testing:**
>
> - gc/arguments:47 passed, 0 failed, 2 skipped
> - tier1:all pass
> - MemoryManagement.java & TestG1HeapRegionSize.java: pass
>
>
> $ java -XX:G1HeapRegionSize=16 -version
> G1HeapRegionSize (16) must be greater than or equal to ergonomic heap region
> minimum size
> Error: Could not create the Java Virtual Machine.
> Error: A fatal exception has occurred. Program will exit.
>
>
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK
> Interim AI Policy](https://openjdk.org/legal/ai).
`AfterErgo` is the right phase, it runs right after `apply_ergo()` so `UseG1GC`
is settled, and well before `setup_heap_region_size()` does the adjusting.
Dropping `FLAG_IS_CMDLINE` is safe for the same reason: the only ergonomic
setter sits inside that adjustment.
I grepped the test tree and MemoryManagement.java was the only sub-1M value, so
you have them all.
Now that the message is reachable, could it print the minimum too? Someone who
typed 16 meaning 16m is told they are below the minimum without being told what
it is.
-------------
Marked as reviewed by aivy (Author).
PR Review: https://git.openjdk.org/jdk/pull/32749#pullrequestreview-5137163518