8220596: ZGC: Convert ZNMethodData to use ZAttachedArray
authorpliden
Mon, 18 Mar 2019 11:50:40 +0100
changeset 54171 07943af21b96
parent 54170 8f1771ea1e39
child 54172 f92f1f1045ad
8220596: ZGC: Convert ZNMethodData to use ZAttachedArray Reviewed-by: stefank, eosterlund
src/hotspot/share/gc/z/zNMethodData.cpp
src/hotspot/share/gc/z/zNMethodData.hpp
--- a/src/hotspot/share/gc/z/zNMethodData.cpp	Mon Mar 18 11:50:40 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodData.cpp	Mon Mar 18 11:50:40 2019 +0100
@@ -22,6 +22,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/z/zAttachedArray.inline.hpp"
 #include "gc/z/zLock.inline.hpp"
 #include "gc/z/zNMethodData.hpp"
 #include "memory/allocation.hpp"
@@ -31,40 +32,29 @@
 #include "utilities/debug.hpp"
 #include "utilities/growableArray.hpp"
 
-size_t ZNMethodDataOops::header_size() {
-  const size_t size = sizeof(ZNMethodDataOops);
-  assert(is_aligned(size, sizeof(oop*)), "Header misaligned");
-  return size;
-}
-
 ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
-  // 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 = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
-  return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
+  return ::new (AttachedArray::alloc(immediates.length())) ZNMethodDataOops(immediates, has_non_immediates);
 }
 
 void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
-  FREE_C_HEAP_ARRAY(uint8_t, oops);
+  AttachedArray::free(oops);
 }
 
 ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
-    _nimmediates(immediates.length()),
+    _immediates(immediates.length()),
     _has_non_immediates(has_non_immediates) {
   // Save all immediate oops
-  for (size_t i = 0; i < _nimmediates; i++) {
+  for (size_t i = 0; i < immediates_count(); i++) {
     immediates_begin()[i] = immediates.at(i);
   }
 }
 
 size_t ZNMethodDataOops::immediates_count() const {
-  return _nimmediates;
+  return _immediates.length();
 }
 
 oop** ZNMethodDataOops::immediates_begin() const {
-  // The immediate oop* array starts immediately after this object
-  return (oop**)((uintptr_t)this + header_size());
+  return _immediates(this);
 }
 
 oop** ZNMethodDataOops::immediates_end() const {
--- a/src/hotspot/share/gc/z/zNMethodData.hpp	Mon Mar 18 11:50:40 2019 +0100
+++ b/src/hotspot/share/gc/z/zNMethodData.hpp	Mon Mar 18 11:50:40 2019 +0100
@@ -21,23 +21,24 @@
  * questions.
  */
 
+#ifndef SHARE_GC_Z_ZNMETHODDATA_HPP
+#define SHARE_GC_Z_ZNMETHODDATA_HPP
+
+#include "gc/z/zAttachedArray.hpp"
 #include "gc/z/zLock.hpp"
 #include "memory/allocation.hpp"
 #include "oops/oopsHierarchy.hpp"
 #include "utilities/globalDefinitions.hpp"
 
-#ifndef SHARE_GC_Z_ZNMETHODDATA_HPP
-#define SHARE_GC_Z_ZNMETHODDATA_HPP
-
 class nmethod;
 template <typename T> class GrowableArray;
 
 class ZNMethodDataOops {
 private:
-  const size_t _nimmediates;
-  bool         _has_non_immediates;
+  typedef ZAttachedArray<ZNMethodDataOops, oop*> AttachedArray;
 
-  static size_t header_size();
+  const AttachedArray _immediates;
+  const bool          _has_non_immediates;
 
   ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates);