changeset 58588:d172861d7559

8241743: Shenandoah: refactor and inline ShenandoahHeap::heap() Reviewed-by: rkennke
author shade
date Fri, 27 Mar 2020 15:33:11 +0100
parents 2ebedcc9933d
children 3524e8fc7701
files src/hotspot/share/gc/shenandoah/c1/shenandoahBarrierSetC1.cpp src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp src/hotspot/share/gc/shenandoah/shenandoahMonitoringSupport.cpp src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
diffstat 7 files changed, 21 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/c1/shenandoahBarrierSetC1.cpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/c1/shenandoahBarrierSetC1.cpp	Fri Mar 27 15:33:11 2020 +0100
@@ -27,7 +27,7 @@
 #include "gc/shared/satbMarkQueue.hpp"
 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
-#include "gc/shenandoah/shenandoahHeap.hpp"
+#include "gc/shenandoah/shenandoahHeap.inline.hpp"
 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 #include "gc/shenandoah/shenandoahRuntime.hpp"
 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
--- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp	Fri Mar 27 15:33:11 2020 +0100
@@ -169,7 +169,7 @@
 }
 
 void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) {
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
 
   if (!heap->is_in(obj)) {
     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap failed",
@@ -179,7 +179,7 @@
 }
 
 void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
 
   // Step 1. Check that obj is correct.
   // After this step, it is safe to call heap_region_containing().
@@ -247,7 +247,7 @@
 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
   assert_correct(interior_loc, obj, file, line);
 
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
   ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
   if (!r->is_active()) {
     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
@@ -300,7 +300,7 @@
 void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *file, int line) {
   assert_correct(interior_loc, obj, file, line);
 
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
   if (!heap->marking_context()->is_marked(obj)) {
     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked failed",
                   "Object should be marked",
@@ -311,7 +311,7 @@
 void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) {
   assert_correct(interior_loc, obj, file, line);
 
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
   if (!heap->in_collection_set(obj)) {
     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_in_cset failed",
                   "Object should be in collection set",
@@ -322,7 +322,7 @@
 void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line) {
   assert_correct(interior_loc, obj, file, line);
 
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
   if (heap->in_collection_set(obj)) {
     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_in_cset failed",
                   "Object should not be in collection set",
@@ -331,7 +331,7 @@
 }
 
 void ShenandoahAsserts::assert_not_in_cset_loc(void* interior_loc, const char* file, int line) {
-  ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
   if (heap->in_collection_set_loc(interior_loc)) {
     print_failure(_safe_unknown, NULL, interior_loc, NULL, "Shenandoah assert_not_in_cset_loc failed",
                   "Interior location should not be in collection set",
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Fri Mar 27 15:33:11 2020 +0100
@@ -82,6 +82,8 @@
 #include "services/mallocTracker.hpp"
 #include "utilities/powerOfTwo.hpp"
 
+ShenandoahHeap* ShenandoahHeap::_heap = NULL;
+
 #ifdef ASSERT
 template <class T>
 void ShenandoahAssertToSpaceClosure::do_oop_work(T* p) {
@@ -461,6 +463,8 @@
   _liveness_cache(NULL),
   _collection_set(NULL)
 {
+  _heap = this;
+
   log_info(gc, init)("GC threads: " UINT32_FORMAT " parallel, " UINT32_FORMAT " concurrent", ParallelGCThreads, ConcGCThreads);
   log_info(gc, init)("Reference processing: %s", ParallelRefProcEnabled ? "parallel" : "serial");
 
@@ -777,18 +781,6 @@
   return res;
 }
 
-ShenandoahHeap* ShenandoahHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Unitialized access to ShenandoahHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Shenandoah, "not a shenandoah heap");
-  return (ShenandoahHeap*) heap;
-}
-
-ShenandoahHeap* ShenandoahHeap::heap_no_check() {
-  CollectedHeap* heap = Universe::heap();
-  return (ShenandoahHeap*) heap;
-}
-
 HeapWord* ShenandoahHeap::allocate_memory(ShenandoahAllocRequest& req) {
   intptr_t pacer_epoch = 0;
   bool in_new_region = false;
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp	Fri Mar 27 15:33:11 2020 +0100
@@ -132,9 +132,11 @@
 
 // ---------- Initialization, termination, identification, printing routines
 //
+private:
+  static ShenandoahHeap* _heap;
+
 public:
   static ShenandoahHeap* heap();
-  static ShenandoahHeap* heap_no_check();
 
   const char* name()          const { return "Shenandoah"; }
   ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp	Fri Mar 27 15:33:11 2020 +0100
@@ -48,6 +48,10 @@
 #include "utilities/copy.hpp"
 #include "utilities/globalDefinitions.hpp"
 
+inline ShenandoahHeap* ShenandoahHeap::heap() {
+  assert(_heap != NULL, "Heap is not initialized yet");
+  return _heap;
+}
 
 inline ShenandoahHeapRegion* ShenandoahRegionIterator::next() {
   size_t new_index = Atomic::add(&_index, (size_t) 1);
--- a/src/hotspot/share/gc/shenandoah/shenandoahMonitoringSupport.cpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahMonitoringSupport.cpp	Fri Mar 27 15:33:11 2020 +0100
@@ -27,7 +27,7 @@
 #include "gc/shared/generationCounters.hpp"
 #include "gc/shared/hSpaceCounters.hpp"
 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
-#include "gc/shenandoah/shenandoahHeap.hpp"
+#include "gc/shenandoah/shenandoahHeap.inline.hpp"
 #include "gc/shenandoah/shenandoahHeapRegionCounters.hpp"
 #include "memory/metaspaceCounters.hpp"
 #include "services/memoryService.hpp"
--- a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Fri Mar 27 15:33:05 2020 +0100
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp	Fri Mar 27 15:33:11 2020 +0100
@@ -982,7 +982,7 @@
     T o = RawAccess<>::oop_load(p);
     if (!CompressedOops::is_null(o)) {
       oop obj = CompressedOops::decode_not_null(o);
-      ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
+      ShenandoahHeap* heap = ShenandoahHeap::heap();
 
       if (!heap->marking_context()->is_marked(obj)) {
         ShenandoahAsserts::print_failure(ShenandoahAsserts::_safe_all, obj, p, NULL,