Skip to content
18 changes: 13 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,24 +566,28 @@ void ShenandoahHeapRegion::recycle_internal() {
ShenandoahHeap* heap = ShenandoahHeap::heap();

_mixed_candidate_garbage_words = 0;
set_top(bottom());
clear_live_data();
reset_alloc_metadata();
heap->marking_context()->reset_top_at_mark_start(this);
set_update_watermark(bottom());
if (ZapUnusedHeapArea) {
SpaceMangler::mangle_region(MemRegion(bottom(), end()));
}
set_top(bottom());
set_affiliation(FREE);

// Lastly, set region state to empty
make_empty();
set_affiliation(FREE);
}

// Upon return, this region has been recycled. We try to recycle it.
// We may fail if some other thread recycled it before we do.
void ShenandoahHeapRegion::try_recycle_under_lock() {
shenandoah_assert_heaplocked();
if (is_trash() && _recycling.try_set()) {
if (!is_trash()) {
return;
}
if (_recycling.try_set()) {
if (is_trash()) {
// At freeset rebuild time, which precedes recycling of collection set, we treat all cset regions as
// part of capacity, as empty, as fully available, and as unaffiliated. This provides short-lived optimism
Expand All @@ -603,14 +607,18 @@ void ShenandoahHeapRegion::try_recycle_under_lock() {
os::naked_yield();
}
}
assert(!is_trash(), "Must not");
}
}

// Note that return from try_recycle() does not mean the region has been recycled. It only means that
// some GC worker thread has taken responsibility to recycle the region, eventually.
void ShenandoahHeapRegion::try_recycle() {
shenandoah_assert_not_heaplocked();
if (is_trash() && _recycling.try_set()) {
if (!is_trash()) {
return;
}
if (_recycling.try_set()) {
// Double check region state after win the race to set recycling flag
if (is_trash()) {
// At freeset rebuild time, which precedes recycling of collection set, we treat all cset regions as
Expand Down Expand Up @@ -834,7 +842,7 @@ void ShenandoahHeapRegion::set_state(RegionState to) {
evt.set_to(to);
evt.commit();
}
_state.store_relaxed(to);
_state.release_store(to);
}

void ShenandoahHeapRegion::record_pin() {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ShenandoahHeapRegion {
bool is_alloc_allowed() const { auto cur_state = state(); return is_empty_state(cur_state) || cur_state == _regular || cur_state == _pinned; }
bool is_stw_move_allowed() const { auto cur_state = state(); return cur_state == _regular || cur_state == _cset || (ShenandoahHumongousMoves && cur_state == _humongous_start); }

RegionState state() const { return _state.load_relaxed(); }
RegionState state() const { return _state.load_acquire(); }
int state_ordinal() const { return region_state_to_ordinal(state()); }

void record_pin();
Expand Down