changeset 60700:5bb36b006854

8247759: ZGC: Replace ZGC specific array implementations with GrowableArray Reviewed-by: pliden
author stefank
date Thu, 27 Aug 2020 09:54:32 +0200
parents c3a975498072
children 986d7d26f9fe
files src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp src/hotspot/share/gc/z/zArray.hpp src/hotspot/share/gc/z/zArray.inline.hpp src/hotspot/share/gc/z/zPhysicalMemory.cpp src/hotspot/share/gc/z/zPhysicalMemory.hpp src/hotspot/share/gc/z/zPhysicalMemory.inline.hpp src/hotspot/share/gc/z/zRelocationSetSelector.cpp src/hotspot/share/gc/z/zSafeDelete.inline.hpp test/hotspot/gtest/gc/z/test_zArray.cpp test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp
diffstat 10 files changed, 152 insertions(+), 295 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp	Thu Aug 27 09:54:32 2020 +0200
@@ -83,7 +83,7 @@
   while (getline(&line, &length, fd) != -1) {
     char* const mountpoint = get_mountpoint(line, filesystem);
     if (mountpoint != NULL) {
-      mountpoints->add(mountpoint);
+      mountpoints->append(mountpoint);
     }
   }
 
@@ -129,10 +129,10 @@
 
   get_mountpoints(filesystem, &mountpoints);
 
-  if (mountpoints.size() == 0) {
+  if (mountpoints.length() == 0) {
     // No mount point found
     log_error_p(gc)("Failed to find an accessible %s filesystem", filesystem);
-  } else if (mountpoints.size() == 1) {
+  } else if (mountpoints.length() == 1) {
     // One mount point found
     path = strdup(mountpoints.at(0));
   } else {
--- a/src/hotspot/share/gc/z/zArray.hpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zArray.hpp	Thu Aug 27 09:54:32 2020 +0200
@@ -26,39 +26,21 @@
 
 #include "memory/allocation.hpp"
 #include "utilities/globalDefinitions.hpp"
+#include "utilities/growableArray.hpp"
 
 template <typename T>
-class ZArray {
-private:
-  static const size_t initial_capacity = 32;
-
-  T*     _array;
-  size_t _size;
-  size_t _capacity;
-
-  NONCOPYABLE(ZArray);
-
-  void expand(size_t new_capacity);
-
+class ZArray : public GrowableArrayCHeap<T, mtGC> {
 public:
   ZArray();
-  ~ZArray();
 
-  size_t size() const;
-  bool is_empty() const;
-
-  T at(size_t index) const;
-
-  void add(T value);
   void transfer(ZArray<T>* from);
-  void clear();
 };
 
 template <typename T, bool parallel>
 class ZArrayIteratorImpl : public StackObj {
 private:
   ZArray<T>* const _array;
-  size_t           _next;
+  int              _next;
 
 public:
   ZArrayIteratorImpl(ZArray<T>* array);
@@ -70,16 +52,7 @@
 #define ZARRAY_SERIAL      false
 #define ZARRAY_PARALLEL    true
 
-template <typename T>
-class ZArrayIterator : public ZArrayIteratorImpl<T, ZARRAY_SERIAL> {
-public:
-  ZArrayIterator(ZArray<T>* array);
-};
-
-template <typename T>
-class ZArrayParallelIterator : public ZArrayIteratorImpl<T, ZARRAY_PARALLEL> {
-public:
-  ZArrayParallelIterator(ZArray<T>* array);
-};
+template <typename T> using ZArrayIterator = ZArrayIteratorImpl<T, ZARRAY_SERIAL>;
+template <typename T> using ZArrayParallelIterator = ZArrayIteratorImpl<T, ZARRAY_PARALLEL>;
 
 #endif // SHARE_GC_Z_ZARRAY_HPP
--- a/src/hotspot/share/gc/z/zArray.inline.hpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zArray.inline.hpp	Thu Aug 27 09:54:32 2020 +0200
@@ -30,67 +30,17 @@
 
 template <typename T>
 inline ZArray<T>::ZArray() :
-    _array(NULL),
-    _size(0),
-    _capacity(0) {}
-
-template <typename T>
-inline ZArray<T>::~ZArray() {
-  FREE_C_HEAP_ARRAY(T, _array);
-}
-
-template <typename T>
-inline size_t ZArray<T>::size() const {
-  return _size;
-}
-
-template <typename T>
-inline bool ZArray<T>::is_empty() const {
-  return size() == 0;
-}
-
-template <typename T>
-inline T ZArray<T>::at(size_t index) const {
-  assert(index < _size, "Index out of bounds");
-  return _array[index];
-}
-
-template <typename T>
-inline void ZArray<T>::expand(size_t new_capacity) {
-  T* new_array = NEW_C_HEAP_ARRAY(T, new_capacity, mtGC);
-  if (_array != NULL) {
-    memcpy(new_array, _array, sizeof(T) * _capacity);
-    FREE_C_HEAP_ARRAY(T, _array);
-  }
-
-  _array = new_array;
-  _capacity = new_capacity;
-}
-
-template <typename T>
-inline void ZArray<T>::add(T value) {
-  if (_size == _capacity) {
-    const size_t new_capacity = (_capacity > 0) ? _capacity * 2 : initial_capacity;
-    expand(new_capacity);
-  }
-
-  _array[_size++] = value;
-}
+    GrowableArrayCHeap<T, mtGC>(0) {}
 
 template <typename T>
 inline void ZArray<T>::transfer(ZArray<T>* from) {
-  assert(_array == NULL, "Should be empty");
-  _array = from->_array;
-  _size = from->_size;
-  _capacity = from->_capacity;
-  from->_array = NULL;
-  from->_size = 0;
-  from->_capacity = 0;
-}
-
-template <typename T>
-inline void ZArray<T>::clear() {
-  _size = 0;
+  assert(this->_data == NULL, "Should be empty");
+  this->_data = from->_data;
+  this->_len = from->_len;
+  this->_max = from->_max;
+  from->_data = NULL;
+  from->_len = 0;
+  from->_max = 0;
 }
 
 template <typename T, bool parallel>
@@ -101,13 +51,13 @@
 template <typename T, bool parallel>
 inline bool ZArrayIteratorImpl<T, parallel>::next(T* elem) {
   if (parallel) {
-    const size_t next = Atomic::fetch_and_add(&_next, 1u);
-    if (next < _array->size()) {
+    const int next = Atomic::fetch_and_add(&_next, 1);
+    if (next < _array->length()) {
       *elem = _array->at(next);
       return true;
     }
   } else {
-    if (_next < _array->size()) {
+    if (_next < _array->length()) {
       *elem = _array->at(_next++);
       return true;
     }
@@ -117,12 +67,4 @@
   return false;
 }
 
-template <typename T>
-inline ZArrayIterator<T>::ZArrayIterator(ZArray<T>* array) :
-    ZArrayIteratorImpl<T, ZARRAY_SERIAL>(array) {}
-
-template <typename T>
-inline ZArrayParallelIterator<T>::ZArrayParallelIterator(ZArray<T>* array) :
-    ZArrayIteratorImpl<T, ZARRAY_PARALLEL>(array) {}
-
 #endif // SHARE_GC_Z_ZARRAY_INLINE_HPP
--- a/src/hotspot/share/gc/z/zPhysicalMemory.cpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zPhysicalMemory.cpp	Thu Aug 27 09:54:32 2020 +0200
@@ -24,6 +24,7 @@
 #include "precompiled.hpp"
 #include "gc/shared/gcLogPrecious.hpp"
 #include "gc/z/zAddress.inline.hpp"
+#include "gc/z/zArray.inline.hpp"
 #include "gc/z/zGlobals.hpp"
 #include "gc/z/zLargePages.inline.hpp"
 #include "gc/z/zNUMA.inline.hpp"
@@ -40,102 +41,58 @@
 #include "utilities/powerOfTwo.hpp"
 
 ZPhysicalMemory::ZPhysicalMemory() :
-    _nsegments_max(0),
-    _nsegments(0),
-    _segments(NULL) {}
+    _segments() {}
 
 ZPhysicalMemory::ZPhysicalMemory(const ZPhysicalMemorySegment& segment) :
-    _nsegments_max(0),
-    _nsegments(0),
-    _segments(NULL) {
+    _segments() {
   add_segment(segment);
 }
 
 ZPhysicalMemory::ZPhysicalMemory(const ZPhysicalMemory& pmem) :
-    _nsegments_max(0),
-    _nsegments(0),
-    _segments(NULL) {
+    _segments() {
   add_segments(pmem);
 }
 
 const ZPhysicalMemory& ZPhysicalMemory::operator=(const ZPhysicalMemory& pmem) {
-  remove_segments();
+  // Free segments
+  _segments.clear_and_deallocate();
+
+  // Copy segments
   add_segments(pmem);
+
   return *this;
 }
 
-ZPhysicalMemory::~ZPhysicalMemory() {
-  remove_segments();
-}
-
 size_t ZPhysicalMemory::size() const {
   size_t size = 0;
 
-  for (uint32_t i = 0; i < _nsegments; i++) {
-    size += _segments[i].size();
+  for (int i = 0; i < _segments.length(); i++) {
+    size += _segments.at(i).size();
   }
 
   return size;
 }
 
-void ZPhysicalMemory::insert_segment(uint32_t index, uintptr_t start, size_t size, bool committed) {
-  assert(index <= _nsegments, "Invalid index");
-
-  ZPhysicalMemorySegment* const from_segments = _segments;
-
-  if (_nsegments + 1 > _nsegments_max) {
-    // Resize array
-    _nsegments_max = round_up_power_of_2(_nsegments_max + 1);
-    _segments = new ZPhysicalMemorySegment[_nsegments_max];
-
-    // Copy segments before index
-    for (uint32_t i = 0; i < index; i++) {
-      _segments[i] = from_segments[i];
-    }
-  }
-
-  // Copy/Move segments after index
-  for (uint32_t i = _nsegments; i > index; i--) {
-    _segments[i] = from_segments[i - 1];
-  }
-
-  // Insert new segment
-  _segments[index] = ZPhysicalMemorySegment(start, size, committed);
-  _nsegments++;
-
-  // Delete old array
-  if (from_segments != _segments) {
-    delete [] from_segments;
-  }
+void ZPhysicalMemory::insert_segment(int index, uintptr_t start, size_t size, bool committed) {
+  _segments.insert_before(index, ZPhysicalMemorySegment(start, size, committed));
 }
 
-void ZPhysicalMemory::replace_segment(uint32_t index, uintptr_t start, size_t size, bool committed) {
-  assert(index < _nsegments, "Invalid index");
-  _segments[index] = ZPhysicalMemorySegment(start, size, committed);;
+void ZPhysicalMemory::replace_segment(int index, uintptr_t start, size_t size, bool committed) {
+  _segments.at_put(index, ZPhysicalMemorySegment(start, size, committed));
 }
 
-void ZPhysicalMemory::remove_segment(uint32_t index) {
-  assert(index < _nsegments, "Invalid index");
-
-  // Move segments after index
-  for (uint32_t i = index + 1; i < _nsegments; i++) {
-    _segments[i - 1] = _segments[i];
-  }
-
-  _nsegments--;
+void ZPhysicalMemory::remove_segment(int index) {
+  _segments.remove_at(index);
 }
 
 void ZPhysicalMemory::add_segments(const ZPhysicalMemory& pmem) {
-  for (uint32_t i = 0; i < pmem.nsegments(); i++) {
+  for (int i = 0; i < pmem.nsegments(); i++) {
     add_segment(pmem.segment(i));
   }
 }
 
 void ZPhysicalMemory::remove_segments() {
-  delete [] _segments;
-  _segments = NULL;
-  _nsegments_max = 0;
-  _nsegments = 0;
+  _segments.clear_and_deallocate();
 }
 
 static bool is_mergable(const ZPhysicalMemorySegment& before, const ZPhysicalMemorySegment& after) {
@@ -144,29 +101,29 @@
 
 void ZPhysicalMemory::add_segment(const ZPhysicalMemorySegment& segment) {
   // Insert segments in address order, merge segments when possible
-  for (uint32_t i = _nsegments; i > 0; i--) {
-    const uint32_t current = i - 1;
+  for (int i = _segments.length(); i > 0; i--) {
+    const int current = i - 1;
 
-    if (_segments[current].end() <= segment.start()) {
-      if (is_mergable(_segments[current], segment)) {
-        if (current + 1 < _nsegments && is_mergable(segment, _segments[current + 1])) {
+    if (_segments.at(current).end() <= segment.start()) {
+      if (is_mergable(_segments.at(current), segment)) {
+        if (current + 1 < _segments.length() && is_mergable(segment, _segments.at(current + 1))) {
           // Merge with end of current segment and start of next segment
-          const size_t start = _segments[current].start();
-          const size_t size = _segments[current].size() + segment.size() + _segments[current + 1].size();
+          const size_t start = _segments.at(current).start();
+          const size_t size = _segments.at(current).size() + segment.size() + _segments.at(current + 1).size();
           replace_segment(current, start, size, segment.is_committed());
           remove_segment(current + 1);
           return;
         }
 
         // Merge with end of current segment
-        const size_t start = _segments[current].start();
-        const size_t size = _segments[current].size() + segment.size();
+        const size_t start = _segments.at(current).start();
+        const size_t size = _segments.at(current).size() + segment.size();
         replace_segment(current, start, size, segment.is_committed());
         return;
-      } else if (current + 1 < _nsegments && is_mergable(segment, _segments[current + 1])) {
+      } else if (current + 1 < _segments.length() && is_mergable(segment, _segments.at(current + 1))) {
         // Merge with start of next segment
         const size_t start = segment.start();
-        const size_t size = segment.size() + _segments[current + 1].size();
+        const size_t size = segment.size() + _segments.at(current + 1).size();
         replace_segment(current + 1, start, size, segment.is_committed());
         return;
       }
@@ -177,10 +134,10 @@
     }
   }
 
-  if (_nsegments > 0 && is_mergable(segment, _segments[0])) {
+  if (_segments.length() > 0 && is_mergable(segment, _segments.at(0))) {
     // Merge with start of first segment
     const size_t start = segment.start();
-    const size_t size = segment.size() + _segments[0].size();
+    const size_t size = segment.size() + _segments.at(0).size();
     replace_segment(0, start, size, segment.is_committed());
     return;
   }
@@ -189,41 +146,43 @@
   insert_segment(0, segment.start(), segment.size(), segment.is_committed());
 }
 
-bool ZPhysicalMemory::commit_segment(uint32_t index, size_t size) {
-  assert(index < _nsegments, "Invalid index");
-  assert(size <= _segments[index].size(), "Invalid size");
-  assert(!_segments[index].is_committed(), "Invalid state");
+bool ZPhysicalMemory::commit_segment(int index, size_t size) {
+  ZPhysicalMemorySegment& segment = _segments.at(index);
 
-  if (size == _segments[index].size()) {
+  assert(size <= segment.size(), "Invalid size");
+  assert(!segment.is_committed(), "Invalid state");
+
+  if (size == segment.size()) {
     // Completely committed
-    _segments[index].set_committed(true);
+    segment.set_committed(true);
     return true;
   }
 
   if (size > 0) {
     // Partially committed, split segment
-    insert_segment(index + 1, _segments[index].start() + size, _segments[index].size() - size, false /* committed */);
-    replace_segment(index, _segments[index].start(), size, true /* committed */);
+    insert_segment(index + 1, segment.start() + size, segment.size() - size, false /* committed */);
+    replace_segment(index, segment.start(), size, true /* committed */);
   }
 
   return false;
 }
 
-bool ZPhysicalMemory::uncommit_segment(uint32_t index, size_t size) {
-  assert(index < _nsegments, "Invalid index");
-  assert(size <= _segments[index].size(), "Invalid size");
-  assert(_segments[index].is_committed(), "Invalid state");
+bool ZPhysicalMemory::uncommit_segment(int index, size_t size) {
+  ZPhysicalMemorySegment& segment = _segments.at(index);
 
-  if (size == _segments[index].size()) {
+  assert(size <= segment.size(), "Invalid size");
+  assert(segment.is_committed(), "Invalid state");
+
+  if (size == segment.size()) {
     // Completely uncommitted
-    _segments[index].set_committed(false);
+    segment.set_committed(false);
     return true;
   }
 
   if (size > 0) {
     // Partially uncommitted, split segment
-    insert_segment(index + 1, _segments[index].start() + size, _segments[index].size() - size, true /* committed */);
-    replace_segment(index, _segments[index].start(), size, false /* committed */);
+    insert_segment(index + 1, segment.start() + size, segment.size() - size, true /* committed */);
+    replace_segment(index, segment.start(), size, false /* committed */);
   }
 
   return false;
@@ -231,10 +190,10 @@
 
 ZPhysicalMemory ZPhysicalMemory::split(size_t size) {
   ZPhysicalMemory pmem;
-  uint32_t nsegments = 0;
+  int nsegments = 0;
 
-  for (uint32_t i = 0; i < _nsegments; i++) {
-    const ZPhysicalMemorySegment& segment = _segments[i];
+  for (int i = 0; i < _segments.length(); i++) {
+    const ZPhysicalMemorySegment& segment = _segments.at(i);
     if (pmem.size() < size) {
       if (pmem.size() + segment.size() <= size) {
         // Transfer segment
@@ -243,35 +202,35 @@
         // Split segment
         const size_t split_size = size - pmem.size();
         pmem.add_segment(ZPhysicalMemorySegment(segment.start(), split_size, segment.is_committed()));
-        _segments[nsegments++] = ZPhysicalMemorySegment(segment.start() + split_size, segment.size() - split_size, segment.is_committed());
+        _segments.at_put(nsegments++, ZPhysicalMemorySegment(segment.start() + split_size, segment.size() - split_size, segment.is_committed()));
       }
     } else {
       // Keep segment
-      _segments[nsegments++] = segment;
+      _segments.at_put(nsegments++, segment);
     }
   }
 
-  _nsegments = nsegments;
+  _segments.trunc_to(nsegments);
 
   return pmem;
 }
 
 ZPhysicalMemory ZPhysicalMemory::split_committed() {
   ZPhysicalMemory pmem;
-  uint32_t nsegments = 0;
+  int nsegments = 0;
 
-  for (uint32_t i = 0; i < _nsegments; i++) {
-    const ZPhysicalMemorySegment& segment = _segments[i];
+  for (int i = 0; i < _segments.length(); i++) {
+    const ZPhysicalMemorySegment& segment = _segments.at(i);
     if (segment.is_committed()) {
       // Transfer segment
       pmem.add_segment(segment);
     } else {
       // Keep segment
-      _segments[nsegments++] = segment;
+      _segments.at_put(nsegments++, segment);
     }
   }
 
-  _nsegments = nsegments;
+  _segments.trunc_to(nsegments);
 
   return pmem;
 }
@@ -349,7 +308,7 @@
 
 void ZPhysicalMemoryManager::free(const ZPhysicalMemory& pmem) {
   // Free segments
-  for (uint32_t i = 0; i < pmem.nsegments(); i++) {
+  for (int i = 0; i < pmem.nsegments(); i++) {
     const ZPhysicalMemorySegment& segment = pmem.segment(i);
     _manager.free(segment.start(), segment.size());
   }
@@ -357,7 +316,7 @@
 
 bool ZPhysicalMemoryManager::commit(ZPhysicalMemory& pmem) {
   // Commit segments
-  for (uint32_t i = 0; i < pmem.nsegments(); i++) {
+  for (int i = 0; i < pmem.nsegments(); i++) {
     const ZPhysicalMemorySegment& segment = pmem.segment(i);
     if (segment.is_committed()) {
       // Segment already committed
@@ -378,7 +337,7 @@
 
 bool ZPhysicalMemoryManager::uncommit(ZPhysicalMemory& pmem) {
   // Commit segments
-  for (uint32_t i = 0; i < pmem.nsegments(); i++) {
+  for (int i = 0; i < pmem.nsegments(); i++) {
     const ZPhysicalMemorySegment& segment = pmem.segment(i);
     if (!segment.is_committed()) {
       // Segment already uncommitted
@@ -406,7 +365,7 @@
   size_t size = 0;
 
   // Map segments
-  for (uint32_t i = 0; i < pmem.nsegments(); i++) {
+  for (int i = 0; i < pmem.nsegments(); i++) {
     const ZPhysicalMemorySegment& segment = pmem.segment(i);
     _backing.map(addr + size, segment.size(), segment.start());
     size += segment.size();
--- a/src/hotspot/share/gc/z/zPhysicalMemory.hpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zPhysicalMemory.hpp	Thu Aug 27 09:54:32 2020 +0200
@@ -24,6 +24,7 @@
 #ifndef SHARE_GC_Z_ZPHYSICALMEMORY_HPP
 #define SHARE_GC_Z_ZPHYSICALMEMORY_HPP
 
+#include "gc/z/zArray.hpp"
 #include "gc/z/zMemory.hpp"
 #include "memory/allocation.hpp"
 #include OS_HEADER(gc/z/zPhysicalMemoryBacking)
@@ -48,33 +49,30 @@
 
 class ZPhysicalMemory {
 private:
-  uint32_t                _nsegments_max;
-  uint32_t                _nsegments;
-  ZPhysicalMemorySegment* _segments;
+  ZArray<ZPhysicalMemorySegment> _segments;
 
-  void insert_segment(uint32_t index, uintptr_t start, size_t size, bool committed);
-  void replace_segment(uint32_t index, uintptr_t start, size_t size, bool committed);
-  void remove_segment(uint32_t index);
+  void insert_segment(int index, uintptr_t start, size_t size, bool committed);
+  void replace_segment(int index, uintptr_t start, size_t size, bool committed);
+  void remove_segment(int index);
 
 public:
   ZPhysicalMemory();
   ZPhysicalMemory(const ZPhysicalMemorySegment& segment);
   ZPhysicalMemory(const ZPhysicalMemory& pmem);
   const ZPhysicalMemory& operator=(const ZPhysicalMemory& pmem);
-  ~ZPhysicalMemory();
 
   bool is_null() const;
   size_t size() const;
 
-  uint32_t nsegments() const;
-  const ZPhysicalMemorySegment& segment(uint32_t index) const;
+  int nsegments() const;
+  const ZPhysicalMemorySegment& segment(int index) const;
 
   void add_segments(const ZPhysicalMemory& pmem);
   void remove_segments();
 
   void add_segment(const ZPhysicalMemorySegment& segment);
-  bool commit_segment(uint32_t index, size_t size);
-  bool uncommit_segment(uint32_t index, size_t size);
+  bool commit_segment(int index, size_t size);
+  bool uncommit_segment(int index, size_t size);
 
   ZPhysicalMemory split(size_t size);
   ZPhysicalMemory split_committed();
--- a/src/hotspot/share/gc/z/zPhysicalMemory.inline.hpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zPhysicalMemory.inline.hpp	Thu Aug 27 09:54:32 2020 +0200
@@ -58,16 +58,15 @@
 }
 
 inline bool ZPhysicalMemory::is_null() const {
-  return _nsegments == 0;
+  return _segments.length() == 0;
 }
 
-inline uint32_t ZPhysicalMemory::nsegments() const {
-  return _nsegments;
+inline int ZPhysicalMemory::nsegments() const {
+  return _segments.length();
 }
 
-inline const ZPhysicalMemorySegment& ZPhysicalMemory::segment(uint32_t index) const {
-  assert(index < _nsegments, "Invalid segment index");
-  return _segments[index];
+inline const ZPhysicalMemorySegment& ZPhysicalMemory::segment(int index) const {
+  return _segments.at(index);
 }
 
 #endif // SHARE_GC_Z_ZPHYSICALMEMORY_INLINE_HPP
--- a/src/hotspot/share/gc/z/zRelocationSetSelector.cpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zRelocationSetSelector.cpp	Thu Aug 27 09:54:32 2020 +0200
@@ -66,7 +66,7 @@
   const size_t garbage = size - live;
 
   if (garbage > _fragmentation_limit) {
-    _registered_pages.add(page);
+    _registered_pages.append(page);
   }
 
   _stats._npages++;
@@ -100,7 +100,7 @@
   const size_t npartitions = (size_t)1 << npartitions_shift;
   const size_t partition_size = _page_size >> npartitions_shift;
   const size_t partition_size_shift = exact_log2(partition_size);
-  const size_t npages = _registered_pages.size();
+  const size_t npages = _registered_pages.length();
 
   // Partition slots/fingers
   size_t partitions[npartitions];
@@ -140,7 +140,7 @@
   // Calculate the number of pages to relocate by successively including pages in
   // a candidate relocation set and calculate the maximum space requirement for
   // their live objects.
-  const size_t npages = _registered_pages.size();
+  const size_t npages = _registered_pages.length();
   size_t selected_from = 0;
   size_t selected_to = 0;
   size_t from_size = 0;
--- a/src/hotspot/share/gc/z/zSafeDelete.inline.hpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/src/hotspot/share/gc/z/zSafeDelete.inline.hpp	Thu Aug 27 09:54:32 2020 +0200
@@ -39,7 +39,7 @@
 bool ZSafeDeleteImpl<T>::deferred_delete(ItemT* item) {
   ZLocker<ZLock> locker(_lock);
   if (_enabled > 0) {
-    _deferred.add(item);
+    _deferred.append(item);
     return true;
   }
 
--- a/test/hotspot/gtest/gc/z/test_zArray.cpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/test/hotspot/gtest/gc/z/test_zArray.cpp	Thu Aug 27 09:54:32 2020 +0200
@@ -25,63 +25,49 @@
 #include "gc/z/zArray.inline.hpp"
 #include "unittest.hpp"
 
-TEST(ZArrayTest, test_add) {
+TEST(ZArray, sanity) {
   ZArray<int> a;
 
   // Add elements
   for (int i = 0; i < 10; i++) {
-    a.add(i);
+    a.append(i);
   }
 
+  ZArray<int> b;
+
+  b.transfer(&a);
+
   // Check size
-  ASSERT_EQ(a.size(), 10u);
+  ASSERT_EQ(a.length(), 0);
+  ASSERT_EQ(a.max_length(), 0);
+  ASSERT_EQ(a.is_empty(), true);
 
-  // Check elements
-  for (int i = 0; i < 10; i++) {
-    EXPECT_EQ(a.at(i), i);
-  }
+  ASSERT_EQ(b.length(), 10);
+  ASSERT_GE(b.max_length(), 10);
+  ASSERT_EQ(b.is_empty(), false);
+
+  // Clear elements
+  a.clear();
+
+  // Check that b is unaffected
+  ASSERT_EQ(b.length(), 10);
+  ASSERT_GE(b.max_length(), 10);
+  ASSERT_EQ(b.is_empty(), false);
+
+  a.append(1);
+
+  // Check that b is unaffected
+  ASSERT_EQ(b.length(), 10);
+  ASSERT_GE(b.max_length(), 10);
+  ASSERT_EQ(b.is_empty(), false);
 }
 
-TEST(ZArrayTest, test_clear) {
+TEST(ZArray, iterator) {
   ZArray<int> a;
 
   // Add elements
   for (int i = 0; i < 10; i++) {
-    a.add(i);
-  }
-
-  // Check size
-  ASSERT_EQ(a.size(), 10u);
-  ASSERT_EQ(a.is_empty(), false);
-
-  // Clear elements
-  a.clear();
-
-  // Check size
-  ASSERT_EQ(a.size(), 0u);
-  ASSERT_EQ(a.is_empty(), true);
-
-  // Add element
-  a.add(11);
-
-  // Check size
-  ASSERT_EQ(a.size(), 1u);
-  ASSERT_EQ(a.is_empty(), false);
-
-  // Clear elements
-  a.clear();
-
-  // Check size
-  ASSERT_EQ(a.size(), 0u);
-  ASSERT_EQ(a.is_empty(), true);
-}
-
-TEST(ZArrayTest, test_iterator) {
-  ZArray<int> a;
-
-  // Add elements
-  for (int i = 0; i < 10; i++) {
-    a.add(i);
+    a.append(i);
   }
 
   // Iterate
--- a/test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp	Thu Aug 27 09:53:31 2020 +0200
+++ b/test/hotspot/gtest/gc/z/test_zPhysicalMemory.cpp	Thu Aug 27 09:54:32 2020 +0200
@@ -31,22 +31,22 @@
 
   ZPhysicalMemory pmem0;
   pmem0.add_segment(seg0);
-  EXPECT_EQ(pmem0.nsegments(), 1u);
+  EXPECT_EQ(pmem0.nsegments(), 1);
   EXPECT_EQ(pmem0.segment(0).size(), 100u);
 
   ZPhysicalMemory pmem1;
   pmem1.add_segment(seg0);
   pmem1.add_segment(seg1);
-  EXPECT_EQ(pmem1.nsegments(), 2u);
+  EXPECT_EQ(pmem1.nsegments(), 2);
   EXPECT_EQ(pmem1.segment(0).size(), 100u);
   EXPECT_EQ(pmem1.segment(1).size(), 100u);
 
   ZPhysicalMemory pmem2(pmem0);
-  EXPECT_EQ(pmem2.nsegments(), 1u);
+  EXPECT_EQ(pmem2.nsegments(), 1);
   EXPECT_EQ(pmem2.segment(0).size(), 100u);
 
   pmem2 = pmem1;
-  EXPECT_EQ(pmem2.nsegments(), 2u);
+  EXPECT_EQ(pmem2.nsegments(), 2);
   EXPECT_EQ(pmem2.segment(0).size(), 100u);
   EXPECT_EQ(pmem2.segment(1).size(), 100u);
 }
@@ -61,7 +61,7 @@
   const ZPhysicalMemorySegment seg6(6, 1, true);
 
   ZPhysicalMemory pmem0;
-  EXPECT_EQ(pmem0.nsegments(), 0u);
+  EXPECT_EQ(pmem0.nsegments(), 0);
   EXPECT_EQ(pmem0.is_null(), true);
 
   ZPhysicalMemory pmem1;
@@ -72,7 +72,7 @@
   pmem1.add_segment(seg4);
   pmem1.add_segment(seg5);
   pmem1.add_segment(seg6);
-  EXPECT_EQ(pmem1.nsegments(), 1u);
+  EXPECT_EQ(pmem1.nsegments(), 1);
   EXPECT_EQ(pmem1.segment(0).size(), 7u);
   EXPECT_EQ(pmem1.is_null(), false);
 
@@ -83,7 +83,7 @@
   pmem2.add_segment(seg4);
   pmem2.add_segment(seg5);
   pmem2.add_segment(seg6);
-  EXPECT_EQ(pmem2.nsegments(), 2u);
+  EXPECT_EQ(pmem2.nsegments(), 2);
   EXPECT_EQ(pmem2.segment(0).size(), 3u);
   EXPECT_EQ(pmem2.segment(1).size(), 3u);
   EXPECT_EQ(pmem2.is_null(), false);
@@ -94,7 +94,7 @@
   pmem3.add_segment(seg3);
   pmem3.add_segment(seg4);
   pmem3.add_segment(seg6);
-  EXPECT_EQ(pmem3.nsegments(), 3u);
+  EXPECT_EQ(pmem3.nsegments(), 3);
   EXPECT_EQ(pmem3.segment(0).size(), 1u);
   EXPECT_EQ(pmem3.segment(1).size(), 3u);
   EXPECT_EQ(pmem3.segment(2).size(), 1u);
@@ -105,7 +105,7 @@
   pmem4.add_segment(seg2);
   pmem4.add_segment(seg4);
   pmem4.add_segment(seg6);
-  EXPECT_EQ(pmem4.nsegments(), 4u);
+  EXPECT_EQ(pmem4.nsegments(), 4);
   EXPECT_EQ(pmem4.segment(0).size(), 1u);
   EXPECT_EQ(pmem4.segment(1).size(), 1u);
   EXPECT_EQ(pmem4.segment(2).size(), 1u);
@@ -119,12 +119,12 @@
   pmem.add_segment(ZPhysicalMemorySegment(10, 10, true));
   pmem.add_segment(ZPhysicalMemorySegment(30, 10, true));
   pmem.add_segment(ZPhysicalMemorySegment(50, 10, true));
-  EXPECT_EQ(pmem.nsegments(), 3u);
+  EXPECT_EQ(pmem.nsegments(), 3);
   EXPECT_EQ(pmem.size(), 30u);
   EXPECT_FALSE(pmem.is_null());
 
   pmem.remove_segments();
-  EXPECT_EQ(pmem.nsegments(), 0u);
+  EXPECT_EQ(pmem.nsegments(), 0);
   EXPECT_EQ(pmem.size(), 0u);
   EXPECT_TRUE(pmem.is_null());
 }
@@ -135,25 +135,25 @@
   pmem.add_segment(ZPhysicalMemorySegment(0, 10, true));
   pmem.add_segment(ZPhysicalMemorySegment(10, 10, true));
   pmem.add_segment(ZPhysicalMemorySegment(30, 10, true));
-  EXPECT_EQ(pmem.nsegments(), 2u);
+  EXPECT_EQ(pmem.nsegments(), 2);
   EXPECT_EQ(pmem.size(), 30u);
 
   ZPhysicalMemory pmem0 = pmem.split(1);
-  EXPECT_EQ(pmem0.nsegments(), 1u);
+  EXPECT_EQ(pmem0.nsegments(), 1);
   EXPECT_EQ(pmem0.size(), 1u);
-  EXPECT_EQ(pmem.nsegments(), 2u);
+  EXPECT_EQ(pmem.nsegments(), 2);
   EXPECT_EQ(pmem.size(), 29u);
 
   ZPhysicalMemory pmem1 = pmem.split(25);
-  EXPECT_EQ(pmem1.nsegments(), 2u);
+  EXPECT_EQ(pmem1.nsegments(), 2);
   EXPECT_EQ(pmem1.size(), 25u);
-  EXPECT_EQ(pmem.nsegments(), 1u);
+  EXPECT_EQ(pmem.nsegments(), 1);
   EXPECT_EQ(pmem.size(), 4u);
 
   ZPhysicalMemory pmem2 = pmem.split(4);
-  EXPECT_EQ(pmem2.nsegments(), 1u);
+  EXPECT_EQ(pmem2.nsegments(), 1);
   EXPECT_EQ(pmem2.size(), 4u);
-  EXPECT_EQ(pmem.nsegments(), 0u);
+  EXPECT_EQ(pmem.nsegments(), 0);
   EXPECT_EQ(pmem.size(), 0u);
 }
 
@@ -163,12 +163,12 @@
   pmem0.add_segment(ZPhysicalMemorySegment(10, 10, false));
   pmem0.add_segment(ZPhysicalMemorySegment(20, 10, true));
   pmem0.add_segment(ZPhysicalMemorySegment(30, 10, false));
-  EXPECT_EQ(pmem0.nsegments(), 4u);
+  EXPECT_EQ(pmem0.nsegments(), 4);
   EXPECT_EQ(pmem0.size(), 40u);
 
   ZPhysicalMemory pmem1 = pmem0.split_committed();
-  EXPECT_EQ(pmem0.nsegments(), 2u);
+  EXPECT_EQ(pmem0.nsegments(), 2);
   EXPECT_EQ(pmem0.size(), 20u);
-  EXPECT_EQ(pmem1.nsegments(), 2u);
+  EXPECT_EQ(pmem1.nsegments(), 2);
   EXPECT_EQ(pmem1.size(), 20u);
 }