diff --git a/src/hotspot/share/gc/z/zLock.inline.hpp b/src/hotspot/share/gc/z/zLock.inline.hpp index b9688b338cb..860ab9182dc 100644 --- a/src/hotspot/share/gc/z/zLock.inline.hpp +++ b/src/hotspot/share/gc/z/zLock.inline.hpp @@ -80,12 +80,16 @@ inline bool ZReentrantLock::is_owned() const { template inline ZLocker::ZLocker(T* lock) : _lock(lock) { - _lock->lock(); + if (_lock != NULL) { + _lock->lock(); + } } template inline ZLocker::~ZLocker() { - _lock->unlock(); + if (_lock != NULL) { + _lock->unlock(); + } } #endif // SHARE_GC_Z_ZLOCK_INLINE_HPP diff --git a/src/hotspot/share/gc/z/zNMethodTable.cpp b/src/hotspot/share/gc/z/zNMethodTable.cpp index 6f585bc2a5e..dcfa477ac03 100644 --- a/src/hotspot/share/gc/z/zNMethodTable.cpp +++ b/src/hotspot/share/gc/z/zNMethodTable.cpp @@ -51,7 +51,7 @@ size_t ZNMethodTable::_size = 0; size_t ZNMethodTable::_nregistered = 0; size_t ZNMethodTable::_nunregistered = 0; ZNMethodTableIteration ZNMethodTable::_iteration; -ZSafeDelete ZNMethodTable::_safe_delete; +ZSafeDeleteNoLock ZNMethodTable::_safe_delete; size_t ZNMethodTable::first_index(const nmethod* nm, size_t size) { assert(is_power_of_2(size), "Invalid size"); diff --git a/src/hotspot/share/gc/z/zNMethodTable.hpp b/src/hotspot/share/gc/z/zNMethodTable.hpp index a2443bc93d3..26ae2d27933 100644 --- a/src/hotspot/share/gc/z/zNMethodTable.hpp +++ b/src/hotspot/share/gc/z/zNMethodTable.hpp @@ -35,12 +35,12 @@ class ZWorkers; class ZNMethodTable : public AllStatic { private: - static ZNMethodTableEntry* _table; - static size_t _size; - static size_t _nregistered; - static size_t _nunregistered; - static ZNMethodTableIteration _iteration; - static ZSafeDelete _safe_delete; + static ZNMethodTableEntry* _table; + static size_t _size; + static size_t _nregistered; + static size_t _nunregistered; + static ZNMethodTableIteration _iteration; + static ZSafeDeleteNoLock _safe_delete; static ZNMethodTableEntry* create(size_t size); static void destroy(ZNMethodTableEntry* table); diff --git a/src/hotspot/share/gc/z/zSafeDelete.hpp b/src/hotspot/share/gc/z/zSafeDelete.hpp index b41b6e9f552..f18d1e4153e 100644 --- a/src/hotspot/share/gc/z/zSafeDelete.hpp +++ b/src/hotspot/share/gc/z/zSafeDelete.hpp @@ -29,11 +29,11 @@ #include "metaprogramming/removeExtent.hpp" template -class ZSafeDelete { +class ZSafeDeleteImpl { private: typedef typename RemoveExtent::type ItemT; - ZLock _lock; + ZLock* _lock; uint64_t _enabled; ZArray _deferred; @@ -41,7 +41,7 @@ private: void immediate_delete(ItemT* item); public: - ZSafeDelete(); + ZSafeDeleteImpl(ZLock* lock); void enable_deferred_delete(); void disable_deferred_delete(); @@ -49,4 +49,19 @@ public: void operator()(ItemT* item); }; +template +class ZSafeDelete : public ZSafeDeleteImpl { +private: + ZLock _lock; + +public: + ZSafeDelete(); +}; + +template +class ZSafeDeleteNoLock : public ZSafeDeleteImpl { +public: + ZSafeDeleteNoLock(); +}; + #endif // SHARE_GC_Z_ZSAFEDELETE_HPP diff --git a/src/hotspot/share/gc/z/zSafeDelete.inline.hpp b/src/hotspot/share/gc/z/zSafeDelete.inline.hpp index 29b032b2009..75bcc03de58 100644 --- a/src/hotspot/share/gc/z/zSafeDelete.inline.hpp +++ b/src/hotspot/share/gc/z/zSafeDelete.inline.hpp @@ -30,14 +30,14 @@ #include "utilities/debug.hpp" template -ZSafeDelete::ZSafeDelete() : - _lock(), +ZSafeDeleteImpl::ZSafeDeleteImpl(ZLock* lock) : + _lock(lock), _enabled(0), _deferred() {} template -bool ZSafeDelete::deferred_delete(ItemT* item) { - ZLocker locker(&_lock); +bool ZSafeDeleteImpl::deferred_delete(ItemT* item) { + ZLocker locker(_lock); if (_enabled > 0) { _deferred.add(item); return true; @@ -47,7 +47,7 @@ bool ZSafeDelete::deferred_delete(ItemT* item) { } template -void ZSafeDelete::immediate_delete(ItemT* item) { +void ZSafeDeleteImpl::immediate_delete(ItemT* item) { if (IsArray::value) { delete [] item; } else { @@ -56,17 +56,17 @@ void ZSafeDelete::immediate_delete(ItemT* item) { } template -void ZSafeDelete::enable_deferred_delete() { - ZLocker locker(&_lock); +void ZSafeDeleteImpl::enable_deferred_delete() { + ZLocker locker(_lock); _enabled++; } template -void ZSafeDelete::disable_deferred_delete() { +void ZSafeDeleteImpl::disable_deferred_delete() { ZArray deferred; { - ZLocker locker(&_lock); + ZLocker locker(_lock); assert(_enabled > 0, "Invalid state"); if (--_enabled == 0) { deferred.transfer(&_deferred); @@ -80,10 +80,19 @@ void ZSafeDelete::disable_deferred_delete() { } template -void ZSafeDelete::operator()(ItemT* item) { +void ZSafeDeleteImpl::operator()(ItemT* item) { if (!deferred_delete(item)) { immediate_delete(item); } } +template +ZSafeDelete::ZSafeDelete() : + ZSafeDeleteImpl(&_lock), + _lock() {} + +template +ZSafeDeleteNoLock::ZSafeDeleteNoLock() : + ZSafeDeleteImpl(NULL) {} + #endif // SHARE_GC_Z_ZSAFEDELETE_INLINE_HPP