--- a/src/hotspot/share/code/nmethod.cpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/code/nmethod.cpp Tue Feb 26 11:36:00 2019 +0100
@@ -1370,6 +1370,8 @@
assert(_speculation_log == NULL, "should have been nulled out when transitioned to zombie");
#endif
+ Universe::heap()->flush_nmethod(this);
+
CodeBlob::flush();
CodeCache::free(this);
}
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp Tue Feb 26 11:36:00 2019 +0100
@@ -521,6 +521,7 @@
// Override with specific mechanism for each specialized heap type.
virtual void register_nmethod(nmethod* nm) {}
virtual void unregister_nmethod(nmethod* nm) {}
+ virtual void flush_nmethod(nmethod* nm) {}
virtual void verify_nmethod(nmethod* nmethod) {}
void trace_heap_before_gc(const GCTracer* gc_tracer);
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp Tue Feb 26 11:36:00 2019 +0100
@@ -262,6 +262,10 @@
ZNMethod::unregister_nmethod(nm);
}
+void ZCollectedHeap::flush_nmethod(nmethod* nm) {
+ ZNMethod::flush_nmethod(nm);
+}
+
void ZCollectedHeap::verify_nmethod(nmethod* nm) {
// Does nothing
}
--- a/src/hotspot/share/gc/z/zCollectedHeap.hpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp Tue Feb 26 11:36:00 2019 +0100
@@ -105,6 +105,7 @@
virtual void register_nmethod(nmethod* nm);
virtual void unregister_nmethod(nmethod* nm);
+ virtual void flush_nmethod(nmethod* nm);
virtual void verify_nmethod(nmethod* nmethod);
virtual WorkGang* get_safepoint_workers();
--- a/src/hotspot/share/gc/z/zNMethod.cpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zNMethod.cpp Tue Feb 26 11:36:00 2019 +0100
@@ -82,7 +82,7 @@
// Attach GC data to nmethod
ZNMethodData* data = gc_data(nm);
if (data == NULL) {
- data = ZNMethodData::create(nm);
+ data = new ZNMethodData();
set_gc_data(nm, data);
}
@@ -92,18 +92,8 @@
ZNMethodDataOops::destroy(old_oops);
}
-void ZNMethod::detach_gc_data(nmethod* nm) {
- // Destroy GC data
- ZNMethodData::destroy(gc_data(nm));
- set_gc_data(nm, NULL);
-}
-
ZReentrantLock* ZNMethod::lock_for_nmethod(nmethod* nm) {
- ZNMethodData* const data = gc_data(nm);
- if (data == NULL) {
- return NULL;
- }
- return data->lock();
+ return gc_data(nm)->lock();
}
void ZNMethod::log_register(const nmethod* nm) {
@@ -190,9 +180,11 @@
log_unregister(nm);
ZNMethodTable::unregister_nmethod(nm);
+}
- // Destroy and detach gc data
- detach_gc_data(nm);
+void ZNMethod::flush_nmethod(nmethod* nm) {
+ // Destroy GC data
+ delete gc_data(nm);
}
void ZNMethod::disarm_nmethod(nmethod* nm) {
--- a/src/hotspot/share/gc/z/zNMethod.hpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zNMethod.hpp Tue Feb 26 11:36:00 2019 +0100
@@ -34,7 +34,6 @@
class ZNMethod : public AllStatic {
private:
static void attach_gc_data(nmethod* nm);
- static void detach_gc_data(nmethod* nm);
static void log_register(const nmethod* nm);
static void log_unregister(const nmethod* nm);
@@ -42,6 +41,7 @@
public:
static void register_nmethod(nmethod* nm);
static void unregister_nmethod(nmethod* nm);
+ static void flush_nmethod(nmethod* nm);
static void disarm_nmethod(nmethod* nm);
--- a/src/hotspot/share/gc/z/zNMethodData.cpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zNMethodData.cpp Tue Feb 26 11:36:00 2019 +0100
@@ -76,20 +76,14 @@
return _has_non_immediates;
}
-ZNMethodData* ZNMethodData::create(nmethod* nm) {
- void* const mem = ZNMethodAllocator::allocate(sizeof(ZNMethodData));
- return ::new (mem) ZNMethodData(nm);
-}
-
-void ZNMethodData::destroy(ZNMethodData* data) {
- ZNMethodAllocator::free(data->oops());
- ZNMethodAllocator::free(data);
-}
-
-ZNMethodData::ZNMethodData(nmethod* nm) :
+ZNMethodData::ZNMethodData() :
_lock(),
_oops(NULL) {}
+ZNMethodData::~ZNMethodData() {
+ ZNMethodAllocator::free(_oops);
+}
+
ZReentrantLock* ZNMethodData::lock() {
return &_lock;
}
--- a/src/hotspot/share/gc/z/zNMethodData.hpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zNMethodData.hpp Tue Feb 26 11:36:00 2019 +0100
@@ -22,6 +22,7 @@
*/
#include "gc/z/zLock.hpp"
+#include "memory/allocation.hpp"
#include "oops/oopsHierarchy.hpp"
#include "utilities/globalDefinitions.hpp"
@@ -51,16 +52,14 @@
bool has_non_immediates() const;
};
-class ZNMethodData {
+class ZNMethodData : public CHeapObj<mtGC> {
private:
ZReentrantLock _lock;
ZNMethodDataOops* volatile _oops;
- ZNMethodData(nmethod* nm);
-
public:
- static ZNMethodData* create(nmethod* nm);
- static void destroy(ZNMethodData* data);
+ ZNMethodData();
+ ~ZNMethodData();
ZReentrantLock* lock();
--- a/src/hotspot/share/gc/z/zUnload.cpp Tue Feb 26 14:57:23 2019 +0530
+++ b/src/hotspot/share/gc/z/zUnload.cpp Tue Feb 26 11:36:00 2019 +0100
@@ -65,23 +65,14 @@
};
class ZIsUnloadingBehaviour : public IsUnloadingBehaviour {
-private:
- bool is_unloading(nmethod* nm) const {
- ZIsUnloadingOopClosure cl;
- nm->oops_do(&cl, true /* allow_zombie */);
- return cl.is_unloading();
- }
-
public:
virtual bool is_unloading(CompiledMethod* method) const {
nmethod* const nm = method->as_nmethod();
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm);
- if (lock == NULL) {
- return is_unloading(nm);
- } else {
- ZLocker<ZReentrantLock> locker(lock);
- return is_unloading(nm);
- }
+ ZLocker<ZReentrantLock> locker(lock);
+ ZIsUnloadingOopClosure cl;
+ nm->oops_do(&cl, true /* allow_zombie */);
+ return cl.is_unloading();
}
};
@@ -90,18 +81,14 @@
virtual bool lock(CompiledMethod* method) {
nmethod* const nm = method->as_nmethod();
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm);
- if (lock != NULL) {
- lock->lock();
- }
+ lock->lock();
return true;
}
virtual void unlock(CompiledMethod* method) {
nmethod* const nm = method->as_nmethod();
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm);
- if (lock != NULL) {
- lock->unlock();
- }
+ lock->unlock();
}
virtual bool is_safe(CompiledMethod* method) {
@@ -111,7 +98,7 @@
nmethod* const nm = method->as_nmethod();
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm);
- return lock == NULL || lock->is_owned();
+ return lock->is_owned();
}
};