Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit afce5e6

Browse files
William Kempershipilev
authored andcommitted
8322503: Shenandoah: Clarify gc state usage
Backport-of: 51238c4bdbce48f6b719f7dcfe5b7df8b8c6d85b
1 parent 6c2eefc commit afce5e6

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ void ShenandoahHeap::prepare_update_heap_references(bool concurrent) {
17421742
_update_refs_iterator.reset();
17431743
}
17441744

1745-
void ShenandoahHeap::set_gc_state_all_threads() {
1745+
void ShenandoahHeap::propagate_gc_state_to_java_threads() {
17461746
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
17471747
if (_gc_state_changed) {
17481748
_gc_state_changed = false;
@@ -1753,21 +1753,21 @@ void ShenandoahHeap::set_gc_state_all_threads() {
17531753
}
17541754
}
17551755

1756-
void ShenandoahHeap::set_gc_state_mask(uint mask, bool value) {
1756+
void ShenandoahHeap::set_gc_state(uint mask, bool value) {
17571757
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
17581758
_gc_state.set_cond(mask, value);
17591759
_gc_state_changed = true;
17601760
}
17611761

17621762
void ShenandoahHeap::set_concurrent_mark_in_progress(bool in_progress) {
17631763
assert(!has_forwarded_objects(), "Not expected before/after mark phase");
1764-
set_gc_state_mask(MARKING, in_progress);
1764+
set_gc_state(MARKING, in_progress);
17651765
ShenandoahBarrierSet::satb_mark_queue_set().set_active_all_threads(in_progress, !in_progress);
17661766
}
17671767

17681768
void ShenandoahHeap::set_evacuation_in_progress(bool in_progress) {
17691769
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Only call this at safepoint");
1770-
set_gc_state_mask(EVACUATION, in_progress);
1770+
set_gc_state(EVACUATION, in_progress);
17711771
}
17721772

17731773
void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
@@ -1779,7 +1779,7 @@ void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
17791779
}
17801780

17811781
void ShenandoahHeap::set_concurrent_weak_root_in_progress(bool cond) {
1782-
set_gc_state_mask(WEAK_ROOTS, cond);
1782+
set_gc_state(WEAK_ROOTS, cond);
17831783
}
17841784

17851785
GCTracer* ShenandoahHeap::tracer() {
@@ -1905,7 +1905,7 @@ void ShenandoahHeap::parallel_cleaning(bool full_gc) {
19051905
}
19061906

19071907
void ShenandoahHeap::set_has_forwarded_objects(bool cond) {
1908-
set_gc_state_mask(HAS_FORWARDED, cond);
1908+
set_gc_state(HAS_FORWARDED, cond);
19091909
}
19101910

19111911
void ShenandoahHeap::set_unload_classes(bool uc) {
@@ -1944,7 +1944,7 @@ void ShenandoahHeap::set_full_gc_move_in_progress(bool in_progress) {
19441944
}
19451945

19461946
void ShenandoahHeap::set_update_refs_in_progress(bool in_progress) {
1947-
set_gc_state_mask(UPDATEREFS, in_progress);
1947+
set_gc_state(UPDATEREFS, in_progress);
19481948
}
19491949

19501950
void ShenandoahHeap::register_nmethod(nmethod* nm) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,19 @@ class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
293293

294294
size_t _gc_no_progress_count;
295295

296-
void set_gc_state_mask(uint mask, bool value);
296+
// This updates the singlular, global gc state. This must happen on a safepoint.
297+
void set_gc_state(uint mask, bool value);
297298

298299
public:
299300
char gc_state() const;
300-
void set_gc_state_all_threads();
301-
bool has_gc_state_changed() { return _gc_state_changed; }
301+
302+
// This copies the global gc state into a thread local variable for java threads.
303+
// It is primarily intended to support quick access at barriers.
304+
void propagate_gc_state_to_java_threads();
305+
306+
// This is public to support assertions that the state hasn't been changed off of
307+
// a safepoint and that any changes were propagated to java threads after the safepoint.
308+
bool has_gc_state_changed() const { return _gc_state_changed; }
302309

303310
void set_concurrent_mark_in_progress(bool in_progress);
304311
void set_evacuation_in_progress(bool in_progress);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ShenandoahThreadLocalData {
8989
}
9090

9191
static char gc_state(Thread* thread) {
92+
assert(thread->is_Java_thread(), "GC state is only synchronized to java threads");
9293
return data(thread)->_gc_state;
9394
}
9495

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,41 @@ void VM_ShenandoahReferenceOperation::doit_epilogue() {
6262
void VM_ShenandoahInitMark::doit() {
6363
ShenandoahGCPauseMark mark(_gc_id, "Init Mark", SvcGCMarker::CONCURRENT);
6464
_gc->entry_init_mark();
65-
ShenandoahHeap::heap()->set_gc_state_all_threads();
65+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
6666
}
6767

6868
void VM_ShenandoahFinalMarkStartEvac::doit() {
6969
ShenandoahGCPauseMark mark(_gc_id, "Final Mark", SvcGCMarker::CONCURRENT);
7070
_gc->entry_final_mark();
71-
ShenandoahHeap::heap()->set_gc_state_all_threads();
71+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
7272
}
7373

7474
void VM_ShenandoahFullGC::doit() {
7575
ShenandoahGCPauseMark mark(_gc_id, "Full GC", SvcGCMarker::FULL);
7676
_full_gc->entry_full(_gc_cause);
77-
ShenandoahHeap::heap()->set_gc_state_all_threads();
77+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
7878
}
7979

8080
void VM_ShenandoahDegeneratedGC::doit() {
8181
ShenandoahGCPauseMark mark(_gc_id, "Degenerated GC", SvcGCMarker::CONCURRENT);
8282
_gc->entry_degenerated();
83-
ShenandoahHeap::heap()->set_gc_state_all_threads();
83+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
8484
}
8585

8686
void VM_ShenandoahInitUpdateRefs::doit() {
8787
ShenandoahGCPauseMark mark(_gc_id, "Init Update Refs", SvcGCMarker::CONCURRENT);
8888
_gc->entry_init_updaterefs();
89-
ShenandoahHeap::heap()->set_gc_state_all_threads();
89+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
9090
}
9191

9292
void VM_ShenandoahFinalUpdateRefs::doit() {
9393
ShenandoahGCPauseMark mark(_gc_id, "Final Update Refs", SvcGCMarker::CONCURRENT);
9494
_gc->entry_final_updaterefs();
95-
ShenandoahHeap::heap()->set_gc_state_all_threads();
95+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
9696
}
9797

9898
void VM_ShenandoahFinalRoots::doit() {
9999
ShenandoahGCPauseMark mark(_gc_id, "Final Roots", SvcGCMarker::CONCURRENT);
100100
_gc->entry_final_roots();
101-
ShenandoahHeap::heap()->set_gc_state_all_threads();
101+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
102102
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char *label,
620620
guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
621621
guarantee(ShenandoahVerify, "only when enabled, and bitmap is initialized in ShenandoahHeap::initialize");
622622

623-
ShenandoahHeap::heap()->set_gc_state_all_threads();
623+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
624624

625625
// Avoid side-effect of changing workers' active thread count, but bypass concurrent/parallel protocol check
626626
ShenandoahPushWorkerScope verify_worker_scope(_heap->workers(), _heap->max_workers(), false /*bypass check*/);

0 commit comments

Comments
 (0)