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).
This pull request has now been integrated.
Changeset: 041f89ab
Author: Yunbo Zhang <[email protected]>
Committer: Thomas Schatzl <[email protected]>
URL:
https://git.openjdk.org/jdk/commit/041f89ab1e74b1e36da453f21083bc9f61eb2a14
Stats: 11 lines in 4 files changed: 2 ins; 0 del; 9 mod
8311029: G1: Check constraints before adjusting G1HeapRegionSize
Reviewed-by: aivy, tschatzl
-------------
PR: https://git.openjdk.org/jdk/pull/32749