src/hotspot/share/gc/z/zNMethodTable.cpp
changeset 53887 2e1896987ed8
parent 53500 f618cfbaf35b
child 53888 a858ad440eb9
--- a/src/hotspot/share/gc/z/zNMethodTable.cpp	Fri Feb 22 09:23:37 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodTable.cpp	Tue Feb 19 13:47:45 2019 +0100
@@ -40,7 +40,6 @@
 #include "memory/resourceArea.hpp"
 #include "runtime/atomic.hpp"
 #include "runtime/orderAccess.hpp"
-#include "runtime/os.hpp"
 #include "utilities/debug.hpp"
 
 class ZNMethodDataImmediateOops {
@@ -440,24 +439,24 @@
   disarm_nmethod(nm);
 }
 
-void ZNMethodTable::sweeper_wait_for_iteration() {
-  // The sweeper must wait for any ongoing iteration to complete
-  // before it can unregister an nmethod.
-  if (!Thread::current()->is_Code_cache_sweeper_thread()) {
-    return;
-  }
+void ZNMethodTable::wait_until_iteration_done() {
+  assert(CodeCache_lock->owned_by_self(), "Lock must be held");
 
   while (_iter_table != NULL) {
-    MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
-    os::naked_short_sleep(1);
+    CodeCache_lock->wait(Monitor::_no_safepoint_check_flag);
   }
 }
 
 void ZNMethodTable::unregister_nmethod(nmethod* nm) {
   assert(CodeCache_lock->owned_by_self(), "Lock must be held");
-  ResourceMark rm;
 
-  sweeper_wait_for_iteration();
+  if (Thread::current()->is_Code_cache_sweeper_thread()) {
+    // The sweeper must wait for any ongoing iteration to complete
+    // before it can unregister an nmethod.
+    ZNMethodTable::wait_until_iteration_done();
+  }
+
+  ResourceMark rm;
 
   log_unregister(nm);
 
@@ -494,6 +493,7 @@
     delete [] _iter_table;
   }
   _iter_table = NULL;
+
   assert(_claimed >= _iter_table_size, "Failed to claim all table entries");
 
   // Process deferred deletes
@@ -502,6 +502,9 @@
     FREE_C_HEAP_ARRAY(uint8_t, data);
   }
   _iter_deferred_deletes.clear();
+
+  // Notify iteration done
+  CodeCache_lock->notify_all();
 }
 
 void ZNMethodTable::entry_oops_do(ZNMethodTableEntry entry, OopClosure* cl) {