changeset 6425:8886a4bcaeaa

8027643: Merge GenCollectorPolicy and TwoGenerationCollectorPolicy Summary: Merged the two calsses GenCollectorPolicy and TwoGenerationCollectorPolicy Reviewed-by: sjohanss, jcoomes
author jwilhelm
date Tue, 29 Apr 2014 22:57:19 +0200
parents 1fd17e0a0791
children 5549b26a0660
files src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp src/share/vm/gc_implementation/parallelScavenge/generationSizer.cpp src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp src/share/vm/memory/collectorPolicy.cpp src/share/vm/memory/collectorPolicy.hpp src/share/vm/memory/genCollectedHeap.cpp src/share/vm/memory/genCollectedHeap.hpp src/share/vm/services/memoryService.cpp
diffstat 9 files changed, 37 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp	Tue Apr 29 22:57:19 2014 +0200
@@ -27,7 +27,7 @@
 
 #include "memory/collectorPolicy.hpp"
 
-class ConcurrentMarkSweepPolicy : public TwoGenerationCollectorPolicy {
+class ConcurrentMarkSweepPolicy : public GenCollectorPolicy {
  protected:
   void initialize_alignments();
   void initialize_generations();
--- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp	Tue Apr 29 22:57:19 2014 +0200
@@ -1560,7 +1560,7 @@
   // this is not likely to be productive in practice because it's probably too
   // late anyway.
   GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(gch->collector_policy()->is_two_generation_policy(),
+  assert(gch->collector_policy()->is_generation_policy(),
          "You may want to check the correctness of the following");
   if (gch->incremental_collection_will_fail(true /* consult_young */)) {
     if (Verbose && PrintGCDetails) {
@@ -1964,7 +1964,7 @@
   // has exceeded the threshold set by CMSFullGCsBeforeCompaction,
   // or if an incremental collection has failed
   GenCollectedHeap* gch = GenCollectedHeap::heap();
-  assert(gch->collector_policy()->is_two_generation_policy(),
+  assert(gch->collector_policy()->is_generation_policy(),
          "You may want to check the correctness of the following");
   // Inform cms gen if this was due to partial collection failing.
   // The CMS gen may use this fact to determine its expansion policy.
--- a/src/share/vm/gc_implementation/parallelScavenge/generationSizer.cpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/gc_implementation/parallelScavenge/generationSizer.cpp	Tue Apr 29 22:57:19 2014 +0200
@@ -45,7 +45,7 @@
 
 void GenerationSizer::initialize_flags() {
   // Do basic sizing work
-  TwoGenerationCollectorPolicy::initialize_flags();
+  GenCollectorPolicy::initialize_flags();
 
   assert(UseSerialGC ||
           !FLAG_IS_DEFAULT(ParallelGCThreads) ||
@@ -79,7 +79,7 @@
     // Redo everything from the start
     initialize_flags();
   }
-  TwoGenerationCollectorPolicy::initialize_size_info();
+  GenCollectorPolicy::initialize_size_info();
 
   trace_gen_sizes("ps heap rnd");
 }
--- a/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp	Tue Apr 29 22:57:19 2014 +0200
@@ -28,9 +28,9 @@
 #include "memory/collectorPolicy.hpp"
 
 // There is a nice batch of tested generation sizing code in
-// TwoGenerationCollectorPolicy. Lets reuse it!
+// GenCollectorPolicy. Lets reuse it!
 
-class GenerationSizer : public TwoGenerationCollectorPolicy {
+class GenerationSizer : public GenCollectorPolicy {
  private:
 
   void trace_gen_sizes(const char* const str);
--- a/src/share/vm/memory/collectorPolicy.cpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/memory/collectorPolicy.cpp	Tue Apr 29 22:57:19 2014 +0200
@@ -200,6 +200,9 @@
     _initial_gen0_size(0),
     _max_gen0_size(0),
     _gen_alignment(0),
+    _min_gen1_size(0),
+    _initial_gen1_size(0),
+    _max_gen1_size(0),
     _generations(NULL)
 {}
 
@@ -238,10 +241,6 @@
   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
-}
-
-void TwoGenerationCollectorPolicy::assert_flags() {
-  GenCollectorPolicy::assert_flags();
   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
   assert(OldSize % _gen_alignment == 0, "OldSize alignment");
 }
@@ -252,6 +251,7 @@
   assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes");
   assert(NewSize == _initial_gen0_size, "Discrepancy between NewSize flag and local storage");
   assert(MaxNewSize == _max_gen0_size, "Discrepancy between MaxNewSize flag and local storage");
+  assert(OldSize == _initial_gen1_size, "Discrepancy between OldSize flag and local storage");
   assert(_min_gen0_size <= _initial_gen0_size, "Ergonomics decided on incompatible minimum and initial young gen sizes");
   assert(_initial_gen0_size <= _max_gen0_size, "Ergonomics decided on incompatible initial and maximum young gen sizes");
   assert(_min_gen0_size % _gen_alignment == 0, "_min_gen0_size alignment");
@@ -263,11 +263,6 @@
       "Ergonomics made initial young generation larger than initial heap");
   assert(_max_gen0_size <= bound_minus_alignment(_max_gen0_size, _max_heap_byte_size),
       "Ergonomics made maximum young generation lager than maximum heap");
-}
-
-void TwoGenerationCollectorPolicy::assert_size_info() {
-  GenCollectorPolicy::assert_size_info();
-  assert(OldSize == _initial_gen1_size, "Discrepancy between OldSize flag and local storage");
   assert(_min_gen1_size <= _initial_gen1_size, "Ergonomics decided on incompatible minimum and initial old gen sizes");
   assert(_initial_gen1_size <= _max_gen1_size, "Ergonomics decided on incompatible initial and maximum old gen sizes");
   assert(_max_gen1_size % _gen_alignment == 0, "_max_gen1_size alignment");
@@ -369,12 +364,6 @@
     vm_exit_during_initialization("Invalid young gen ratio specified");
   }
 
-  DEBUG_ONLY(GenCollectorPolicy::assert_flags();)
-}
-
-void TwoGenerationCollectorPolicy::initialize_flags() {
-  GenCollectorPolicy::initialize_flags();
-
   if (!is_size_aligned(OldSize, _gen_alignment)) {
     // Setting OldSize directly to preserve information about the possible
     // setting of OldSize on the command line.
@@ -433,7 +422,7 @@
 
   always_do_update_barrier = UseConcMarkSweepGC;
 
-  DEBUG_ONLY(TwoGenerationCollectorPolicy::assert_flags();)
+  DEBUG_ONLY(GenCollectorPolicy::assert_flags();)
 }
 
 // Values set on the command line win over any ergonomically
@@ -445,6 +434,13 @@
 // themselves and with overall heap sizings.
 // In the absence of explicitly set command line flags, policies
 // such as the use of NewRatio are used to size the generation.
+
+// Minimum sizes of the generations may be different than
+// the initial sizes.  An inconsistency is permitted here
+// in the total size that can be specified explicitly by
+// command line specification of OldSize and NewSize and
+// also a command line specification of -Xms.  Issue a warning
+// but allow the values to pass.
 void GenCollectorPolicy::initialize_size_info() {
   CollectorPolicy::initialize_size_info();
 
@@ -520,19 +516,6 @@
       _min_gen0_size, _initial_gen0_size, _max_gen0_size);
   }
 
-  DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
-}
-
-// Minimum sizes of the generations may be different than
-// the initial sizes.  An inconsistency is permitted here
-// in the total size that can be specified explicitly by
-// command line specification of OldSize and NewSize and
-// also a command line specification of -Xms.  Issue a warning
-// but allow the values to pass.
-
-void TwoGenerationCollectorPolicy::initialize_size_info() {
-  GenCollectorPolicy::initialize_size_info();
-
   // At this point the minimum, initial and maximum sizes
   // of the overall heap and of gen0 have been determined.
   // The maximum gen1 size can be determined from the maximum gen0
@@ -625,7 +608,7 @@
       _min_gen1_size, _initial_gen1_size, _max_gen1_size);
   }
 
-  DEBUG_ONLY(TwoGenerationCollectorPolicy::assert_size_info();)
+  DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
 }
 
 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
--- a/src/share/vm/memory/collectorPolicy.hpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/memory/collectorPolicy.hpp	Tue Apr 29 22:57:19 2014 +0200
@@ -47,7 +47,6 @@
 
 // Forward declarations.
 class GenCollectorPolicy;
-class TwoGenerationCollectorPolicy;
 class AdaptiveSizePolicy;
 #if INCLUDE_ALL_GCS
 class ConcurrentMarkSweepPolicy;
@@ -114,7 +113,7 @@
 
   enum Name {
     CollectorPolicyKind,
-    TwoGenerationCollectorPolicyKind,
+    GenCollectorPolicyKind,
     ConcurrentMarkSweepPolicyKind,
     ASConcurrentMarkSweepPolicyKind,
     G1CollectorPolicyKind
@@ -135,7 +134,6 @@
 
   // Identification methods.
   virtual GenCollectorPolicy*           as_generation_policy()            { return NULL; }
-  virtual TwoGenerationCollectorPolicy* as_two_generation_policy()        { return NULL; }
   virtual MarkSweepPolicy*              as_mark_sweep_policy()            { return NULL; }
 #if INCLUDE_ALL_GCS
   virtual ConcurrentMarkSweepPolicy*    as_concurrent_mark_sweep_policy() { return NULL; }
@@ -143,7 +141,6 @@
 #endif // INCLUDE_ALL_GCS
   // Note that these are not virtual.
   bool is_generation_policy()            { return as_generation_policy() != NULL; }
-  bool is_two_generation_policy()        { return as_two_generation_policy() != NULL; }
   bool is_mark_sweep_policy()            { return as_mark_sweep_policy() != NULL; }
 #if INCLUDE_ALL_GCS
   bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; }
@@ -225,6 +222,9 @@
   size_t _min_gen0_size;
   size_t _initial_gen0_size;
   size_t _max_gen0_size;
+  size_t _min_gen1_size;
+  size_t _initial_gen1_size;
+  size_t _max_gen1_size;
 
   // _gen_alignment and _space_alignment will have the same value most of the
   // time. When using large pages they can differ.
@@ -264,8 +264,11 @@
   size_t initial_gen0_size() { return _initial_gen0_size; }
   size_t max_gen0_size()     { return _max_gen0_size; }
   size_t gen_alignment()     { return _gen_alignment; }
+  size_t min_gen1_size()     { return _min_gen1_size; }
+  size_t initial_gen1_size() { return _initial_gen1_size; }
+  size_t max_gen1_size()     { return _max_gen1_size; }
 
-  virtual int number_of_generations() = 0;
+  int number_of_generations() { return 2; }
 
   virtual GenerationSpec **generations() {
     assert(_generations != NULL, "Sanity check");
@@ -297,47 +300,15 @@
   virtual void post_heap_initialize() {
     assert(_max_gen0_size == MaxNewSize, "Should be taken care of by initialize_size_info");
   }
-};
 
-// All of hotspot's current collectors are subtypes of this
-// class. Currently, these collectors all use the same gen[0],
-// but have different gen[1] types. If we add another subtype
-// of CollectorPolicy, this class should be broken out into
-// its own file.
-
-class TwoGenerationCollectorPolicy : public GenCollectorPolicy {
- protected:
-  size_t _min_gen1_size;
-  size_t _initial_gen1_size;
-  size_t _max_gen1_size;
-
-  void initialize_flags();
-  void initialize_size_info();
-
-  DEBUG_ONLY(void assert_flags();)
-  DEBUG_ONLY(void assert_size_info();)
-
- public:
-  TwoGenerationCollectorPolicy() : GenCollectorPolicy(), _min_gen1_size(0),
-    _initial_gen1_size(0), _max_gen1_size(0) {}
-
-  // Accessors
-  size_t min_gen1_size()     { return _min_gen1_size; }
-  size_t initial_gen1_size() { return _initial_gen1_size; }
-  size_t max_gen1_size()     { return _max_gen1_size; }
-
-  // Inherited methods
-  TwoGenerationCollectorPolicy* as_two_generation_policy() { return this; }
-
-  int number_of_generations()          { return 2; }
   BarrierSet::Name barrier_set_name()  { return BarrierSet::CardTableModRef; }
 
   virtual CollectorPolicy::Name kind() {
-    return CollectorPolicy::TwoGenerationCollectorPolicyKind;
+    return CollectorPolicy::GenCollectorPolicyKind;
   }
 };
 
-class MarkSweepPolicy : public TwoGenerationCollectorPolicy {
+class MarkSweepPolicy : public GenCollectorPolicy {
  protected:
   void initialize_alignments();
   void initialize_generations();
--- a/src/share/vm/memory/genCollectedHeap.cpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/memory/genCollectedHeap.cpp	Tue Apr 29 22:57:19 2014 +0200
@@ -197,9 +197,8 @@
 
 void GenCollectedHeap::post_initialize() {
   SharedHeap::post_initialize();
-  TwoGenerationCollectorPolicy *policy =
-    (TwoGenerationCollectorPolicy *)collector_policy();
-  guarantee(policy->is_two_generation_policy(), "Illegal policy type");
+  GenCollectorPolicy *policy = (GenCollectorPolicy *)collector_policy();
+  guarantee(policy->is_generation_policy(), "Illegal policy type");
   DefNewGeneration* def_new_gen = (DefNewGeneration*) get_gen(0);
   assert(def_new_gen->kind() == Generation::DefNew ||
          def_new_gen->kind() == Generation::ParNew ||
--- a/src/share/vm/memory/genCollectedHeap.hpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/memory/genCollectedHeap.hpp	Tue Apr 29 22:57:19 2014 +0200
@@ -453,7 +453,7 @@
     // Assumes a 2-generation system; the first disjunct remembers if an
     // incremental collection failed, even when we thought (second disjunct)
     // that it would not.
-    assert(heap()->collector_policy()->is_two_generation_policy(),
+    assert(heap()->collector_policy()->is_generation_policy(),
            "the following definition may not be suitable for an n(>2)-generation system");
     return incremental_collection_failed() ||
            (consult_young && !get_gen(0)->collection_attempt_is_safe());
--- a/src/share/vm/services/memoryService.cpp	Tue Apr 29 09:33:20 2014 +0200
+++ b/src/share/vm/services/memoryService.cpp	Tue Apr 29 22:57:19 2014 +0200
@@ -123,12 +123,12 @@
 void MemoryService::add_gen_collected_heap_info(GenCollectedHeap* heap) {
   CollectorPolicy* policy = heap->collector_policy();
 
-  assert(policy->is_two_generation_policy(), "Only support two generations");
+  assert(policy->is_generation_policy(), "Only support two generations");
   guarantee(heap->n_gens() == 2, "Only support two-generation heap");
 
-  TwoGenerationCollectorPolicy* two_gen_policy = policy->as_two_generation_policy();
-  if (two_gen_policy != NULL) {
-    GenerationSpec** specs = two_gen_policy->generations();
+  GenCollectorPolicy* gen_policy = policy->as_generation_policy();
+  if (gen_policy != NULL) {
+    GenerationSpec** specs = gen_policy->generations();
     Generation::Name kind = specs[0]->name();
     switch (kind) {
       case Generation::DefNew: