RFR: 8371019: G1: Support heap expansion during startup

Erik Österlund eosterlund at openjdk.org
Mon Nov 10 10:32:38 UTC 2025


On Mon, 10 Nov 2025 09:32:32 GMT, Stefan Johansson <sjohanss at openjdk.org> wrote:

> Please review this change to allow G1 to expand the initial heap during startup
> 
> **Summary**
> Currently G1 shuts down during startup if we allocate more memory than what's available in the initial young generation. The reason is that we can't allow GCs during initialization. To allow G1 to work in situations requiring additional memory during initialization, this change enables G1 to expand the initial young generation size all the way up the maximum heap size. When initialization is complete mutator allocations will no longer expand the heap.
> 
> **Testing**
> * Mach 5 tier1-5
> * Manual testing requiring additional allocations during startup

Thanks for fixing this Stefan! Might have found an assert issue.

I see now how the assert works: it only checks for the VM thread if not owning the heap lock, so I think it won't be an issue. Looks good.

src/hotspot/share/gc/g1/g1CollectedHeap.cpp line 3107:

> 3105:     G1HeapRegion* new_alloc_region = new_region(word_size,
> 3106:                                                 G1HeapRegionType::Eden,
> 3107:                                                 policy()->should_expand_on_mutator_allocation() /* do_expand */,

On line 3102 above, there is an assert looking like this:
```assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);```
The assumption seems to be that this is the VM thread. That won't be the case when exapnding from a mutator, right?

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

Changes requested by eosterlund (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28213#pullrequestreview-3442142270
Marked as reviewed by eosterlund (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28213#pullrequestreview-3442232032
PR Review Comment: https://git.openjdk.org/jdk/pull/28213#discussion_r2509693488


More information about the hotspot-gc-dev mailing list