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).

-------------

Commit messages:
 - 8311029: G1: Check constraints before adjusting G1HeapRegionSize

Changes: https://git.openjdk.org/jdk/pull/32749/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32749&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8311029
  Stats: 9 lines in 4 files changed: 2 ins; 0 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/32749.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/32749/head:pull/32749

PR: https://git.openjdk.org/jdk/pull/32749

Reply via email to