Skip to content

Commit aa2cdb3

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

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
@@ -1702,7 +1702,7 @@ void ShenandoahHeap::prepare_update_heap_references(bool concurrent) {
17021702
_update_refs_iterator.reset();
17031703
}
17041704

1705-
void ShenandoahHeap::set_gc_state_all_threads() {
1705+
void ShenandoahHeap::propagate_gc_state_to_java_threads() {
17061706
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
17071707
if (_gc_state_changed) {
17081708
_gc_state_changed = false;
@@ -1713,21 +1713,21 @@ void ShenandoahHeap::set_gc_state_all_threads() {
17131713
}
17141714
}
17151715

1716-
void ShenandoahHeap::set_gc_state_mask(uint mask, bool value) {
1716+
void ShenandoahHeap::set_gc_state(uint mask, bool value) {
17171717
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at Shenandoah safepoint");
17181718
_gc_state.set_cond(mask, value);
17191719
_gc_state_changed = true;
17201720
}
17211721

17221722
void ShenandoahHeap::set_concurrent_mark_in_progress(bool in_progress) {
17231723
assert(!has_forwarded_objects(), "Not expected before/after mark phase");
1724-
set_gc_state_mask(MARKING, in_progress);
1724+
set_gc_state(MARKING, in_progress);
17251725
ShenandoahBarrierSet::satb_mark_queue_set().set_active_all_threads(in_progress, !in_progress);
17261726
}
17271727

17281728
void ShenandoahHeap::set_evacuation_in_progress(bool in_progress) {
17291729
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Only call this at safepoint");
1730-
set_gc_state_mask(EVACUATION, in_progress);
1730+
set_gc_state(EVACUATION, in_progress);
17311731
}
17321732

17331733
void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
@@ -1739,7 +1739,7 @@ void ShenandoahHeap::set_concurrent_strong_root_in_progress(bool in_progress) {
17391739
}
17401740

17411741
void ShenandoahHeap::set_concurrent_weak_root_in_progress(bool cond) {
1742-
set_gc_state_mask(WEAK_ROOTS, cond);
1742+
set_gc_state(WEAK_ROOTS, cond);
17431743
}
17441744

17451745
GCTracer* ShenandoahHeap::tracer() {
@@ -1857,7 +1857,7 @@ void ShenandoahHeap::parallel_cleaning(bool full_gc) {
18571857
}
18581858

18591859
void ShenandoahHeap::set_has_forwarded_objects(bool cond) {
1860-
set_gc_state_mask(HAS_FORWARDED, cond);
1860+
set_gc_state(HAS_FORWARDED, cond);
18611861
}
18621862

18631863
void ShenandoahHeap::set_unload_classes(bool uc) {
@@ -1900,7 +1900,7 @@ void ShenandoahHeap::set_full_gc_move_in_progress(bool in_progress) {
19001900
}
19011901

19021902
void ShenandoahHeap::set_update_refs_in_progress(bool in_progress) {
1903-
set_gc_state_mask(UPDATEREFS, in_progress);
1903+
set_gc_state(UPDATEREFS, in_progress);
19041904
}
19051905

19061906
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
@@ -100,6 +100,7 @@ class ShenandoahThreadLocalData {
100100
}
101101

102102
static char gc_state(Thread* thread) {
103+
assert(thread->is_Java_thread(), "GC state is only synchronized to java threads");
103104
return data(thread)->_gc_state;
104105
}
105106

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
@@ -619,7 +619,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char *label,
619619
guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
620620
guarantee(ShenandoahVerify, "only when enabled, and bitmap is initialized in ShenandoahHeap::initialize");
621621

622-
ShenandoahHeap::heap()->set_gc_state_all_threads();
622+
ShenandoahHeap::heap()->propagate_gc_state_to_java_threads();
623623

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

0 commit comments

Comments
 (0)