Skip to content

Commit

Permalink
Backport b32e4a68bca588d908bd81a398eb3171a6876dc5
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaolong Peng authored and earthling-amzn committed Sep 26, 2024
1 parent 3d9f0ab commit 070339c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ void ShenandoahRegionPartitions::assert_bounds() {
ShenandoahFreeSet::ShenandoahFreeSet(ShenandoahHeap* heap, size_t max_regions) :
_heap(heap),
_partitions(max_regions, this),
_trash_regions(NEW_C_HEAP_ARRAY(ShenandoahHeapRegion*, max_regions, mtGC)),
_alloc_bias_weight(0)
{
clear_internal();
Expand Down Expand Up @@ -1217,7 +1218,7 @@ HeapWord* ShenandoahFreeSet::allocate_contiguous(ShenandoahAllocRequest& req) {
return _heap->get_region(beg)->bottom();
}

void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion *r) {
void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion* r) {
if (r->is_trash()) {
r->recycle();
}
Expand All @@ -1226,13 +1227,24 @@ void ShenandoahFreeSet::try_recycle_trashed(ShenandoahHeapRegion *r) {
void ShenandoahFreeSet::recycle_trash() {
// lock is not reentrable, check we don't have it
shenandoah_assert_not_heaplocked();
size_t count = 0;
for (size_t i = 0; i < _heap->num_regions(); i++) {
ShenandoahHeapRegion* r = _heap->get_region(i);
if (r->is_trash()) {
ShenandoahHeapLocker locker(_heap->lock());
try_recycle_trashed(r);
_trash_regions[count++] = r;
}
}

// Relinquish the lock after this much time passed.
static constexpr jlong deadline_ns = 30000; // 30 us
size_t idx = 0;
while (idx < count) {
os::naked_yield(); // Yield to allow allocators to take the lock
ShenandoahHeapLocker locker(_heap->lock());
const jlong deadline = os::javaTimeNanos() + deadline_ns;
while (idx < count && os::javaTimeNanos() < deadline) {
try_recycle_trashed(_trash_regions[idx++]);
}
SpinPause(); // allow allocators to take the lock
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahFreeSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class ShenandoahFreeSet : public CHeapObj<mtGC> {
private:
ShenandoahHeap* const _heap;
ShenandoahRegionPartitions _partitions;
size_t _retired_old_regions;
ShenandoahHeapRegion** _trash_regions;

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

Expand Down

0 comments on commit 070339c

Please sign in to comment.