Skip to content

Commit 7b924d8

Browse files
committed
8261973: Shenandoah: Cleanup/simplify root verifier
Reviewed-by: rkennke
1 parent 63f8fc8 commit 7b924d8

File tree

4 files changed

+39
-188
lines changed

4 files changed

+39
-188
lines changed

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

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,69 +55,6 @@ ShenandoahGCStateResetter::~ShenandoahGCStateResetter() {
5555
_heap->set_concurrent_weak_root_in_progress(_concurrent_weak_root_in_progress);
5656
}
5757

58-
// Check for overflow of number of root types.
59-
STATIC_ASSERT((static_cast<uint>(ShenandoahRootVerifier::AllRoots) + 1) > static_cast<uint>(ShenandoahRootVerifier::AllRoots));
60-
61-
ShenandoahRootVerifier::ShenandoahRootVerifier(RootTypes types) : _types(types) {
62-
Threads::change_thread_claim_token();
63-
}
64-
65-
void ShenandoahRootVerifier::excludes(RootTypes types) {
66-
_types = static_cast<ShenandoahRootVerifier::RootTypes>(static_cast<uint>(_types) & (~static_cast<uint>(types)));
67-
}
68-
69-
bool ShenandoahRootVerifier::verify(RootTypes type) const {
70-
return (_types & type) == type;
71-
}
72-
73-
ShenandoahRootVerifier::RootTypes ShenandoahRootVerifier::combine(RootTypes t1, RootTypes t2) {
74-
return static_cast<ShenandoahRootVerifier::RootTypes>(static_cast<uint>(t1) | static_cast<uint>(t2));
75-
}
76-
77-
void ShenandoahRootVerifier::oops_do(OopClosure* oops) {
78-
ShenandoahGCStateResetter resetter;
79-
80-
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
81-
if (verify(CodeRoots)) {
82-
shenandoah_assert_locked_or_safepoint(CodeCache_lock);
83-
CodeCache::blobs_do(&blobs);
84-
}
85-
86-
if (verify(CLDGRoots)) {
87-
shenandoah_assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
88-
CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
89-
ClassLoaderDataGraph::cld_do(&clds);
90-
}
91-
92-
if (verify(SerialRoots)) {
93-
shenandoah_assert_safepoint();
94-
}
95-
96-
if (verify(JNIHandleRoots)) {
97-
shenandoah_assert_safepoint();
98-
JNIHandles::oops_do(oops);
99-
Universe::vm_global()->oops_do(oops);
100-
}
101-
102-
if (verify(WeakRoots)) {
103-
shenandoah_assert_safepoint();
104-
weak_roots_do(oops);
105-
}
106-
107-
if (ShenandoahStringDedup::is_enabled() && verify(StringDedupRoots)) {
108-
shenandoah_assert_safepoint();
109-
ShenandoahStringDedup::oops_do_slow(oops);
110-
}
111-
112-
if (verify(ThreadRoots)) {
113-
shenandoah_assert_safepoint();
114-
// Do thread roots the last. This allows verification code to find
115-
// any broken objects from those special roots first, not the accidental
116-
// dangling reference from the thread root.
117-
Threads::possibly_parallel_oops_do(false, oops, &blobs);
118-
}
119-
}
120-
12158
void ShenandoahRootVerifier::roots_do(OopClosure* oops) {
12259
ShenandoahGCStateResetter resetter;
12360
shenandoah_assert_safepoint();
@@ -128,35 +65,37 @@ void ShenandoahRootVerifier::roots_do(OopClosure* oops) {
12865
CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
12966
ClassLoaderDataGraph::cld_do(&clds);
13067

131-
JNIHandles::oops_do(oops);
132-
Universe::vm_global()->oops_do(oops);
68+
if (ShenandoahStringDedup::is_enabled()) {
69+
ShenandoahStringDedup::oops_do_slow(oops);
70+
}
71+
72+
for (auto id : EnumRange<OopStorageSet::StrongId>()) {
73+
OopStorageSet::storage(id)->oops_do(oops);
74+
}
13375

13476
// Do thread roots the last. This allows verification code to find
13577
// any broken objects from those special roots first, not the accidental
13678
// dangling reference from the thread root.
137-
Threads::possibly_parallel_oops_do(true, oops, &blobs);
79+
Threads::possibly_parallel_oops_do(true, oops, NULL);
13880
}
13981

14082
void ShenandoahRootVerifier::strong_roots_do(OopClosure* oops) {
14183
ShenandoahGCStateResetter resetter;
14284
shenandoah_assert_safepoint();
14385

144-
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
145-
14686
CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
147-
ClassLoaderDataGraph::roots_cld_do(&clds, NULL);
87+
ClassLoaderDataGraph::always_strong_cld_do(&clds);
14888

149-
JNIHandles::oops_do(oops);
150-
Universe::vm_global()->oops_do(oops);
89+
if (ShenandoahStringDedup::is_enabled()) {
90+
ShenandoahStringDedup::oops_do_slow(oops);
91+
}
15192

93+
for (auto id : EnumRange<OopStorageSet::StrongId>()) {
94+
OopStorageSet::storage(id)->oops_do(oops);
95+
}
15296
// Do thread roots the last. This allows verification code to find
15397
// any broken objects from those special roots first, not the accidental
15498
// dangling reference from the thread root.
99+
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
155100
Threads::possibly_parallel_oops_do(true, oops, &blobs);
156101
}
157-
158-
void ShenandoahRootVerifier::weak_roots_do(OopClosure* cl) {
159-
for (auto id : EnumRange<OopStorageSet::WeakId>()) {
160-
OopStorageSet::storage(id)->oops_do(cl);
161-
}
162-
}

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

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,11 @@ class ShenandoahGCStateResetter : public StackObj {
3939
~ShenandoahGCStateResetter();
4040
};
4141

42-
class ShenandoahRootVerifier : public StackObj {
42+
class ShenandoahRootVerifier : public AllStatic {
4343
public:
44-
enum RootTypes {
45-
None = 0,
46-
SerialRoots = 1 << 0,
47-
ThreadRoots = 1 << 1,
48-
CodeRoots = 1 << 2,
49-
CLDGRoots = 1 << 3,
50-
WeakRoots = 1 << 4,
51-
StringDedupRoots = 1 << 5,
52-
JNIHandleRoots = 1 << 6,
53-
AllRoots = (SerialRoots | ThreadRoots | CodeRoots | CLDGRoots | WeakRoots | StringDedupRoots | JNIHandleRoots)
54-
};
55-
56-
private:
57-
RootTypes _types;
58-
59-
public:
60-
ShenandoahRootVerifier(RootTypes types = AllRoots);
61-
62-
void excludes(RootTypes types);
63-
void oops_do(OopClosure* cl);
64-
6544
// Used to seed ShenandoahVerifier, do not honor root type filter
66-
void roots_do(OopClosure* cl);
67-
void strong_roots_do(OopClosure* cl);
68-
69-
static RootTypes combine(RootTypes t1, RootTypes t2);
70-
private:
71-
bool verify(RootTypes type) const;
72-
73-
void weak_roots_do(OopClosure* cl);
45+
static void roots_do(OopClosure* cl);
46+
static void strong_roots_do(OopClosure* cl);
7447
};
7548

7649
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHROOTVERIFIER_HPP

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

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ class ShenandoahVerifyHeapRegionClosure : public ShenandoahHeapRegionClosure {
424424
class ShenandoahVerifierReachableTask : public AbstractGangTask {
425425
private:
426426
const char* _label;
427-
ShenandoahRootVerifier* _verifier;
428427
ShenandoahVerifier::VerifyOptions _options;
429428
ShenandoahHeap* _heap;
430429
ShenandoahLivenessData* _ld;
@@ -434,12 +433,10 @@ class ShenandoahVerifierReachableTask : public AbstractGangTask {
434433
public:
435434
ShenandoahVerifierReachableTask(MarkBitMap* bitmap,
436435
ShenandoahLivenessData* ld,
437-
ShenandoahRootVerifier* verifier,
438436
const char* label,
439437
ShenandoahVerifier::VerifyOptions options) :
440438
AbstractGangTask("Shenandoah Verifier Reachable Objects"),
441439
_label(label),
442-
_verifier(verifier),
443440
_options(options),
444441
_heap(ShenandoahHeap::heap()),
445442
_ld(ld),
@@ -464,9 +461,9 @@ class ShenandoahVerifierReachableTask : public AbstractGangTask {
464461
ShenandoahMessageBuffer("%s, Roots", _label),
465462
_options);
466463
if (_heap->unload_classes()) {
467-
_verifier->strong_roots_do(&cl);
464+
ShenandoahRootVerifier::strong_roots_do(&cl);
468465
} else {
469-
_verifier->roots_do(&cl);
466+
ShenandoahRootVerifier::roots_do(&cl);
470467
}
471468
}
472469

@@ -618,8 +615,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char *label,
618615
VerifyForwarded forwarded, VerifyMarked marked,
619616
VerifyCollectionSet cset,
620617
VerifyLiveness liveness, VerifyRegions regions,
621-
VerifyGCState gcstate,
622-
VerifyWeakRoots weak_roots) {
618+
VerifyGCState gcstate) {
623619
guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
624620
guarantee(ShenandoahVerify, "only when enabled, and bitmap is initialized in ShenandoahHeap::initialize");
625621

@@ -713,8 +709,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char *label,
713709
// This verifies what application can see, since it only cares about reachable objects.
714710
size_t count_reachable = 0;
715711
if (ShenandoahVerifyLevel >= 2) {
716-
ShenandoahRootVerifier verifier;
717-
ShenandoahVerifierReachableTask task(_verification_bit_map, ld, &verifier, label, options);
712+
ShenandoahVerifierReachableTask task(_verification_bit_map, ld, label, options);
718713
_heap->workers()->run_task(&task);
719714
count_reachable = task.processed();
720715
}
@@ -780,8 +775,7 @@ void ShenandoahVerifier::verify_generic(VerifyOption vo) {
780775
_verify_cset_disable, // cset may be inconsistent
781776
_verify_liveness_disable, // no reliable liveness data
782777
_verify_regions_disable, // no reliable region data
783-
_verify_gcstate_disable, // no data about gcstate
784-
_verify_all_weak_roots
778+
_verify_gcstate_disable // no data about gcstate
785779
);
786780
}
787781

@@ -793,8 +787,7 @@ void ShenandoahVerifier::verify_before_concmark() {
793787
_verify_cset_none, // UR should have fixed this
794788
_verify_liveness_disable, // no reliable liveness data
795789
_verify_regions_notrash, // no trash regions
796-
_verify_gcstate_stable, // there are no forwarded objects
797-
_verify_all_weak_roots
790+
_verify_gcstate_stable // there are no forwarded objects
798791
);
799792
}
800793

@@ -806,44 +799,31 @@ void ShenandoahVerifier::verify_after_concmark() {
806799
_verify_cset_none, // no references to cset anymore
807800
_verify_liveness_complete, // liveness data must be complete here
808801
_verify_regions_disable, // trash regions not yet recycled
809-
_verify_gcstate_stable, // mark should have stabilized the heap
810-
_verify_all_weak_roots
802+
_verify_gcstate_stable // mark should have stabilized the heap
811803
);
812804
}
813805

814806
void ShenandoahVerifier::verify_before_evacuation() {
815-
// Concurrent weak roots are evacuated during concurrent phase
816-
VerifyWeakRoots verify_weak_roots = _heap->unload_classes() ?
817-
_verify_serial_weak_roots :
818-
_verify_all_weak_roots;
819-
820807
verify_at_safepoint(
821808
"Before Evacuation",
822809
_verify_forwarded_none, // no forwarded references
823810
_verify_marked_complete_except_references, // walk over marked objects too
824811
_verify_cset_disable, // non-forwarded references to cset expected
825812
_verify_liveness_complete, // liveness data must be complete here
826813
_verify_regions_disable, // trash regions not yet recycled
827-
_verify_gcstate_stable, // mark should have stabilized the heap
828-
verify_weak_roots
814+
_verify_gcstate_stable // mark should have stabilized the heap
829815
);
830816
}
831817

832818
void ShenandoahVerifier::verify_during_evacuation() {
833-
// Concurrent weak roots are evacuated during concurrent phase
834-
VerifyWeakRoots verify_weak_roots = _heap->unload_classes() ?
835-
_verify_serial_weak_roots :
836-
_verify_all_weak_roots;
837-
838819
verify_at_safepoint(
839820
"During Evacuation",
840821
_verify_forwarded_allow, // some forwarded references are allowed
841822
_verify_marked_disable, // walk only roots
842823
_verify_cset_disable, // some cset references are not forwarded yet
843824
_verify_liveness_disable, // liveness data might be already stale after pre-evacs
844825
_verify_regions_disable, // trash regions not yet recycled
845-
_verify_gcstate_evacuation, // evacuation is in progress
846-
verify_weak_roots
826+
_verify_gcstate_evacuation // evacuation is in progress
847827
);
848828
}
849829

@@ -855,8 +835,7 @@ void ShenandoahVerifier::verify_after_evacuation() {
855835
_verify_cset_forwarded, // all cset refs are fully forwarded
856836
_verify_liveness_disable, // no reliable liveness data anymore
857837
_verify_regions_notrash, // trash regions have been recycled already
858-
_verify_gcstate_forwarded, // evacuation produced some forwarded objects
859-
_verify_all_weak_roots
838+
_verify_gcstate_forwarded // evacuation produced some forwarded objects
860839
);
861840
}
862841

@@ -868,8 +847,7 @@ void ShenandoahVerifier::verify_before_updaterefs() {
868847
_verify_cset_forwarded, // all cset refs are fully forwarded
869848
_verify_liveness_disable, // no reliable liveness data anymore
870849
_verify_regions_notrash, // trash regions have been recycled already
871-
_verify_gcstate_forwarded, // evacuation should have produced some forwarded objects
872-
_verify_all_weak_roots
850+
_verify_gcstate_forwarded // evacuation should have produced some forwarded objects
873851
);
874852
}
875853

@@ -881,8 +859,7 @@ void ShenandoahVerifier::verify_after_updaterefs() {
881859
_verify_cset_none, // no cset references, all updated
882860
_verify_liveness_disable, // no reliable liveness data anymore
883861
_verify_regions_nocset, // no cset regions, trash regions have appeared
884-
_verify_gcstate_stable, // update refs had cleaned up forwarded objects
885-
_verify_all_weak_roots
862+
_verify_gcstate_stable // update refs had cleaned up forwarded objects
886863
);
887864
}
888865

@@ -894,8 +871,7 @@ void ShenandoahVerifier::verify_after_degenerated() {
894871
_verify_cset_none, // no cset references
895872
_verify_liveness_disable, // no reliable liveness data anymore
896873
_verify_regions_notrash_nocset, // no trash, no cset
897-
_verify_gcstate_stable, // degenerated refs had cleaned up forwarded objects
898-
_verify_all_weak_roots
874+
_verify_gcstate_stable // degenerated refs had cleaned up forwarded objects
899875
);
900876
}
901877

@@ -907,8 +883,7 @@ void ShenandoahVerifier::verify_before_fullgc() {
907883
_verify_cset_disable, // cset might be foobared
908884
_verify_liveness_disable, // no reliable liveness data anymore
909885
_verify_regions_disable, // no reliable region data here
910-
_verify_gcstate_disable, // no reliable gcstate data
911-
_verify_all_weak_roots
886+
_verify_gcstate_disable // no reliable gcstate data
912887
);
913888
}
914889

@@ -920,8 +895,7 @@ void ShenandoahVerifier::verify_after_fullgc() {
920895
_verify_cset_none, // no cset references
921896
_verify_liveness_disable, // no reliable liveness data anymore
922897
_verify_regions_notrash_nocset, // no trash, no cset
923-
_verify_gcstate_stable, // full gc cleaned up everything
924-
_verify_all_weak_roots
898+
_verify_gcstate_stable // full gc cleaned up everything
925899
);
926900
}
927901

@@ -978,33 +952,11 @@ class ShenandoahVerifyInToSpaceClosure : public OopClosure {
978952
};
979953

980954
void ShenandoahVerifier::verify_roots_in_to_space() {
981-
ShenandoahRootVerifier verifier;
982-
ShenandoahVerifyInToSpaceClosure cl;
983-
verifier.oops_do(&cl);
984-
}
985-
986-
void ShenandoahVerifier::verify_roots_in_to_space_except(ShenandoahRootVerifier::RootTypes types) {
987-
ShenandoahRootVerifier verifier;
988-
verifier.excludes(types);
989955
ShenandoahVerifyInToSpaceClosure cl;
990-
verifier.oops_do(&cl);
956+
ShenandoahRootVerifier::roots_do(&cl);
991957
}
992958

993959
void ShenandoahVerifier::verify_roots_no_forwarded() {
994-
ShenandoahRootVerifier verifier;
995-
ShenandoahVerifyNoForwared cl;
996-
verifier.oops_do(&cl);
997-
}
998-
999-
void ShenandoahVerifier::verify_roots_no_forwarded(ShenandoahRootVerifier::RootTypes types) {
1000-
ShenandoahRootVerifier verifier(types);
1001-
ShenandoahVerifyNoForwared cl;
1002-
verifier.oops_do(&cl);
1003-
}
1004-
1005-
void ShenandoahVerifier::verify_roots_no_forwarded_except(ShenandoahRootVerifier::RootTypes types) {
1006-
ShenandoahRootVerifier verifier;
1007-
verifier.excludes(types);
1008960
ShenandoahVerifyNoForwared cl;
1009-
verifier.oops_do(&cl);
961+
ShenandoahRootVerifier::roots_do(&cl);
1010962
}

0 commit comments

Comments
 (0)