8154752: Cleanup initialization of G1Policy
authormgerdin
Tue, 19 Apr 2016 14:53:33 +0200
changeset 38013 89b93eb018fb
parent 38012 69916710bfed
child 38014 8731fa11f766
8154752: Cleanup initialization of G1Policy Reviewed-by: ehelin, tschatzl
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1Policy.cpp
hotspot/src/share/vm/gc/g1/g1Policy.hpp
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Tue Apr 19 14:53:32 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Tue Apr 19 14:53:33 2016 +0200
@@ -1989,7 +1989,7 @@
   }
 
   // Perform any initialization actions delegated to the policy.
-  g1_policy()->init();
+  g1_policy()->init(this, &_collection_set);
 
   JavaThread::satb_mark_queue_set().initialize(SATB_Q_CBL_mon,
                                                SATB_Q_FL_lock,
--- a/hotspot/src/share/vm/gc/g1/g1Policy.cpp	Tue Apr 19 14:53:32 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Policy.cpp	Tue Apr 19 14:53:33 2016 +0200
@@ -45,40 +45,23 @@
 G1Policy::G1Policy() :
   _predictor(G1ConfidencePercent / 100.0),
   _analytics(new G1Analytics(&_predictor)),
-  _pause_time_target_ms((double) MaxGCPauseMillis),
-  _rs_lengths_prediction(0),
-  _max_survivor_regions(0),
-  _survivors_age_table(true),
-
-  _bytes_allocated_in_old_since_last_gc(0),
-  _ihop_control(NULL),
+  _mmu_tracker(new G1MMUTrackerQueue(GCPauseIntervalMillis / 1000.0, MaxGCPauseMillis / 1000.0)),
+  _ihop_control(create_ihop_control(&_predictor)),
   _policy_counters(new GCPolicyCounters("GarbageFirst", 1, 3)),
-  _initial_mark_to_mixed() {
-
-  // SurvRateGroups below must be initialized after the predictor because they
-  // indirectly use it through this object passed to their constructor.
-  _short_lived_surv_rate_group =
-    new SurvRateGroup(&_predictor, "Short Lived", G1YoungSurvRateNumRegionsSummary);
-  _survivor_surv_rate_group =
-    new SurvRateGroup(&_predictor, "Survivor", G1YoungSurvRateNumRegionsSummary);
-
-  _phase_times = new G1GCPhaseTimes(ParallelGCThreads);
-
-  double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
-  double time_slice  = (double) GCPauseIntervalMillis / 1000.0;
-  _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
-
-  _tenuring_threshold = MaxTenuringThreshold;
-
-
-  guarantee(G1ReservePercent <= 50, "Range checking should not allow values over 50.");
-  _reserve_factor = (double) G1ReservePercent / 100.0;
-  // This will be set when the heap is expanded
-  // for the first time during initialization.
-  _reserve_regions = 0;
-
-  _ihop_control = create_ihop_control();
-}
+  _young_list_fixed_length(0),
+  _short_lived_surv_rate_group(new SurvRateGroup(&_predictor, "Short Lived", G1YoungSurvRateNumRegionsSummary)),
+  _survivor_surv_rate_group(new SurvRateGroup(&_predictor, "Survivor", G1YoungSurvRateNumRegionsSummary)),
+  _reserve_factor((double) G1ReservePercent / 100.0),
+  _reserve_regions(0),
+  _rs_lengths_prediction(0),
+  _bytes_allocated_in_old_since_last_gc(0),
+  _initial_mark_to_mixed(),
+  _collection_set(NULL),
+  _g1(NULL),
+  _phase_times(new G1GCPhaseTimes(ParallelGCThreads)),
+  _tenuring_threshold(MaxTenuringThreshold),
+  _max_survivor_regions(0),
+  _survivors_age_table(true) { }
 
 G1Policy::~G1Policy() {
   delete _ihop_control;
@@ -86,16 +69,13 @@
 
 G1CollectorState* G1Policy::collector_state() const { return _g1->collector_state(); }
 
-void G1Policy::init() {
-  // Set aside an initial future to_space.
-  _g1 = G1CollectedHeap::heap();
-  _collection_set = _g1->collection_set();
+void G1Policy::init(G1CollectedHeap* g1h, G1CollectionSet* collection_set) {
+  _g1 = g1h;
+  _collection_set = collection_set;
 
   assert(Heap_lock->owned_by_self(), "Locking discipline.");
 
-  if (adaptive_young_list_length()) {
-    _young_list_fixed_length = 0;
-  } else {
+  if (!adaptive_young_list_length()) {
     _young_list_fixed_length = _young_gen_sizer.min_desired_young_length();
   }
   _young_gen_sizer.adjust_max_new_size(_g1->max_regions());
@@ -798,10 +778,10 @@
   cset_chooser()->verify();
 }
 
-G1IHOPControl* G1Policy::create_ihop_control() const {
+G1IHOPControl* G1Policy::create_ihop_control(const G1Predictions* predictor){
   if (G1UseAdaptiveIHOP) {
     return new G1AdaptiveIHOPControl(InitiatingHeapOccupancyPercent,
-                                     &_predictor,
+                                     predictor,
                                      G1ReservePercent,
                                      G1HeapWastePercent);
   } else {
--- a/hotspot/src/share/vm/gc/g1/g1Policy.hpp	Tue Apr 19 14:53:32 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Policy.hpp	Tue Apr 19 14:53:33 2016 +0200
@@ -50,9 +50,8 @@
 
 class G1Policy: public CHeapObj<mtGC> {
  private:
-  G1IHOPControl* _ihop_control;
 
-  G1IHOPControl* create_ihop_control() const;
+  static G1IHOPControl* create_ihop_control(const G1Predictions* predictor);
   // Update the IHOP control with necessary statistics.
   void update_ihop_prediction(double mutator_time_s,
                               size_t mutator_alloc_bytes,
@@ -62,6 +61,7 @@
   G1Predictions _predictor;
   G1Analytics* _analytics;
   G1MMUTracker* _mmu_tracker;
+  G1IHOPControl* _ihop_control;
 
   GCPolicyCounters* _policy_counters;
 
@@ -74,10 +74,14 @@
   // locker is active. This should be >= _young_list_target_length;
   uint _young_list_max_length;
 
+  // SurvRateGroups below must be initialized after the predictor because they
+  // indirectly use it through this object passed to their constructor.
   SurvRateGroup* _short_lived_surv_rate_group;
   SurvRateGroup* _survivor_surv_rate_group;
 
   double _reserve_factor;
+  // This will be set when the heap is expanded
+  // for the first time during initialization.
   uint   _reserve_regions;
 
   G1YoungGenSizer _young_gen_sizer;
@@ -92,8 +96,6 @@
   bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group);
 #endif // PRODUCT
 
-  double _pause_time_target_ms;
-
   size_t _pending_cards;
 
   // The amount of allocated bytes in old gen during the last mutator and the following
@@ -299,7 +301,7 @@
   // This should be called after the heap is resized.
   void record_new_heap_size(uint new_number_of_regions);
 
-  void init();
+  void init(G1CollectedHeap* g1h, G1CollectionSet* collection_set);
 
   virtual void note_gc_start();