--- 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) {
--- a/src/hotspot/share/gc/z/zNMethodTable.hpp Fri Feb 22 09:23:37 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodTable.hpp Tue Feb 19 13:47:45 2019 +0100
@@ -54,7 +54,7 @@
static size_t first_index(const nmethod* nm, size_t size);
static size_t next_index(size_t prev_index, size_t size);
- static void sweeper_wait_for_iteration();
+ static void wait_until_iteration_done();
static bool register_entry(ZNMethodTableEntry* table, size_t size, ZNMethodTableEntry entry);
static void unregister_entry(ZNMethodTableEntry* table, size_t size, nmethod* nm);