8075635: Remove GenerationSpec array
authorjwilhelm
Mon, 16 Mar 2015 13:28:27 +0100
changeset 29794 2dcbd946f9a8
parent 29793 ddd5618b5804
child 29795 984c5c379c6a
8075635: Remove GenerationSpec array Summary: Replaced the array with explicit variables for young and old Reviewed-by: kbarrett, mgerdin
hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java
hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
hotspot/src/share/vm/memory/collectorPolicy.cpp
hotspot/src/share/vm/memory/collectorPolicy.hpp
hotspot/src/share/vm/memory/defNewGeneration.cpp
hotspot/src/share/vm/memory/genCollectedHeap.cpp
hotspot/src/share/vm/memory/genCollectedHeap.hpp
hotspot/src/share/vm/memory/generation.cpp
hotspot/src/share/vm/memory/generationSpec.hpp
hotspot/src/share/vm/runtime/vmStructs.cpp
hotspot/src/share/vm/services/memoryService.cpp
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java	Mon Mar 16 13:28:27 2015 +0100
@@ -37,7 +37,9 @@
   private static CIntegerField nGensField;
   private static AddressField youngGenField;
   private static AddressField oldGenField;
-  private static AddressField genSpecsField;
+
+  private static AddressField youngGenSpecField;
+  private static AddressField oldGenSpecField;
 
   private static GenerationFactory genFactory;
 
@@ -55,9 +57,12 @@
     nGensField = type.getCIntegerField("_n_gens");
     youngGenField = type.getAddressField("_young_gen");
     oldGenField = type.getAddressField("_old_gen");
-    genSpecsField = type.getAddressField("_gen_specs");
 
     genFactory = new GenerationFactory();
+
+    Type collectorPolicyType = db.lookupType("GenCollectorPolicy");
+    youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec");
+    oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec");
   }
 
   public GenCollectedHeap(Address addr) {
@@ -115,21 +120,23 @@
   /** Package-private access to GenerationSpecs */
   GenerationSpec spec(int level) {
     if (Assert.ASSERTS_ENABLED) {
-      Assert.that((level >= 0) && (level < nGens()), "Index " + level +
-                  " out of range (should be between 0 and " + nGens() + ")");
+      Assert.that((level == 0) || (level == 1), "Index " + level +
+                  " out of range (should be 0 or 1)");
     }
 
-    if ((level < 0) || (level >= nGens())) {
+    if ((level != 0) && (level != 1)) {
       return null;
     }
 
-    Address ptrList = genSpecsField.getValue(addr);
-    if (ptrList == null) {
-      return null;
+    if (level == 0) {
+      return (GenerationSpec)
+              VMObjectFactory.newObject(GenerationSpec.class,
+                      youngGenSpecField.getAddress());
+    } else {
+      return (GenerationSpec)
+              VMObjectFactory.newObject(GenerationSpec.class,
+                      oldGenSpecField.getAddress());
     }
-    return (GenerationSpec)
-      VMObjectFactory.newObject(GenerationSpec.class,
-                                ptrList.getAddressAt(level * VM.getVM().getAddressSize()));
   }
 
   public CollectedHeapName kind() {
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, 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
@@ -52,9 +52,10 @@
 }
 
 void ConcurrentMarkSweepPolicy::initialize_generations() {
-  _generations = NEW_C_HEAP_ARRAY(GenerationSpecPtr, number_of_generations(), mtGC);
-  _generations[0] = new GenerationSpec(Generation::ParNew, _initial_young_size, _max_young_size);
-  _generations[1] = new GenerationSpec(Generation::ConcurrentMarkSweep, _initial_old_size, _max_old_size);
+  _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_size_policy(size_t init_eden_size,
--- a/hotspot/src/share/vm/memory/collectorPolicy.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -190,11 +190,12 @@
     _min_young_size(0),
     _initial_young_size(0),
     _max_young_size(0),
-    _gen_alignment(0),
     _min_old_size(0),
     _initial_old_size(0),
     _max_old_size(0),
-    _generations(NULL)
+    _gen_alignment(0),
+    _young_gen_spec(NULL),
+    _old_gen_spec(NULL)
 {}
 
 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
@@ -912,9 +913,8 @@
 }
 
 void MarkSweepPolicy::initialize_generations() {
-  _generations = NEW_C_HEAP_ARRAY(GenerationSpecPtr, number_of_generations(), mtGC);
-  _generations[0] = new GenerationSpec(Generation::DefNew, _initial_young_size, _max_young_size);
-  _generations[1] = new GenerationSpec(Generation::MarkSweepCompact, _initial_old_size, _max_old_size);
+  _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() {
--- a/hotspot/src/share/vm/memory/collectorPolicy.hpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/collectorPolicy.hpp	Mon Mar 16 13:28:27 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, 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
@@ -208,7 +208,8 @@
 };
 
 class GenCollectorPolicy : public CollectorPolicy {
-friend class TestGenCollectorPolicy;
+  friend class TestGenCollectorPolicy;
+  friend class VMStructs;
  protected:
   size_t _min_young_size;
   size_t _initial_young_size;
@@ -221,7 +222,8 @@
   // time. When using large pages they can differ.
   size_t _gen_alignment;
 
-  GenerationSpec **_generations;
+  GenerationSpec* _young_gen_spec;
+  GenerationSpec* _old_gen_spec;
 
   // Return true if an allocation should be attempted in the older generation
   // if it fails in the younger generation.  Return false, otherwise.
@@ -261,9 +263,14 @@
 
   int number_of_generations() { return 2; }
 
-  virtual GenerationSpec **generations() {
-    assert(_generations != NULL, "Sanity check");
-    return _generations;
+  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;
   }
 
   virtual GenCollectorPolicy* as_generation_policy() { return this; }
--- a/hotspot/src/share/vm/memory/defNewGeneration.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -380,7 +380,7 @@
 
   int next_level = level() + 1;
   GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(next_level < gch->_n_gens,
+  assert(next_level < gch->n_gens(),
          "DefNewGeneration cannot be an oldest gen");
 
   Generation* old_gen = gch->old_gen();
--- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -90,7 +90,6 @@
 jint GenCollectedHeap::initialize() {
   CollectedHeap::pre_initialize();
 
-  int i;
   _n_gens = gen_policy()->number_of_generations();
   assert(_n_gens == 2, "There is no support for more than two generations");
 
@@ -101,16 +100,6 @@
   // HeapWordSize).
   guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
 
-  // The heap must be at least as aligned as generations.
-  size_t gen_alignment = Generation::GenGrain;
-
-  _gen_specs = gen_policy()->generations();
-
-  // Make sure the sizes are all aligned.
-  for (i = 0; i < _n_gens; i++) {
-    _gen_specs[i]->align(gen_alignment);
-  }
-
   // Allocate space for the heap.
 
   char* heap_address;
@@ -133,12 +122,12 @@
 
   _gch = this;
 
-  ReservedSpace young_rs = heap_rs.first_part(_gen_specs[0]->max_size(), false, false);
-  _young_gen = _gen_specs[0]->init(young_rs, 0, rem_set());
-  heap_rs = heap_rs.last_part(_gen_specs[0]->max_size());
+  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, 0, rem_set());
+  heap_rs = heap_rs.last_part(gen_policy()->young_gen_spec()->max_size());
 
-  ReservedSpace old_rs = heap_rs.first_part(_gen_specs[1]->max_size(), false, false);
-  _old_gen = _gen_specs[1]->init(old_rs, 1, rem_set());
+  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, 1, rem_set());
   clear_incremental_collection_failed();
 
 #if INCLUDE_ALL_GCS
@@ -155,21 +144,18 @@
 
 char* GenCollectedHeap::allocate(size_t alignment,
                                  ReservedSpace* heap_rs){
-  const char overflow_msg[] = "The size of the object heap + VM data exceeds "
-    "the maximum representable size";
-
   // Now figure out the total size.
-  size_t total_reserved = 0;
-  const size_t pageSize = UseLargePages ?
-      os::large_page_size() : os::vm_page_size();
-
+  const size_t pageSize = UseLargePages ? os::large_page_size() : os::vm_page_size();
   assert(alignment % pageSize == 0, "Must be");
 
-  for (int i = 0; i < _n_gens; i++) {
-    total_reserved += _gen_specs[i]->max_size();
-    if (total_reserved < _gen_specs[i]->max_size()) {
-      vm_exit_during_initialization(overflow_msg);
-    }
+  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()) {
+    vm_exit_during_initialization("The size of the object heap + VM data exceeds "
+                                  "the maximum representable size");
   }
   assert(total_reserved % alignment == 0,
          err_msg("Gen size; total_reserved=" SIZE_FORMAT ", alignment="
--- a/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/genCollectedHeap.hpp	Mon Mar 16 13:28:27 2015 +0100
@@ -67,8 +67,6 @@
   Generation* _young_gen;
   Generation* _old_gen;
 
-  GenerationSpec** _gen_specs;
-
   // The singleton Gen Remembered Set.
   GenRemSet* _rem_set;
 
@@ -145,8 +143,8 @@
     return CollectedHeap::GenCollectedHeap;
   }
 
-  Generation* young_gen() { return _young_gen; }
-  Generation* old_gen()   { return _old_gen; }
+  Generation* young_gen() const { return _young_gen; }
+  Generation* old_gen()   const { return _old_gen; }
 
   // The generational collector policy.
   GenCollectorPolicy* gen_policy() const { return _gen_policy; }
--- a/hotspot/src/share/vm/memory/generation.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/generation.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -63,8 +63,8 @@
 
 GenerationSpec* Generation::spec() {
   GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(0 <= level() && level() < gch->_n_gens, "Bad gen level");
-  return gch->_gen_specs[level()];
+  assert(level() == 0 || level() == 1, "Bad gen level");
+  return level() == 0 ? gch->gen_policy()->young_gen_spec() : gch->gen_policy()->old_gen_spec();
 }
 
 size_t Generation::max_capacity() const {
--- a/hotspot/src/share/vm/memory/generationSpec.hpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/memory/generationSpec.hpp	Mon Mar 16 13:28:27 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, 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
@@ -39,11 +39,11 @@
   size_t           _max_size;
 
 public:
-  GenerationSpec(Generation::Name name, size_t init_size, size_t max_size) {
-    _name = name;
-    _init_size = init_size;
-    _max_size = max_size;
-  }
+  GenerationSpec(Generation::Name name, size_t init_size, size_t max_size, size_t alignment) :
+    _name(name),
+    _init_size(align_size_up(init_size, alignment)),
+    _max_size(align_size_up(max_size, alignment))
+  { }
 
   Generation* init(ReservedSpace rs, int level, GenRemSet* remset);
 
@@ -53,12 +53,6 @@
   void set_init_size(size_t size)      { _init_size = size; }
   size_t max_size()              const { return _max_size; }
   void set_max_size(size_t size)       { _max_size = size; }
-
-  // Alignment
-  void align(size_t alignment) {
-    set_init_size(align_size_up(init_size(), alignment));
-    set_max_size(align_size_up(max_size(), alignment));
-  }
 };
 
 typedef GenerationSpec* GenerationSpecPtr;
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -527,11 +527,11 @@
   nonstatic_field(CollectedHeap,               _defer_initial_card_mark,                      bool)                                  \
   nonstatic_field(CollectedHeap,               _is_gc_active,                                 bool)                                  \
   nonstatic_field(CollectedHeap,               _total_collections,                            unsigned int)                          \
+                                                                                                                                     \
   nonstatic_field(CompactibleSpace,            _compaction_top,                               HeapWord*)                             \
   nonstatic_field(CompactibleSpace,            _first_dead,                                   HeapWord*)                             \
   nonstatic_field(CompactibleSpace,            _end_of_live,                                  HeapWord*)                             \
                                                                                                                                      \
-                                                                                                                                     \
   nonstatic_field(ContiguousSpace,             _top,                                          HeapWord*)                             \
   nonstatic_field(ContiguousSpace,             _concurrent_iteration_safe_limit,              HeapWord*)                             \
   nonstatic_field(ContiguousSpace,             _saved_mark_word,                              HeapWord*)                             \
@@ -559,7 +559,9 @@
   nonstatic_field(GenCollectedHeap,            _young_gen,                                    Generation*)                           \
   nonstatic_field(GenCollectedHeap,            _old_gen,                                      Generation*)                           \
  nonstatic_field(GenCollectedHeap,             _n_gens,                                       int)                                   \
-  nonstatic_field(GenCollectedHeap,            _gen_specs,                                    GenerationSpec**)                      \
+                                                                                                                                     \
+  nonstatic_field(GenCollectorPolicy,          _young_gen_spec,                               GenerationSpec*)                       \
+  nonstatic_field(GenCollectorPolicy,          _old_gen_spec,                                 GenerationSpec*)                       \
                                                                                                                                      \
   nonstatic_field(HeapWord,                    i,                                             char*)                                 \
                                                                                                                                      \
@@ -1505,6 +1507,7 @@
            declare_type(DefNewGeneration,             Generation)         \
            declare_type(CardGeneration,               Generation)         \
            declare_type(TenuredGeneration,            CardGeneration)     \
+  declare_toplevel_type(GenCollectorPolicy)                               \
   declare_toplevel_type(Space)                                            \
   declare_toplevel_type(BitMap)                                           \
            declare_type(CompactibleSpace,             Space)              \
--- a/hotspot/src/share/vm/services/memoryService.cpp	Thu Mar 26 11:00:49 2015 +0000
+++ b/hotspot/src/share/vm/services/memoryService.cpp	Mon Mar 16 13:28:27 2015 +0100
@@ -130,8 +130,7 @@
 
   GenCollectorPolicy* gen_policy = policy->as_generation_policy();
   if (gen_policy != NULL) {
-    GenerationSpec** specs = gen_policy->generations();
-    Generation::Name kind = specs[0]->name();
+    Generation::Name kind = gen_policy->young_gen_spec()->name();
     switch (kind) {
       case Generation::DefNew:
         _minor_gc_manager = MemoryManager::get_copy_memory_manager();