RFR: 8361099: Shenandoah: Improve heap lock contention by using CAS for memory allocation [v5]

Xiaolong Peng xpeng at openjdk.org
Tue Nov 11 20:02:13 UTC 2025


On Wed, 5 Nov 2025 22:17:54 GMT, Kelvin Nilsen <kdnilsen at openjdk.org> wrote:

>> src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp line 2280:
>> 
>>> 2278: }
>>> 2279: 
>>> 2280: class DirectAllocatableRegionRefillClosure final : public ShenandoahHeapRegionIterationClosure {
>> 
>> I don't think we want to subclass ShenandoahHeapRegionIterationClosure here.  That iterates over all 2000 regions.  We only want to iterate over the 13 Directly allocatable regions.  Maybe we don't even need/want a closure iterator here.  We could just write a loop.
>
> I think we should be borrowing from this code when replenishing the regions that are ready to be retired:
> 
>   if (_partitions.alloc_from_left_bias(ShenandoahFreeSetPartitionId::Mutator)) {
>     // Allocate from low to high memory.  This keeps the range of fully empty regions more tightly packed.
>     // Note that the most recently allocated regions tend not to be evacuated in a given GC cycle.  So this
>     // tends to accumulate "fragmented" uncollected regions in high memory.
>     ShenandoahLeftRightIterator iterator(&_partitions, ShenandoahFreeSetPartitionId::Mutator);
>     return allocate_from_regions(iterator, req, in_new_region);
>   }
> 
>   // Allocate from high to low memory. This preserves low memory for humongous allocations.
>   ShenandoahRightLeftIterator iterator(&_partitions, ShenandoahFreeSetPartitionId::Mutator);
>   return allocate_from_regions(iterator, req, in_new_region);

Thanks, the closure I am using here returns a bool indicating when it needs to break out the iteration. We can get rid of the ShenandoahHeapRegionIterationClosure here, I'll replace it with simple loop.

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

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


More information about the hotspot-gc-dev mailing list