Skip to content

Commit c9269bf

Browse files
committed
8255036: Shenandoah: Reset GC state for root verifier
Reviewed-by: rkennke
1 parent 839f01d commit c9269bf

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
#include "runtime/thread.hpp"
4141
#include "utilities/debug.hpp"
4242

43+
ShenandoahGCStateResetter::ShenandoahGCStateResetter() :
44+
_gc_state(ShenandoahHeap::heap()->gc_state()),
45+
_concurrent_weak_root_in_progress(ShenandoahHeap::heap()->is_concurrent_weak_root_in_progress()) {
46+
}
47+
48+
ShenandoahGCStateResetter::~ShenandoahGCStateResetter() {
49+
ShenandoahHeap* const heap = ShenandoahHeap::heap();
50+
heap->_gc_state.set(_gc_state);
51+
assert(heap->gc_state() == _gc_state, "Should be restored");
52+
heap->set_concurrent_weak_root_in_progress(_concurrent_weak_root_in_progress);
53+
}
54+
4355
// Check for overflow of number of root types.
4456
STATIC_ASSERT((static_cast<uint>(ShenandoahRootVerifier::AllRoots) + 1) > static_cast<uint>(ShenandoahRootVerifier::AllRoots));
4557

@@ -60,6 +72,8 @@ ShenandoahRootVerifier::RootTypes ShenandoahRootVerifier::combine(RootTypes t1,
6072
}
6173

6274
void ShenandoahRootVerifier::oops_do(OopClosure* oops) {
75+
ShenandoahGCStateResetter resetter;
76+
6377
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
6478
if (verify(CodeRoots)) {
6579
shenandoah_assert_locked_or_safepoint(CodeCache_lock);
@@ -108,6 +122,7 @@ void ShenandoahRootVerifier::oops_do(OopClosure* oops) {
108122
}
109123

110124
void ShenandoahRootVerifier::roots_do(OopClosure* oops) {
125+
ShenandoahGCStateResetter resetter;
111126
shenandoah_assert_safepoint();
112127

113128
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
@@ -133,6 +148,7 @@ void ShenandoahRootVerifier::roots_do(OopClosure* oops) {
133148
}
134149

135150
void ShenandoahRootVerifier::strong_roots_do(OopClosure* oops) {
151+
ShenandoahGCStateResetter resetter;
136152
shenandoah_assert_safepoint();
137153

138154
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
#include "memory/allocation.hpp"
2929
#include "memory/iterator.hpp"
3030

31+
class ShenandoahGCStateResetter : public StackObj {
32+
private:
33+
const char _gc_state;
34+
const bool _concurrent_weak_root_in_progress;
35+
36+
public:
37+
ShenandoahGCStateResetter();
38+
~ShenandoahGCStateResetter();
39+
};
40+
3141
class ShenandoahRootVerifier : public StackObj {
3242
public:
3343
enum RootTypes {

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -592,23 +592,6 @@ class VerifyThreadGCState : public ThreadClosure {
592592
}
593593
};
594594

595-
class ShenandoahGCStateResetter : public StackObj {
596-
private:
597-
ShenandoahHeap* const _heap;
598-
char _gc_state;
599-
600-
public:
601-
ShenandoahGCStateResetter() : _heap(ShenandoahHeap::heap()) {
602-
_gc_state = _heap->gc_state();
603-
_heap->_gc_state.clear();
604-
}
605-
606-
~ShenandoahGCStateResetter() {
607-
_heap->_gc_state.set(_gc_state);
608-
assert(_heap->gc_state() == _gc_state, "Should be restored");
609-
}
610-
};
611-
612595
void ShenandoahVerifier::verify_at_safepoint(const char *label,
613596
VerifyForwarded forwarded, VerifyMarked marked,
614597
VerifyCollectionSet cset,

0 commit comments

Comments
 (0)