8224978: Shenandoah: Allows root verifier to verify some roots outside safepoints with proper locks
authorzgu
Wed, 29 May 2019 11:55:30 -0400
changeset 55119 04ff1e00635a
parent 55118 9ea55cb79d77
child 55120 b0513c833960
8224978: Shenandoah: Allows root verifier to verify some roots outside safepoints with proper locks Reviewed-by: shade
src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp
src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp
src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp
src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp
src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
--- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp	Thu May 30 16:21:08 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp	Wed May 29 11:55:30 2019 -0400
@@ -362,3 +362,16 @@
                      file, line);
   }
 }
+
+void ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(const Monitor* lock, const char* file, int line) {
+  if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
+    return;
+  }
+
+  if (lock->owned_by_self()) {
+    return;
+  }
+
+  ShenandoahMessageBuffer msg("Must ba at a Shenandoah safepoint or held %s lock", lock->name());
+  report_vm_error(file, line, msg.buffer());
+}
--- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp	Thu May 30 16:21:08 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp	Wed May 29 11:55:30 2019 -0400
@@ -25,6 +25,7 @@
 #define SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
 
 #include "memory/iterator.hpp"
+#include "runtime/mutex.hpp"
 #include "utilities/formatBuffer.hpp"
 
 typedef FormatBuffer<8192> ShenandoahMessageBuffer;
@@ -65,6 +66,8 @@
   static void assert_rp_isalive_not_installed(const char *file, int line);
   static void assert_rp_isalive_installed(const char *file, int line);
 
+  static void assert_locked_or_shenandoah_safepoint(const Monitor* lock, const char*file, int line);
+
 #ifdef ASSERT
 #define shenandoah_assert_in_heap(interior_loc, obj) \
                     ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__);
@@ -124,6 +127,12 @@
                     ShenandoahAsserts::assert_rp_isalive_installed(__FILE__, __LINE__);
 #define shenandoah_assert_rp_isalive_not_installed() \
                     ShenandoahAsserts::assert_rp_isalive_not_installed(__FILE__, __LINE__);
+
+#define shenandoah_assert_safepoint() \
+                    assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at Shenandoah Safepoints");
+
+#define shenandoah_assert_locked_or_safepoint(lock) \
+                    ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(lock, __FILE__, __LINE__);
 #else
 #define shenandoah_assert_in_heap(interior_loc, obj)
 #define shenandoah_assert_in_correct_region(interior_loc, obj)
@@ -158,6 +167,10 @@
 
 #define shenandoah_assert_rp_isalive_installed()
 #define shenandoah_assert_rp_isalive_not_installed()
+
+#define shenandoah_assert_safepoint()
+#define shenandoah_assert_locked_or_safepoint(lock)
+
 #endif
 
 #define shenandoah_not_implemented \
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp	Thu May 30 16:21:08 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp	Wed May 29 11:55:30 2019 -0400
@@ -34,7 +34,6 @@
 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
 #include "gc/shenandoah/shenandoahStringDedup.hpp"
 #include "gc/shenandoah/shenandoahTimingTracker.hpp"
-#include "gc/shenandoah/shenandoahUtils.hpp"
 #include "gc/shenandoah/shenandoahVMOperations.hpp"
 #include "gc/shared/weakProcessor.inline.hpp"
 #include "memory/allocation.inline.hpp"
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp	Thu May 30 16:21:08 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp	Wed May 29 11:55:30 2019 -0400
@@ -28,10 +28,12 @@
 #include "classfile/classLoaderDataGraph.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "code/codeCache.hpp"
+#include "gc/shenandoah/shenandoahAsserts.hpp"
 #include "gc/shenandoah/shenandoahHeap.hpp"
 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
 #include "gc/shenandoah/shenandoahRootVerifier.hpp"
 #include "gc/shenandoah/shenandoahStringDedup.hpp"
+#include "gc/shenandoah/shenandoahUtils.hpp"
 #include "gc/shared/weakProcessor.inline.hpp"
 #include "memory/universe.hpp"
 #include "runtime/thread.hpp"
@@ -55,15 +57,19 @@
 void ShenandoahRootVerifier::oops_do(OopClosure* oops) {
   CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
   if (verify(CodeRoots)) {
+    shenandoah_assert_locked_or_safepoint(CodeCache_lock);
     CodeCache::blobs_do(&blobs);
   }
 
   if (verify(CLDGRoots)) {
+    shenandoah_assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
     CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
     ClassLoaderDataGraph::cld_do(&clds);
   }
 
   if (verify(SerialRoots)) {
+    shenandoah_assert_safepoint();
+
     Universe::oops_do(oops);
     Management::oops_do(oops);
     JvmtiExport::oops_do(oops);
@@ -73,15 +79,18 @@
   }
 
   if (verify(WeakRoots)) {
+    shenandoah_assert_safepoint();
     AlwaysTrueClosure always_true;
     WeakProcessor::weak_oops_do(&always_true, oops);
   }
 
   if (ShenandoahStringDedup::is_enabled() && verify(StringDedupRoots)) {
+    shenandoah_assert_safepoint();
     ShenandoahStringDedup::oops_do_slow(oops);
   }
 
   if (verify(ThreadRoots)) {
+    shenandoah_assert_safepoint();
     // Do thread roots the last. This allows verification code to find
     // any broken objects from those special roots first, not the accidental
     // dangling reference from the thread root.
@@ -90,6 +99,8 @@
 }
 
 void ShenandoahRootVerifier::roots_do(OopClosure* oops) {
+  shenandoah_assert_safepoint();
+
   CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
   CodeCache::blobs_do(&blobs);
 
@@ -117,6 +128,8 @@
 }
 
 void ShenandoahRootVerifier::strong_roots_do(OopClosure* oops) {
+  shenandoah_assert_safepoint();
+
   CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
 
   CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
--- a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Thu May 30 16:21:08 2019 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Wed May 29 11:55:30 2019 -0400
@@ -965,14 +965,12 @@
 };
 
 void ShenandoahVerifier::verify_roots_no_forwarded() {
-  guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
   ShenandoahRootVerifier verifier;
   ShenandoahVerifyNoForwared cl;
   verifier.oops_do(&cl);
 }
 
 void ShenandoahVerifier::verify_roots_no_forwarded_except(ShenandoahRootVerifier::RootTypes types) {
-  guarantee(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "only when nothing else happens");
   ShenandoahRootVerifier verifier;
   verifier.excludes(types);
   ShenandoahVerifyNoForwared cl;