8232116: ZGC: Remove redundant ZLock in ZNMethodTable
Reviewed-by: stefank, pliden
--- a/src/hotspot/share/gc/z/zLock.inline.hpp Thu Oct 10 10:59:13 2019 +0100
+++ b/src/hotspot/share/gc/z/zLock.inline.hpp Fri Oct 11 13:07:21 2019 +0000
@@ -80,12 +80,16 @@
template <typename T>
inline ZLocker<T>::ZLocker(T* lock) :
_lock(lock) {
- _lock->lock();
+ if (_lock != NULL) {
+ _lock->lock();
+ }
}
template <typename T>
inline ZLocker<T>::~ZLocker() {
- _lock->unlock();
+ if (_lock != NULL) {
+ _lock->unlock();
+ }
}
#endif // SHARE_GC_Z_ZLOCK_INLINE_HPP
--- a/src/hotspot/share/gc/z/zNMethodTable.cpp Thu Oct 10 10:59:13 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodTable.cpp Fri Oct 11 13:07:21 2019 +0000
@@ -51,7 +51,7 @@
size_t ZNMethodTable::_nregistered = 0;
size_t ZNMethodTable::_nunregistered = 0;
ZNMethodTableIteration ZNMethodTable::_iteration;
-ZSafeDelete<ZNMethodTableEntry[]> ZNMethodTable::_safe_delete;
+ZSafeDeleteNoLock<ZNMethodTableEntry[]> ZNMethodTable::_safe_delete;
size_t ZNMethodTable::first_index(const nmethod* nm, size_t size) {
assert(is_power_of_2(size), "Invalid size");
--- a/src/hotspot/share/gc/z/zNMethodTable.hpp Thu Oct 10 10:59:13 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodTable.hpp Fri Oct 11 13:07:21 2019 +0000
@@ -35,12 +35,12 @@
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<ZNMethodTableEntry[]> _safe_delete;
+ static ZNMethodTableEntry* _table;
+ static size_t _size;
+ static size_t _nregistered;
+ static size_t _nunregistered;
+ static ZNMethodTableIteration _iteration;
+ static ZSafeDeleteNoLock<ZNMethodTableEntry[]> _safe_delete;
static ZNMethodTableEntry* create(size_t size);
static void destroy(ZNMethodTableEntry* table);
--- a/src/hotspot/share/gc/z/zSafeDelete.hpp Thu Oct 10 10:59:13 2019 +0100
+++ b/src/hotspot/share/gc/z/zSafeDelete.hpp Fri Oct 11 13:07:21 2019 +0000
@@ -29,11 +29,11 @@
#include "metaprogramming/removeExtent.hpp"
template <typename T>
-class ZSafeDelete {
+class ZSafeDeleteImpl {
private:
typedef typename RemoveExtent<T>::type ItemT;
- ZLock _lock;
+ ZLock* _lock;
uint64_t _enabled;
ZArray<ItemT*> _deferred;
@@ -41,7 +41,7 @@
void immediate_delete(ItemT* item);
public:
- ZSafeDelete();
+ ZSafeDeleteImpl(ZLock* lock);
void enable_deferred_delete();
void disable_deferred_delete();
@@ -49,4 +49,19 @@
void operator()(ItemT* item);
};
+template <typename T>
+class ZSafeDelete : public ZSafeDeleteImpl<T> {
+private:
+ ZLock _lock;
+
+public:
+ ZSafeDelete();
+};
+
+template <typename T>
+class ZSafeDeleteNoLock : public ZSafeDeleteImpl<T> {
+public:
+ ZSafeDeleteNoLock();
+};
+
#endif // SHARE_GC_Z_ZSAFEDELETE_HPP
--- a/src/hotspot/share/gc/z/zSafeDelete.inline.hpp Thu Oct 10 10:59:13 2019 +0100
+++ b/src/hotspot/share/gc/z/zSafeDelete.inline.hpp Fri Oct 11 13:07:21 2019 +0000
@@ -30,14 +30,14 @@
#include "utilities/debug.hpp"
template <typename T>
-ZSafeDelete<T>::ZSafeDelete() :
- _lock(),
+ZSafeDeleteImpl<T>::ZSafeDeleteImpl(ZLock* lock) :
+ _lock(lock),
_enabled(0),
_deferred() {}
template <typename T>
-bool ZSafeDelete<T>::deferred_delete(ItemT* item) {
- ZLocker<ZLock> locker(&_lock);
+bool ZSafeDeleteImpl<T>::deferred_delete(ItemT* item) {
+ ZLocker<ZLock> locker(_lock);
if (_enabled > 0) {
_deferred.add(item);
return true;
@@ -47,7 +47,7 @@
}
template <typename T>
-void ZSafeDelete<T>::immediate_delete(ItemT* item) {
+void ZSafeDeleteImpl<T>::immediate_delete(ItemT* item) {
if (IsArray<T>::value) {
delete [] item;
} else {
@@ -56,17 +56,17 @@
}
template <typename T>
-void ZSafeDelete<T>::enable_deferred_delete() {
- ZLocker<ZLock> locker(&_lock);
+void ZSafeDeleteImpl<T>::enable_deferred_delete() {
+ ZLocker<ZLock> locker(_lock);
_enabled++;
}
template <typename T>
-void ZSafeDelete<T>::disable_deferred_delete() {
+void ZSafeDeleteImpl<T>::disable_deferred_delete() {
ZArray<ItemT*> deferred;
{
- ZLocker<ZLock> locker(&_lock);
+ ZLocker<ZLock> locker(_lock);
assert(_enabled > 0, "Invalid state");
if (--_enabled == 0) {
deferred.transfer(&_deferred);
@@ -80,10 +80,19 @@
}
template <typename T>
-void ZSafeDelete<T>::operator()(ItemT* item) {
+void ZSafeDeleteImpl<T>::operator()(ItemT* item) {
if (!deferred_delete(item)) {
immediate_delete(item);
}
}
+template <typename T>
+ZSafeDelete<T>::ZSafeDelete() :
+ ZSafeDeleteImpl<T>(&_lock),
+ _lock() {}
+
+template <typename T>
+ZSafeDeleteNoLock<T>::ZSafeDeleteNoLock() :
+ ZSafeDeleteImpl<T>(NULL) {}
+
#endif // SHARE_GC_Z_ZSAFEDELETE_INLINE_HPP