Skip to content

Commit 2c22b6a

Browse files
author
William Kemper
committed
8335356: Shenandoah: Improve concurrent cleanup locking
Reviewed-by: ysr Backport-of: b32e4a6
1 parent 3d9f0ab commit 2c22b6a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ void ShenandoahRegionPartitions::assert_bounds() {
669669
ShenandoahFreeSet::ShenandoahFreeSet(ShenandoahHeap* heap, size_t max_regions) :
670670
_heap(heap),
671671
_partitions(max_regions, this),
672+
_trash_regions(NEW_C_HEAP_ARRAY(ShenandoahHeapRegion*, max_regions, mtGC)),
672673
_alloc_bias_weight(0)
673674
{
674675
clear_internal();
@@ -1217,7 +1218,7 @@ HeapWord* ShenandoahFreeSet::allocate_contiguous(ShenandoahAllocRequest& req) {
12171218
return _heap->get_region(beg)->bottom();
12181219
}
12191220

1220-
void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion *r) {
1221+
void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion* r) {
12211222
if (r->is_trash()) {
12221223
r->recycle();
12231224
}
@@ -1226,13 +1227,24 @@ void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion *r) {
12261227
void ShenandoahFreeSet::recycle_trash() {
12271228
// lock is not reentrable, check we don't have it
12281229
shenandoah_assert_not_heaplocked();
1230+
size_t count = 0;
12291231
for (size_t i = 0; i < _heap->num_regions(); i++) {
12301232
ShenandoahHeapRegion* r = _heap->get_region(i);
12311233
if (r->is_trash()) {
1232-
ShenandoahHeapLocker locker(_heap->lock());
1233-
try_recycle_trashed(r);
1234+
_trash_regions[count++] = r;
1235+
}
1236+
}
1237+
1238+
// Relinquish the lock after this much time passed.
1239+
static constexpr jlong deadline_ns = 30000; // 30 us
1240+
size_t idx = 0;
1241+
while (idx < count) {
1242+
os::naked_yield(); // Yield to allow allocators to take the lock
1243+
ShenandoahHeapLocker locker(_heap->lock());
1244+
const jlong deadline = os::javaTimeNanos() + deadline_ns;
1245+
while (idx < count && os::javaTimeNanos() < deadline) {
1246+
try_recycle_trashed(_trash_regions[idx++]);
12341247
}
1235-
SpinPause(); // allow allocators to take the lock
12361248
}
12371249
}
12381250

src/hotspot/share/gc/shenandoah/shenandoahFreeSet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class ShenandoahFreeSet : public CHeapObj<mtGC> {
287287
private:
288288
ShenandoahHeap* const _heap;
289289
ShenandoahRegionPartitions _partitions;
290-
size_t _retired_old_regions;
290+
ShenandoahHeapRegion** _trash_regions;
291291

292292
HeapWord* allocate_aligned_plab(size_t size, ShenandoahAllocRequest& req, ShenandoahHeapRegion* r);
293293

0 commit comments

Comments
 (0)