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

Albert Mingkun Yang ayang at openjdk.org
Thu Sep 18 13:18:43 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

> ... thereby avoiding unnecessary computation

That's absolutely true; however, the real expensive part is not the calculation but actual resizing (commit/uncommit).

Since the existing logic is not simplified by the use of early-return, I feel it hinders readability slightly. I wonder what others think.

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

PR Comment: https://git.openjdk.org/jdk/pull/27349#issuecomment-3307400985


More information about the hotspot-gc-dev mailing list