changeset 55029:fc66237d5eae

8224115: Shenandoah: Eliminate RWLock that protects recorded nmethod data array Reviewed-by: shade
author zgu
date Wed, 22 May 2019 21:24:09 -0400
parents da5435d9a801
children 703b2c04fc2c
files src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.hpp
diffstat 2 files changed, 4 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp	Fri May 24 09:23:58 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp	Wed May 22 21:24:09 2019 -0400
@@ -120,15 +120,14 @@
   }
 };
 
-ShenandoahCodeRoots::PaddedLock ShenandoahCodeRoots::_recorded_nms_lock;
 GrowableArray<ShenandoahNMethod*>* ShenandoahCodeRoots::_recorded_nms;
 
 void ShenandoahCodeRoots::initialize() {
-  _recorded_nms_lock._lock = 0;
   _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:
@@ -140,9 +139,6 @@
       if (detector.has_oops()) {
         ShenandoahNMethod* nmr = new ShenandoahNMethod(nm, detector.oops());
         nmr->assert_alive_and_correct();
-
-        ShenandoahCodeRootsLock lock(true);
-
         int idx = _recorded_nms->find(nm, ShenandoahNMethod::find_with_nmethod);
         if (idx != -1) {
           ShenandoahNMethod* old = _recorded_nms->at(idx);
@@ -160,6 +156,7 @@
 };
 
 void ShenandoahCodeRoots::remove_nmethod(nmethod* nm) {
+  assert(CodeCache_lock->owned_by_self(), "Must own CodeCache_lock");
   switch (ShenandoahCodeRootsStyle) {
     case 0:
     case 1: {
@@ -170,8 +167,6 @@
       nm->oops_do(&detector, /* allow_zombie = */ true);
 
       if (detector.has_oops()) {
-        ShenandoahCodeRootsLock lock(true);
-
         int idx = _recorded_nms->find(nm, ShenandoahNMethod::find_with_nmethod);
         assert(idx != -1, "nmethod " PTR_FORMAT " should be registered", p2i(nm));
         ShenandoahNMethod* old = _recorded_nms->at(idx);
@@ -199,7 +194,7 @@
       break;
     }
     case 2: {
-      ShenandoahCodeRoots::acquire_lock(false);
+      CodeCache_lock->lock();
       break;
     }
     default:
@@ -215,7 +210,7 @@
       break;
     }
     case 2: {
-      ShenandoahCodeRoots::release_lock(false);
+      CodeCache_lock->unlock();
       break;
     }
     default:
--- a/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.hpp	Fri May 24 09:23:58 2019 -0400
+++ b/src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.hpp	Wed May 22 21:24:09 2019 -0400
@@ -31,7 +31,6 @@
 
 class ShenandoahHeap;
 class ShenandoahHeapRegion;
-class ShenandoahCodeRootsLock;
 
 class ShenandoahParallelCodeHeapIterator {
   friend class CodeCache;
@@ -124,7 +123,6 @@
 
 class ShenandoahCodeRoots : public CHeapObj<mtGC> {
   friend class ShenandoahHeap;
-  friend class ShenandoahCodeRootsLock;
   friend class ShenandoahCodeRootsIterator;
 
 public:
@@ -133,61 +131,7 @@
   static void remove_nmethod(nmethod* nm);
 
 private:
-  struct PaddedLock {
-    DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile int));
-    volatile int _lock;
-    DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, 0);
-  };
-
-  static PaddedLock _recorded_nms_lock;
   static GrowableArray<ShenandoahNMethod*>* _recorded_nms;
-
-  static void acquire_lock(bool write) {
-    volatile int* loc = &_recorded_nms_lock._lock;
-    if (write) {
-      while ((OrderAccess::load_acquire(loc) != 0) ||
-             Atomic::cmpxchg(-1, loc, 0) != 0) {
-        SpinPause();
-      }
-      assert (*loc == -1, "acquired for write");
-    } else {
-      while (true) {
-        int cur = OrderAccess::load_acquire(loc);
-        if (cur >= 0) {
-          if (Atomic::cmpxchg(cur + 1, loc, cur) == cur) {
-            // Success!
-            assert (*loc > 0, "acquired for read");
-            return;
-          }
-        }
-        SpinPause();
-      }
-    }
-  }
-
-  static void release_lock(bool write) {
-    volatile int* loc = &ShenandoahCodeRoots::_recorded_nms_lock._lock;
-    if (write) {
-      OrderAccess::release_store_fence(loc, 0);
-    } else {
-      Atomic::dec(loc);
-    }
-  }
-};
-
-// Very simple unranked read-write lock
-class ShenandoahCodeRootsLock : public StackObj {
-  friend class ShenandoahCodeRoots;
-private:
-  const bool _write;
-public:
-  ShenandoahCodeRootsLock(bool write) : _write(write) {
-    ShenandoahCodeRoots::acquire_lock(write);
-  }
-
-  ~ShenandoahCodeRootsLock() {
-    ShenandoahCodeRoots::release_lock(_write);
-  }
 };
 
 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCODEROOTS_HPP