changeset 59887:db21ed0754ae

8247740: Inline derived CollectedHeap access for G1 and ParallelGC Summary: Added shared helper in CollectedHeap, and inlined for G1 and ParallelGC Reviewed-by: stefank, pliden
author kbarrett
date Tue, 23 Jun 2020 05:58:52 -0400
parents f37be32c7662
children abdc7ca79bdf
files src/hotspot/share/gc/epsilon/epsilonHeap.cpp src/hotspot/share/gc/g1/g1CollectedHeap.cpp src/hotspot/share/gc/g1/g1CollectedHeap.hpp src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp src/hotspot/share/gc/serial/serialHeap.cpp src/hotspot/share/gc/shared/collectedHeap.hpp src/hotspot/share/gc/shared/genCollectedHeap.cpp src/hotspot/share/gc/z/zCollectedHeap.cpp
diffstat 9 files changed, 28 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/epsilon/epsilonHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/epsilon/epsilonHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -101,10 +101,7 @@
 }
 
 EpsilonHeap* EpsilonHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Epsilon, "Not an Epsilon heap");
-  return (EpsilonHeap*)heap;
+  return named_heap<EpsilonHeap>(CollectedHeap::Epsilon);
 }
 
 HeapWord* EpsilonHeap::allocate_work(size_t size) {
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -2668,13 +2668,6 @@
   gc_tracer->report_metaspace_summary(when, metaspace_summary);
 }
 
-G1CollectedHeap* G1CollectedHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to G1CollectedHeap::heap()");
-  assert(heap->kind() == CollectedHeap::G1, "Invalid name");
-  return (G1CollectedHeap*)heap;
-}
-
 void G1CollectedHeap::gc_prologue(bool full) {
   assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");
 
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Tue Jun 23 05:58:52 2020 -0400
@@ -1293,7 +1293,9 @@
 
   // Convenience function to be used in situations where the heap type can be
   // asserted to be this type.
-  static G1CollectedHeap* heap();
+  static G1CollectedHeap* heap() {
+    return named_heap<G1CollectedHeap>(CollectedHeap::G1);
+  }
 
   void set_region_short_lived_locked(HeapRegion* hr);
   // add appropriate methods for any other surv rate groups
--- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -689,13 +689,6 @@
   gc_tracer->report_metaspace_summary(when, metaspace_summary);
 }
 
-ParallelScavengeHeap* ParallelScavengeHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to ParallelScavengeHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Parallel, "Invalid name");
-  return (ParallelScavengeHeap*)heap;
-}
-
 CardTableBarrierSet* ParallelScavengeHeap::barrier_set() {
   return barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());
 }
--- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp	Tue Jun 23 05:58:52 2020 -0400
@@ -126,7 +126,9 @@
 
   static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
 
-  static ParallelScavengeHeap* heap();
+  static ParallelScavengeHeap* heap() {
+    return named_heap<ParallelScavengeHeap>(CollectedHeap::Parallel);
+  }
 
   CardTableBarrierSet* barrier_set();
   PSCardTable* card_table();
--- a/src/hotspot/share/gc/serial/serialHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/serial/serialHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,7 @@
 #include "services/memoryManager.hpp"
 
 SerialHeap* SerialHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to SerialHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
-  return static_cast<SerialHeap*>(heap);
+  return named_heap<SerialHeap>(CollectedHeap::Serial);
 }
 
 SerialHeap::SerialHeap() :
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Tue Jun 23 05:58:52 2020 -0400
@@ -29,6 +29,7 @@
 #include "gc/shared/gcWhen.hpp"
 #include "gc/shared/verifyOption.hpp"
 #include "memory/allocation.hpp"
+#include "memory/universe.hpp"
 #include "runtime/handles.hpp"
 #include "runtime/perfData.hpp"
 #include "runtime/safepoint.hpp"
@@ -177,6 +178,20 @@
     Shenandoah
   };
 
+ protected:
+  // Get a pointer to the derived heap object.  Used to implement
+  // derived class heap() functions rather than being called directly.
+  template<typename T>
+  static T* named_heap(Name kind) {
+    CollectedHeap* heap = Universe::heap();
+    assert(heap != NULL, "Uninitialized heap");
+    assert(kind == heap->kind(), "Heap kind %u should be %u",
+           static_cast<uint>(heap->kind()), static_cast<uint>(kind));
+    return static_cast<T*>(heap);
+  }
+
+ public:
+
   static inline size_t filler_array_max_size() {
     return _filler_array_max_size;
   }
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -1199,10 +1199,8 @@
 }
 
 GenCollectedHeap* GenCollectedHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
-  return (GenCollectedHeap*) heap;
+  // SerialHeap is the only subtype of GenCollectedHeap.
+  return named_heap<GenCollectedHeap>(CollectedHeap::Serial);
 }
 
 #if INCLUDE_SERIALGC
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp	Tue Jun 23 16:30:38 2020 +0800
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp	Tue Jun 23 05:58:52 2020 -0400
@@ -41,10 +41,7 @@
 #include "utilities/align.hpp"
 
 ZCollectedHeap* ZCollectedHeap::heap() {
-  CollectedHeap* heap = Universe::heap();
-  assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()");
-  assert(heap->kind() == CollectedHeap::Z, "Invalid name");
-  return (ZCollectedHeap*)heap;
+  return named_heap<ZCollectedHeap>(CollectedHeap::Z);
 }
 
 ZCollectedHeap::ZCollectedHeap() :