changeset 60652:731cdb89b27f

8241668: Shenandoah: make ShenandoahHeapRegion not derive from ContiguousSpace Reviewed-by: rkennke
author shade
date Thu, 26 Mar 2020 19:08:30 +0100
parents 5ac19bd3a1e2
children b2651fabca58
files src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp src/hotspot/share/gc/shenandoah/vmStructs_shenandoah.hpp src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java
diffstat 5 files changed, 80 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Thu Mar 26 10:14:52 2020 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Thu Mar 26 19:08:30 2020 +0100
@@ -1127,16 +1127,16 @@
 }
 
 HeapWord* ShenandoahHeap::block_start(const void* addr) const {
-  Space* sp = heap_region_containing(addr);
-  if (sp != NULL) {
-    return sp->block_start(addr);
+  ShenandoahHeapRegion* r = heap_region_containing(addr);
+  if (r != NULL) {
+    return r->block_start(addr);
   }
   return NULL;
 }
 
 bool ShenandoahHeap::block_is_obj(const HeapWord* addr) const {
-  Space* sp = heap_region_containing(addr);
-  return sp->block_is_obj(addr);
+  ShenandoahHeapRegion* r = heap_region_containing(addr);
+  return r->block_is_obj(addr);
 }
 
 bool ShenandoahHeap::print_location(outputStream* st, void* addr) const {
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp	Thu Mar 26 10:14:52 2020 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp	Thu Mar 26 19:08:30 2020 +0100
@@ -60,9 +60,12 @@
   _heap(heap),
   _reserved(MemRegion(start, size_words)),
   _region_number(index),
+  _bottom(start),
+  _end(start + size_words),
   _new_top(NULL),
   _empty_time(os::elapsedTime()),
   _state(committed ? _empty_committed : _empty_uncommitted),
+  _top(start),
   _tlab_allocs(0),
   _gclab_allocs(0),
   _shared_allocs(0),
@@ -71,7 +74,11 @@
   _critical_pins(0),
   _update_watermark(start) {
 
-  ContiguousSpace::initialize(_reserved, true, committed);
+  assert(Universe::on_page_boundary(_bottom) && Universe::on_page_boundary(_end),
+         "invalid space boundaries");
+  if (ZapUnusedHeapArea && committed) {
+    SpaceMangler::mangle_region(_reserved);
+  }
 }
 
 size_t ShenandoahHeapRegion::region_number() const {
@@ -469,10 +476,7 @@
 }
 
 void ShenandoahHeapRegion::recycle() {
-  ContiguousSpace::clear(false);
-  if (ZapUnusedHeapArea) {
-    ContiguousSpace::mangle_unused_area_complete();
-  }
+  set_top(bottom());
   clear_live_data();
 
   reset_alloc_metadata();
@@ -481,9 +485,13 @@
   set_update_watermark(bottom());
 
   make_empty();
+
+  if (ZapUnusedHeapArea) {
+    SpaceMangler::mangle_region(_reserved);
+  }
 }
 
-HeapWord* ShenandoahHeapRegion::block_start_const(const void* p) const {
+HeapWord* ShenandoahHeapRegion::block_start(const void* p) const {
   assert(MemRegion(bottom(), end()).contains(p),
          "p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
          p2i(p), p2i(bottom()), p2i(end()));
@@ -501,6 +509,18 @@
   }
 }
 
+size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
+  assert(MemRegion(bottom(), end()).contains(p),
+         "p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
+         p2i(p), p2i(bottom()), p2i(end()));
+  if (p < top()) {
+    return oop(p)->size();
+  } else {
+    assert(p == top(), "just checking");
+    return pointer_delta(end(), (HeapWord*) p);
+  }
+}
+
 void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
   // Absolute minimums we should not ever break.
   static const size_t MIN_REGION_SIZE = 256*K;
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp	Thu Mar 26 10:14:52 2020 -0700
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp	Thu Mar 26 19:08:30 2020 +0100
@@ -25,7 +25,7 @@
 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
 
-#include "gc/shared/space.hpp"
+#include "gc/shared/spaceDecorator.hpp"
 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
 #include "gc/shenandoah/shenandoahAsserts.hpp"
 #include "gc/shenandoah/shenandoahHeap.hpp"
@@ -35,7 +35,7 @@
 class VMStructs;
 class ShenandoahHeapRegionStateConstant;
 
-class ShenandoahHeapRegion : public ContiguousSpace {
+class ShenandoahHeapRegion : public CHeapObj<mtGC> {
   friend class VMStructs;
   friend class ShenandoahHeapRegionStateConstant;
 private:
@@ -237,9 +237,11 @@
   static PaddedAllocSeqNum _alloc_seq_num;
 
   // Never updated fields
-  ShenandoahHeap* _heap;
-  MemRegion _reserved;
-  size_t _region_number;
+  ShenandoahHeap* const _heap;
+  MemRegion const _reserved;
+  size_t const _region_number;
+  HeapWord* const _bottom;
+  HeapWord* const _end;
 
   // Rarely updated fields
   HeapWord* _new_top;
@@ -249,6 +251,8 @@
   RegionState _state;
 
   // Frequently updated fields
+  HeapWord* _top;
+
   size_t _tlab_allocs;
   size_t _gclab_allocs;
   size_t _shared_allocs;
@@ -356,8 +360,6 @@
   // Allocation (return NULL if full)
   inline HeapWord* allocate(size_t word_size, ShenandoahAllocRequest::Type type);
 
-  HeapWord* allocate(size_t word_size) shenandoah_not_implemented_return(NULL)
-
   void clear_live_data();
   void set_live_data(size_t s);
 
@@ -379,20 +381,25 @@
 
   void oop_iterate(OopIterateClosure* cl);
 
-  HeapWord* block_start_const(const void* p) const;
-
-  bool in_collection_set() const;
+  HeapWord* block_start(const void* p) const;
+  size_t block_size(const HeapWord* p) const;
+  bool block_is_obj(const HeapWord* p) const { return p < top(); }
 
   // Find humongous start region that this region belongs to
   ShenandoahHeapRegion* humongous_start_region() const;
 
-  CompactibleSpace* next_compaction_space() const shenandoah_not_implemented_return(NULL);
-  void prepare_for_compaction(CompactPoint* cp)   shenandoah_not_implemented;
-  void adjust_pointers()                          shenandoah_not_implemented;
-  void compact()                                  shenandoah_not_implemented;
+  HeapWord* top() const         { return _top;     }
+  void set_top(HeapWord* v)     { _top = v;        }
 
-  void set_new_top(HeapWord* new_top) { _new_top = new_top; }
-  HeapWord* new_top() const { return _new_top; }
+  HeapWord* new_top() const     { return _new_top; }
+  void set_new_top(HeapWord* v) { _new_top = v;    }
+
+  HeapWord* bottom() const      { return _bottom;  }
+  HeapWord* end() const         { return _end;     }
+
+  size_t capacity() const       { return byte_size(bottom(), end()); }
+  size_t used() const           { return byte_size(bottom(), top()); }
+  size_t free() const           { return byte_size(top(),    end()); }
 
   inline void adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t);
   void reset_alloc_metadata_to_shared();
--- a/src/hotspot/share/gc/shenandoah/vmStructs_shenandoah.hpp	Thu Mar 26 10:14:52 2020 -0700
+++ b/src/hotspot/share/gc/shenandoah/vmStructs_shenandoah.hpp	Thu Mar 26 19:08:30 2020 +0100
@@ -37,7 +37,10 @@
   static_field(ShenandoahHeapRegion, RegionSizeBytes,              size_t)                            \
   static_field(ShenandoahHeapRegion, RegionSizeBytesShift,         size_t)                            \
   nonstatic_field(ShenandoahHeapRegion, _state,                    ShenandoahHeapRegion::RegionState) \
-  nonstatic_field(ShenandoahHeapRegion, _region_number,            size_t)                            \
+  nonstatic_field(ShenandoahHeapRegion, _region_number,            size_t const)                      \
+  nonstatic_field(ShenandoahHeapRegion, _bottom,                   HeapWord* const)                   \
+  nonstatic_field(ShenandoahHeapRegion, _top,                      HeapWord*)                         \
+  nonstatic_field(ShenandoahHeapRegion, _end,                      HeapWord* const)                   \
 
 #define VM_INT_CONSTANTS_SHENANDOAH(declare_constant, declare_constant_with_value) \
   declare_constant(ShenandoahHeapRegion::_empty_uncommitted)                       \
@@ -55,7 +58,7 @@
                             declare_toplevel_type,                            \
                             declare_integer_type)                             \
   declare_type(ShenandoahHeap, CollectedHeap)                                 \
-  declare_type(ShenandoahHeapRegion, ContiguousSpace)                         \
+  declare_toplevel_type(ShenandoahHeapRegion)                                 \
   declare_toplevel_type(ShenandoahHeap*)                                      \
   declare_toplevel_type(ShenandoahHeapRegion*)                                \
   declare_toplevel_type(ShenandoahHeapRegion::RegionState)                    \
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java	Thu Mar 26 10:14:52 2020 -0700
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java	Thu Mar 26 19:08:30 2020 +0100
@@ -33,6 +33,7 @@
 import sun.jvm.hotspot.oops.UnknownOopException;
 import sun.jvm.hotspot.types.*;
 import sun.jvm.hotspot.runtime.VM;
+import sun.jvm.hotspot.runtime.VMObject;
 import sun.jvm.hotspot.debugger.Address;
 import sun.jvm.hotspot.utilities.AddressOps;
 
@@ -42,7 +43,7 @@
 import java.util.Observer;
 
 
-public class ShenandoahHeapRegion extends ContiguousSpace implements LiveRegionsProvider {
+public class ShenandoahHeapRegion extends VMObject implements LiveRegionsProvider {
     private static int EmptyUncommitted;
     private static int EmptyCommitted;
     private static int Regular;
@@ -59,6 +60,10 @@
     private static CIntegerField RegionNumberField;
     private static CIntegerField RegionSizeBytesShiftField;
 
+    private static AddressField BottomField;
+    private static AddressField TopField;
+    private static AddressField EndField;
+
     private ShenandoahHeap heap;
 
     static {
@@ -74,6 +79,9 @@
         RegionSizeBytesField = type.getCIntegerField("RegionSizeBytes");
         RegionStateField = type.getField("_state");
         RegionNumberField = type.getCIntegerField("_region_number");
+        BottomField = type.getAddressField("_bottom");
+        TopField = type.getAddressField("_top");
+        EndField = type.getAddressField("_end");
 
         RegionSizeBytesShiftField = type.getCIntegerField("RegionSizeBytesShift");
 
@@ -105,6 +113,18 @@
         this.heap = heap;
     }
 
+    public Address bottom() {
+        return BottomField.getValue(addr);
+    }
+
+    public Address top() {
+        return TopField.getValue(addr);
+    }
+
+    public Address end() {
+        return EndField.getValue(addr);
+    }
+
     @Override
     public int hashCode() {
         return (int)regionNumber();