src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 55029 fc66237d5eae
child 58679 9c3209ff7550
--- a/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp	Thu Oct 17 20:53:35 2019 +0100
@@ -26,6 +26,7 @@
 #include "code/nmethod.hpp"
 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
+#include "gc/shenandoah/shenandoahUtils.hpp"
 #include "memory/resourceArea.hpp"
 #include "memory/universe.hpp"
 
@@ -121,18 +122,21 @@
 };
 
 GrowableArray<ShenandoahNMethod*>* ShenandoahCodeRoots::_recorded_nms;
+ShenandoahLock                     ShenandoahCodeRoots::_recorded_nms_lock;
 
 void ShenandoahCodeRoots::initialize() {
   _recorded_nms = new (ResourceObj::C_HEAP, mtGC) GrowableArray<ShenandoahNMethod*>(100, true, mtGC);
 }
 
 void ShenandoahCodeRoots::add_nmethod(nmethod* nm) {
-  assert(CodeCache_lock->owned_by_self(), "Must own CodeCache_lock");
   switch (ShenandoahCodeRootsStyle) {
     case 0:
     case 1:
       break;
     case 2: {
+      assert_locked_or_safepoint(CodeCache_lock);
+      ShenandoahLocker locker(CodeCache_lock->owned_by_self() ? NULL : &_recorded_nms_lock);
+
       ShenandoahNMethodOopDetector detector;
       nm->oops_do(&detector);
 
@@ -156,15 +160,17 @@
 };
 
 void ShenandoahCodeRoots::remove_nmethod(nmethod* nm) {
-  assert(CodeCache_lock->owned_by_self(), "Must own CodeCache_lock");
   switch (ShenandoahCodeRootsStyle) {
     case 0:
     case 1: {
       break;
     }
     case 2: {
+      assert_locked_or_safepoint(CodeCache_lock);
+      ShenandoahLocker locker(CodeCache_lock->owned_by_self() ? NULL : &_recorded_nms_lock);
+
       ShenandoahNMethodOopDetector detector;
-      nm->oops_do(&detector, /* allow_zombie = */ true);
+      nm->oops_do(&detector, /* allow_dead = */ true);
 
       if (detector.has_oops()) {
         int idx = _recorded_nms->find(nm, ShenandoahNMethod::find_with_nmethod);
@@ -194,7 +200,7 @@
       break;
     }
     case 2: {
-      CodeCache_lock->lock();
+      CodeCache_lock->lock_without_safepoint_check();
       break;
     }
     default:
@@ -310,7 +316,11 @@
     oop *loc = _oops[c];
     assert(_nm->code_contains((address) loc) || _nm->oops_contains(loc), "nmethod should contain the oop*");
     oop o = RawAccess<>::oop_load(loc);
-    shenandoah_assert_correct_except(loc, o, o == NULL || heap->is_full_gc_move_in_progress());
+    shenandoah_assert_correct_except(loc, o,
+             o == NULL ||
+             heap->is_full_gc_move_in_progress() ||
+             (VMThread::vm_operation() != NULL) && (VMThread::vm_operation()->type() == VM_Operation::VMOp_HeapWalkOperation)
+    );
   }
 }