Skip to content

Commit e3b6098

Browse files
William Kempershipilev
authored andcommitted
8322503: Shenandoah: Clarify gc state usage
Reviewed-by: shade Backport-of: 51238c4bdbce48f6b719f7dcfe5b7df8b8c6d85b
1 parent 93fd1a1 commit e3b6098

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
@@ -1682,7 +1682,7 @@ void ShenandoahHeap::prepare_update_heap_references(bool concurrent) {
16821682
_update_refs_iterator.reset();
16831683
}
16841684

1685-
void ShenandoahHeap::set_gc_state_all_threads() {
1685+
void ShenandoahHeap::propagate_gc_state_to_java_threads() {
16861686
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
16871687
if (_gc_state_changed) {
16881688
_gc_state_changed = false;
@@ -1693,21 +1693,21 @@ void ShenandoahHeap::set_gc_state_all_threads() {
16931693
}
16941694
}
16951695

1696-
void ShenandoahHeap::set_gc_state_mask(uint mask, bool value) {
1696+
void ShenandoahHeap::set_gc_state(uint mask, bool value) {
16971697
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
16981698
_gc_state.set_cond(mask, value);
16991699
_gc_state_changed = true;
17001700
}
17011701

17021702
void ShenandoahHeap::set_concurrent_mark_in_progress(bool in_progress) {
17031703
assert(!has_forwarded_objects(), "Not expected before/after mark phase");
1704-
set_gc_state_mask(MARKING, in_progress);
1704+
set_gc_state(MARKING, in_progress);
17051705
ShenandoahBarrierSet::satb_mark_queue_set().set_active_all_threads(in_progress, !in_progress);
17061706
}
17071707

17081708
void ShenandoahHeap::set_evacuation_in_progress(bool in_progress) {
17091709
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Only call this at safepoint");
1710-
set_gc_state_mask(EVACUATION, in_progress);
1710+
set_gc_state(EVACUATION, in_progress);
17111711
}
17121712

17131713
void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
@@ -1719,7 +1719,7 @@ void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
17191719
}
17201720

17211721
void ShenandoahHeap::set_concurrent_weak_root_in_progress(bool cond) {
1722-
set_gc_state_mask(WEAK_ROOTS, cond);
1722+
set_gc_state(WEAK_ROOTS, cond);
17231723
}
17241724

17251725
GCTracer* ShenandoahHeap::tracer() {
@@ -1838,7 +1838,7 @@ void ShenandoahHeap::parallel_cleaning(bool full_gc) {
18381838
}
18391839

18401840
void ShenandoahHeap::set_has_forwarded_objects(bool cond) {
1841-
set_gc_state_mask(HAS_FORWARDED, cond);
1841+
set_gc_state(HAS_FORWARDED, cond);
18421842
}
18431843

18441844
void ShenandoahHeap::set_unload_classes(bool uc) {
@@ -1877,7 +1877,7 @@ void ShenandoahHeap::set_full_gc_move_in_progress(bool in_progress) {
18771877
}
18781878

18791879
void ShenandoahHeap::set_update_refs_in_progress(bool in_progress) {
1880-
set_gc_state_mask(UPDATEREFS, in_progress);
1880+
set_gc_state(UPDATEREFS, in_progress);
18811881
}
18821882

18831883
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
@@ -289,12 +289,19 @@ class ShenandoahHeap : public CollectedHeap {
289289
ShenandoahSharedFlag _progress_last_gc;
290290
ShenandoahSharedFlag _concurrent_strong_root_in_progress;
291291

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

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

299306
void set_concurrent_mark_in_progress(bool in_progress);
300307
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)