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:44 UTC 2025


On Wed, 3 Dec 2025 01:13:41 GMT, Xiaolong Peng <xpeng at openjdk.org> wrote:

>> 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.

accounting_update is required for slow path, but you are right, it can be moved to somewhere later, e.g. line 128.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26171#discussion_r2583298253


More information about the shenandoah-dev mailing list