8224525: Shenandoah: Eliminate shenandoah verifier's side-effects
authorzgu
Wed, 22 May 2019 09:10:07 -0400
changeset 54985 37d8790efed7
parent 54984 8f7d232b4225
child 54986 3b4ecc4180e0
8224525: Shenandoah: Eliminate shenandoah verifier's side-effects Reviewed-by: shade, rkennke
src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Wed May 22 13:58:19 2019 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Wed May 22 09:10:07 2019 -0400
@@ -40,6 +40,7 @@
 class ShenandoahCollectorPolicy;
 class ShenandoahControlThread;
 class ShenandoahGCSession;
+class ShenandoahGCStateResetter;
 class ShenandoahHeuristics;
 class ShenandoahMarkingContext;
 class ShenandoahPhaseTimings;
@@ -111,6 +112,7 @@
   friend class ShenandoahAsserts;
   friend class VMStructs;
   friend class ShenandoahGCSession;
+  friend class ShenandoahGCStateResetter;
 
 // ---------- Locks that guard important data structures in Heap
 //
--- a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Wed May 22 13:58:19 2019 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Wed May 22 09:10:07 2019 -0400
@@ -604,6 +604,23 @@
   }
 };
 
+class ShenandoahGCStateResetter : public StackObj {
+private:
+  ShenandoahHeap* const _heap;
+  char _gc_state;
+
+public:
+  ShenandoahGCStateResetter() : _heap(ShenandoahHeap::heap()) {
+    _gc_state = _heap->gc_state();
+    _heap->_gc_state.clear();
+  }
+
+  ~ShenandoahGCStateResetter() {
+    _heap->_gc_state.set(_gc_state);
+    assert(_heap->gc_state() == _gc_state, "Should be restored");
+  }
+};
+
 void ShenandoahVerifier::verify_at_safepoint(const char *label,
                                              VerifyForwarded forwarded, VerifyMarked marked,
                                              VerifyCollectionSet cset,
@@ -653,6 +670,9 @@
     }
   }
 
+  // Deactivate barriers temporarily: Verifier wants plain heap accesses
+  ShenandoahGCStateResetter resetter;
+
   // Heap size checks
   {
     ShenandoahHeapLocker lock(_heap->lock());