RFR: 8361099: Shenandoah: Improve heap lock contention by using CAS for memory allocation [v20]
Xiaolong Peng
xpeng at openjdk.org
Fri Jan 16 01:20:42 UTC 2026
On Tue, 6 Jan 2026 01:19:29 GMT, Kelvin Nilsen <kdnilsen at openjdk.org> wrote:
>> Xiaolong Peng has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 265 commits:
>>
>> - Merge branch 'openjdk:master' into cas-alloc-1
>> - Fix build error after merging from tip
>> - Merge branch 'master' into cas-alloc-1
>> - Merge branch 'master' into cas-alloc-1
>> - Some comments updates as suggested in PR review
>> - Fix build failure after merge
>> - Expend promoted from ShenandoahOldCollectorAllocator
>> - Merge branch 'master' into cas-alloc-1
>> - Address PR comments
>> - Merge branch 'openjdk:master' into cas-alloc-1
>> - ... and 255 more: https://git.openjdk.org/jdk/compare/de81d389...cf13b7b5
>
> src/hotspot/share/gc/shenandoah/shenandoahAllocator.hpp line 91:
>
>> 89: virtual HeapWord* allocate(ShenandoahAllocRequest& req, bool& in_new_region);
>> 90: virtual void release_alloc_regions();
>> 91: virtual void reserve_alloc_regions();
>
> Need comments on these functions. Clarify pre-conditions and post-conditions. I think the intention is:
>
> 1. allocate(): Caller does not hold the heap lock. All allocations by mutator or GC are fulfilled by this function. This function tries to perform a CAS allocation without obtaining the global heap lock. If that fails, it will obtain the global heap lock and do a free-set allocation. As a side effect of doing a free-set allocation, some number of directly allocatable regions may be retired and replaced with new directly allocatable regions.
> 2. release_alloc_regions(): Caller must hold the heap lock. This causes all directly allocatable regions to be placed into the appropriate ShenandoahFreeSet partition. We do this in preparation for choosing a collection set and/or rebuilding the freeset.
> 3. reserve_alloc_regions(): Caller must hold the heap lock. This causes us to set aside N regions as directly allocatable by removing these regions from the relevant ShenandoahFreeSet partitions. Explain what happens if there are not N regions available.
>
> Clarify: these three function represent the entirety of the "public mutation API" that is exercised by mutators and GC workers as they interact with the free set? (There is another set of functions that could be characterized as the read-only API for obtaining state information about the free set. This provides information such as available memory, allocated bytes since GC start, etc.)
Thanks, I have updated the comments on these public APIs.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26171#discussion_r2696512842
More information about the shenandoah-dev
mailing list