RFR: 8367754: G1: Add a fast path in heap resize related method [v3]

Thomas Schatzl tschatzl at openjdk.org
Fri Sep 19 07:40:09 UTC 2025


On Thu, 18 Sep 2025 03:32:16 GMT, Guanqiang Han <ghan at openjdk.org> wrote:

>> Please review this change.
>> 
>> **Description:**
>> 
>> It's common for some Java application engineers to configure the heap with the same minimum and maximum size in order to avoid the overhead of heap resizing.In such cases no expansion or shrinkage is possible, so i think we can adds a fast path at the beginning of the method to detect when the heap’s min and max capacities are equal and return early, thereby avoiding unnecessary computation.
>> I added a check to determine whether MinHeapSize and MaxHeapSize are equal before performing the heap resize calculation. Since both MaxHeapSize and MinHeapSize are aligned to HeapAlignment, so  i think comparing them directly is good.
>> 
>> **Test:**
>> 
>> GHA
>
> Guanqiang Han has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update TestHeapResizeAfterGC.java
>   
>   correct format error

Changes requested by tschatzl (Reviewer).

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

> 892:   // cannot expand or shrink.
> 893:   if (is_fixed_size_heap()) {
> 894:     log_debug(gc, ergo, heap)("Skip heap resize after full collection.");

The comment should explain why we skip too. I.e. `Skip heap resize after full collection because heap size is fixed` or so.

src/hotspot/share/gc/g1/g1CollectedHeap.hpp line 1062:

> 1060:   // thus cannot expand or shrink.
> 1061:   bool _fixed_size_heap;
> 1062: 

I prefer to not use an additional local - repeating the comparison is never significant enough to slow down performance imo, and both `MinHeapSize` and `MaxHeapSize` can not change.

test/hotspot/jtreg/gc/g1/TestHeapResizeAfterGC.java line 26:

> 24: /* @test
> 25:  * @bug 8367754
> 26:  * @summary Verify fast path before performing heap resize.

Suggestion:

 * @summary Verify fast path before performing heap resize if the command line options prohibit resizing.

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

PR Review: https://git.openjdk.org/jdk/pull/27349#pullrequestreview-3243544451
PR Review Comment: https://git.openjdk.org/jdk/pull/27349#discussion_r2362027897
PR Review Comment: https://git.openjdk.org/jdk/pull/27349#discussion_r2362026251
PR Review Comment: https://git.openjdk.org/jdk/pull/27349#discussion_r2362055469


More information about the hotspot-gc-dev mailing list