8219638: ZGC: Free ZNMethodDataOops under a lock
authoreosterlund
Tue, 26 Feb 2019 11:38:07 +0100
changeset 53922 00fcc1ef31e8
parent 53921 a590b6107ab3
child 53923 c431ab7f9e85
8219638: ZGC: Free ZNMethodDataOops under a lock Reviewed-by: pliden
src/hotspot/share/gc/z/zNMethodData.cpp
--- a/src/hotspot/share/gc/z/zNMethodData.cpp	Tue Feb 26 11:36:00 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodData.cpp	Tue Feb 26 11:38:07 2019 +0100
@@ -23,7 +23,6 @@
 
 #include "precompiled.hpp"
 #include "gc/z/zLock.inline.hpp"
-#include "gc/z/zNMethodAllocator.hpp"
 #include "gc/z/zNMethodData.hpp"
 #include "memory/allocation.hpp"
 #include "runtime/atomic.hpp"
@@ -42,12 +41,12 @@
   // Allocate memory for the ZNMethodDataOops object
   // plus the immediate oop* array that follows right after.
   const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length());
-  void* const mem = ZNMethodAllocator::allocate(size);
+  void* const mem = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
   return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
 }
 
 void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
-  ZNMethodAllocator::free(oops);
+  FREE_C_HEAP_ARRAY(uint8_t, oops);
 }
 
 ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
@@ -81,7 +80,7 @@
     _oops(NULL) {}
 
 ZNMethodData::~ZNMethodData() {
-  ZNMethodAllocator::free(_oops);
+  ZNMethodDataOops::destroy(_oops);
 }
 
 ZReentrantLock* ZNMethodData::lock() {
@@ -93,5 +92,8 @@
 }
 
 ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
-  return Atomic::xchg(new_oops, &_oops);
+  ZLocker<ZReentrantLock> locker(&_lock);
+  ZNMethodDataOops* const old_oops = _oops;
+  _oops = new_oops;
+  return old_oops;
 }