8232116: ZGC: Remove redundant ZLock in ZNMethodTable
Reviewed-by: stefank, pliden
This commit is contained in:
parent
67ebe0d274
commit
1a0e073932
@ -80,12 +80,16 @@ inline bool ZReentrantLock::is_owned() const {
|
||||
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
|
||||
|
@ -51,7 +51,7 @@ size_t ZNMethodTable::_size = 0;
|
||||
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");
|
||||
|
@ -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<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);
|
||||
|
@ -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 @@ 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 <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
|
||||
|
@ -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 @@ bool ZSafeDelete<T>::deferred_delete(ItemT* item) {
|
||||
}
|
||||
|
||||
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 @@ void ZSafeDelete<T>::immediate_delete(ItemT* item) {
|
||||
}
|
||||
|
||||
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 @@ void ZSafeDelete<T>::disable_deferred_delete() {
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user