changeset 49480:effb50eeea4e

8198528: Move GenerationSpecs from GenCollectorPolicy to GenCollectedHeap Reviewed-by: pliden, sjohanss, kbarrett
author stefank
date Thu, 22 Feb 2018 18:37:23 +0100
parents 4e8c86b75428
children 170c7b36aea6
files src/hotspot/share/gc/cms/cmsCollectorPolicy.cpp src/hotspot/share/gc/cms/cmsCollectorPolicy.hpp src/hotspot/share/gc/cms/cmsHeap.cpp src/hotspot/share/gc/serial/serialHeap.cpp src/hotspot/share/gc/shared/collectorPolicy.cpp src/hotspot/share/gc/shared/collectorPolicy.hpp src/hotspot/share/gc/shared/genCollectedHeap.cpp src/hotspot/share/gc/shared/genCollectedHeap.hpp src/hotspot/share/gc/shared/generation.cpp src/hotspot/share/runtime/vmStructs.cpp src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java
diffstat 11 files changed, 57 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/cms/cmsCollectorPolicy.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/cms/cmsCollectorPolicy.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -52,13 +52,6 @@
   _heap_alignment = compute_heap_alignment();
 }
 
-void ConcurrentMarkSweepPolicy::initialize_generations() {
-  _young_gen_spec = new GenerationSpec(Generation::ParNew, _initial_young_size,
-                                       _max_young_size, _gen_alignment);
-  _old_gen_spec   = new GenerationSpec(Generation::ConcurrentMarkSweep,
-                                       _initial_old_size, _max_old_size, _gen_alignment);
-}
-
 void ConcurrentMarkSweepPolicy::initialize_gc_policy_counters() {
   // initialize the policy counters - 2 collectors, 2 generations
   _gc_policy_counters = new GCPolicyCounters("ParNew:CMS", 2, 2);
--- a/src/hotspot/share/gc/cms/cmsCollectorPolicy.hpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/cms/cmsCollectorPolicy.hpp	Thu Feb 22 18:37:23 2018 +0100
@@ -30,7 +30,6 @@
 class ConcurrentMarkSweepPolicy : public GenCollectorPolicy {
  protected:
   void initialize_alignments();
-  void initialize_generations();
 
  public:
   ConcurrentMarkSweepPolicy() {}
--- a/src/hotspot/share/gc/cms/cmsHeap.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/cms/cmsHeap.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -64,7 +64,12 @@
 };
 
 CMSHeap::CMSHeap(GenCollectorPolicy *policy) :
-  GenCollectedHeap(policy), _eden_pool(NULL), _survivor_pool(NULL), _old_pool(NULL) {
+    GenCollectedHeap(policy,
+                     Generation::ParNew,
+                     Generation::ConcurrentMarkSweep),
+    _eden_pool(NULL),
+    _survivor_pool(NULL),
+    _old_pool(NULL) {
   _workers = new WorkGang("GC Thread", ParallelGCThreads,
                           /* are_GC_task_threads */true,
                           /* are_ConcurrentGC_threads */false);
--- a/src/hotspot/share/gc/serial/serialHeap.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/serial/serialHeap.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -29,7 +29,12 @@
 #include "services/memoryManager.hpp"
 
 SerialHeap::SerialHeap(GenCollectorPolicy* policy) :
-  GenCollectedHeap(policy), _eden_pool(NULL), _survivor_pool(NULL), _old_pool(NULL) {
+    GenCollectedHeap(policy,
+                     Generation::DefNew,
+                     Generation::MarkSweepCompact),
+    _eden_pool(NULL),
+    _survivor_pool(NULL),
+    _old_pool(NULL) {
   _young_manager = new GCMemoryManager("Copy", "end of minor GC");
   _old_manager = new GCMemoryManager("MarkSweepCompact", "end of major GC");
 }
--- a/src/hotspot/share/gc/shared/collectorPolicy.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/shared/collectorPolicy.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -170,9 +170,7 @@
     _min_old_size(0),
     _initial_old_size(0),
     _max_old_size(0),
-    _gen_alignment(0),
-    _young_gen_spec(NULL),
-    _old_gen_spec(NULL)
+    _gen_alignment(0)
 {}
 
 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
@@ -549,11 +547,6 @@
   _heap_alignment = compute_heap_alignment();
 }
 
-void MarkSweepPolicy::initialize_generations() {
-  _young_gen_spec = new GenerationSpec(Generation::DefNew, _initial_young_size, _max_young_size, _gen_alignment);
-  _old_gen_spec   = new GenerationSpec(Generation::MarkSweepCompact, _initial_old_size, _max_old_size, _gen_alignment);
-}
-
 void MarkSweepPolicy::initialize_gc_policy_counters() {
   // Initialize the policy counters - 2 collectors, 2 generations.
   _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 2);
--- a/src/hotspot/share/gc/shared/collectorPolicy.hpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/shared/collectorPolicy.hpp	Thu Feb 22 18:37:23 2018 +0100
@@ -75,7 +75,7 @@
   CollectorPolicy();
 
  public:
-  virtual void initialize_all() {
+  void initialize_all() {
     initialize_alignments();
     initialize_flags();
     initialize_size_info();
@@ -108,9 +108,6 @@
   // time. When using large pages they can differ.
   size_t _gen_alignment;
 
-  GenerationSpec* _young_gen_spec;
-  GenerationSpec* _old_gen_spec;
-
   GCPolicyCounters* _gc_policy_counters;
 
   void initialize_flags();
@@ -142,29 +139,12 @@
   size_t initial_old_size()   { return _initial_old_size; }
   size_t max_old_size()       { return _max_old_size; }
 
-  GenerationSpec* young_gen_spec() const {
-    assert(_young_gen_spec != NULL, "_young_gen_spec should have been initialized");
-    return _young_gen_spec;
-  }
-
-  GenerationSpec* old_gen_spec() const {
-    assert(_old_gen_spec != NULL, "_old_gen_spec should have been initialized");
-    return _old_gen_spec;
-  }
-
   // Performance Counter support
   GCPolicyCounters* counters()     { return _gc_policy_counters; }
 
   // Create the jstat counters for the GC policy.
   virtual void initialize_gc_policy_counters() = 0;
 
-  virtual void initialize_generations() { };
-
-  virtual void initialize_all() {
-    CollectorPolicy::initialize_all();
-    initialize_generations();
-  }
-
   size_t young_gen_size_lower_bound();
 
   size_t old_gen_size_lower_bound();
@@ -173,7 +153,6 @@
 class MarkSweepPolicy : public GenCollectorPolicy {
  protected:
   void initialize_alignments();
-  void initialize_generations();
 
  public:
   MarkSweepPolicy() {}
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -62,15 +62,23 @@
 #include "utilities/stack.inline.hpp"
 #include "utilities/vmError.hpp"
 
-GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy) :
+GenCollectedHeap::GenCollectedHeap(GenCollectorPolicy *policy,
+                                   Generation::Name young,
+                                   Generation::Name old) :
   CollectedHeap(),
   _rem_set(NULL),
+  _young_gen_spec(new GenerationSpec(young,
+                                     policy->initial_young_size(),
+                                     policy->max_young_size(),
+                                     policy->gen_alignment())),
+  _old_gen_spec(new GenerationSpec(old,
+                                   policy->initial_old_size(),
+                                   policy->max_old_size(),
+                                   policy->gen_alignment())),
   _gen_policy(policy),
   _soft_ref_gen_policy(),
   _process_strong_tasks(new SubTasksDone(GCH_PS_NumElements)),
-  _full_collections_completed(0)
-{
-  assert(policy != NULL, "Sanity check");
+  _full_collections_completed(0) {
 }
 
 jint GenCollectedHeap::initialize() {
@@ -101,12 +109,12 @@
   _rem_set = new CardTableRS(reserved_region());
   set_barrier_set(rem_set()->bs());
 
-  ReservedSpace young_rs = heap_rs.first_part(gen_policy()->young_gen_spec()->max_size(), false, false);
-  _young_gen = gen_policy()->young_gen_spec()->init(young_rs, rem_set());
-  heap_rs = heap_rs.last_part(gen_policy()->young_gen_spec()->max_size());
+  ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size(), false, false);
+  _young_gen = _young_gen_spec->init(young_rs, rem_set());
+  heap_rs = heap_rs.last_part(_young_gen_spec->max_size());
 
-  ReservedSpace old_rs = heap_rs.first_part(gen_policy()->old_gen_spec()->max_size(), false, false);
-  _old_gen = gen_policy()->old_gen_spec()->init(old_rs, rem_set());
+  ReservedSpace old_rs = heap_rs.first_part(_old_gen_spec->max_size(), false, false);
+  _old_gen = _old_gen_spec->init(old_rs, rem_set());
   clear_incremental_collection_failed();
 
   return JNI_OK;
@@ -129,12 +137,9 @@
   const size_t pageSize = UseLargePages ? os::large_page_size() : os::vm_page_size();
   assert(alignment % pageSize == 0, "Must be");
 
-  GenerationSpec* young_spec = gen_policy()->young_gen_spec();
-  GenerationSpec* old_spec = gen_policy()->old_gen_spec();
-
   // Check for overflow.
-  size_t total_reserved = young_spec->max_size() + old_spec->max_size();
-  if (total_reserved < young_spec->max_size()) {
+  size_t total_reserved = _young_gen_spec->max_size() + _old_gen_spec->max_size();
+  if (total_reserved < _young_gen_spec->max_size()) {
     vm_exit_during_initialization("The size of the object heap + VM data exceeds "
                                   "the maximum representable size");
   }
@@ -172,6 +177,14 @@
   _old_gen->ref_processor_init();
 }
 
+GenerationSpec* GenCollectedHeap::young_gen_spec() const {
+  return _young_gen_spec;
+}
+
+GenerationSpec* GenCollectedHeap::old_gen_spec() const {
+  return _old_gen_spec;
+}
+
 size_t GenCollectedHeap::capacity() const {
   return _young_gen->capacity() + _old_gen->capacity();
 }
--- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Thu Feb 22 18:37:23 2018 +0100
@@ -31,6 +31,7 @@
 #include "gc/shared/softRefGenPolicy.hpp"
 
 class AdaptiveSizePolicy;
+class GenerationSpec;
 class StrongRootsScope;
 class SubTasksDone;
 class WorkGang;
@@ -65,6 +66,9 @@
   Generation* _young_gen;
   Generation* _old_gen;
 
+  GenerationSpec* _young_gen_spec;
+  GenerationSpec* _old_gen_spec;
+
   // The singleton CardTable Remembered Set.
   CardTableRS* _rem_set;
 
@@ -149,7 +153,9 @@
   // we absolutely __must__ clear soft refs?
   bool must_clear_all_soft_refs();
 
-  GenCollectedHeap(GenCollectorPolicy *policy);
+  GenCollectedHeap(GenCollectorPolicy *policy,
+                   Generation::Name young,
+                   Generation::Name old);
 
   virtual void check_gen_kinds() = 0;
 
@@ -171,6 +177,9 @@
   bool is_young_gen(const Generation* gen) const { return gen == _young_gen; }
   bool is_old_gen(const Generation* gen) const { return gen == _old_gen; }
 
+  GenerationSpec* young_gen_spec() const;
+  GenerationSpec* old_gen_spec() const;
+
   // The generational collector policy.
   GenCollectorPolicy* gen_policy() const { return _gen_policy; }
 
--- a/src/hotspot/share/gc/shared/generation.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/gc/shared/generation.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -63,9 +63,9 @@
 size_t Generation::initial_size() {
   GenCollectedHeap* gch = GenCollectedHeap::heap();
   if (gch->is_young_gen(this)) {
-    return gch->gen_policy()->young_gen_spec()->init_size();
+    return gch->young_gen_spec()->init_size();
   }
-  return gch->gen_policy()->old_gen_spec()->init_size();
+  return gch->old_gen_spec()->init_size();
 }
 
 size_t Generation::max_capacity() const {
--- a/src/hotspot/share/runtime/vmStructs.cpp	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Thu Feb 22 18:37:23 2018 +0100
@@ -514,9 +514,8 @@
                                                                                                                                      \
   nonstatic_field(GenCollectedHeap,            _young_gen,                                    Generation*)                           \
   nonstatic_field(GenCollectedHeap,            _old_gen,                                      Generation*)                           \
-                                                                                                                                     \
-  nonstatic_field(GenCollectorPolicy,          _young_gen_spec,                               GenerationSpec*)                       \
-  nonstatic_field(GenCollectorPolicy,          _old_gen_spec,                                 GenerationSpec*)                       \
+  nonstatic_field(GenCollectedHeap,            _young_gen_spec,                               GenerationSpec*)                       \
+  nonstatic_field(GenCollectedHeap,            _old_gen_spec,                                 GenerationSpec*)                       \
                                                                                                                                      \
   nonstatic_field(HeapWord,                    i,                                             char*)                                 \
                                                                                                                                      \
@@ -1470,7 +1469,6 @@
            declare_type(DefNewGeneration,             Generation)         \
            declare_type(CardGeneration,               Generation)         \
            declare_type(TenuredGeneration,            CardGeneration)     \
-  declare_toplevel_type(GenCollectorPolicy)                               \
   declare_toplevel_type(Space)                                            \
            declare_type(CompactibleSpace,             Space)              \
            declare_type(ContiguousSpace,              CompactibleSpace)   \
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java	Thu Feb 22 18:36:32 2018 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java	Thu Feb 22 18:37:23 2018 +0100
@@ -54,12 +54,10 @@
 
     youngGenField = type.getAddressField("_young_gen");
     oldGenField = type.getAddressField("_old_gen");
+    youngGenSpecField = type.getAddressField("_young_gen_spec");
+    oldGenSpecField = type.getAddressField("_old_gen_spec");
 
     genFactory = new GenerationFactory();
-
-    Type collectorPolicyType = db.lookupType("GenCollectorPolicy");
-    youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec");
-    oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec");
   }
 
   public GenCollectedHeap(Address addr) {