RFR: 8361099: Shenandoah: Improve heap lock contention by using CAS for memory allocation [v14]
Xiaolong Peng
xpeng at openjdk.org
Wed Dec 3 01:17:43 UTC 2025
On Tue, 2 Dec 2025 22:24:55 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 255 commits:
>>
>> - Add missing header for ShenandoahFreeSetPartitionId
>> - Declare ShenandoahFreeSetPartitionId as enum instead of enum class
>> - Fix a typo
>> - Remove unnecessary `enum class ShenandoahFreeSetPartitionId : uint8_t` in shenandoahAllocator.php
>> - Make ShenandoahAllocator as template class to make compiled code more efficient for each alloc partition
>> - Port the fix of JDK-8372566
>> - Merge branch 'master' into cas-alloc-1
>> - Merge remote-tracking branch 'origin/master' into cas-alloc-1
>> - Remove junk code
>> - Remove unnecessary change and tidy up
>> - ... and 245 more: https://git.openjdk.org/jdk/compare/79e99bb0...7980c039
>
> src/hotspot/share/gc/shenandoah/shenandoahAllocator.cpp line 121:
>
>> 119: template <ShenandoahFreeSetPartitionId ALLOC_PARTITION>
>> 120: HeapWord* ShenandoahAllocator<ALLOC_PARTITION>::attempt_allocation_slow(ShenandoahAllocRequest& req, bool& in_new_region) {
>> 121: ShenandoahHeapLocker locker(ShenandoahHeap::heap()->lock(), _yield_to_safepoint);
>
> I think this is an error. We don't want to acquire the lock here. We also don't want to introduce accounting_update here. Instead, I think these belong before line 130, in case we need to refresh the alloc regions.
It is not an error, before calling into attempt_allocation_slow, it already called attempt_allocation_in_alloc_regions once and failed to allocate, slow path is always with heap lock.
After taking the lock, we should try the attempt_allocation_in_alloc_regions right away, because other mutator thread may have refreshed the alloc regions while holding the lock.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26171#discussion_r2583295858
More information about the shenandoah-dev
mailing list