hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp
changeset 37039 79f62b89a7a6
parent 36365 bcc9c9afda49
child 37051 b02a3fb98142
equal deleted inserted replaced
36592:e208f63ee9ca 37039:79f62b89a7a6
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
    25 #ifndef SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
    26 #define SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
    26 #define SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
    27 
    27 
    28 #include "gc/g1/collectionSetChooser.hpp"
       
    29 #include "gc/g1/g1CollectorState.hpp"
    28 #include "gc/g1/g1CollectorState.hpp"
    30 #include "gc/g1/g1GCPhaseTimes.hpp"
    29 #include "gc/g1/g1GCPhaseTimes.hpp"
    31 #include "gc/g1/g1InCSetState.hpp"
    30 #include "gc/g1/g1InCSetState.hpp"
    32 #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp"
    31 #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp"
    33 #include "gc/g1/g1MMUTracker.hpp"
    32 #include "gc/g1/g1MMUTracker.hpp"
    39 // characteristics of the collector.  Examples include:
    38 // characteristics of the collector.  Examples include:
    40 //   * choice of collection set.
    39 //   * choice of collection set.
    41 //   * when to collect.
    40 //   * when to collect.
    42 
    41 
    43 class HeapRegion;
    42 class HeapRegion;
       
    43 class G1CollectionSet;
    44 class CollectionSetChooser;
    44 class CollectionSetChooser;
    45 class G1IHOPControl;
    45 class G1IHOPControl;
    46 class G1YoungGenSizer;
    46 class G1YoungGenSizer;
    47 
    47 
    48 class G1CollectorPolicy: public CollectorPolicy {
    48 class G1CollectorPolicy: public CollectorPolicy {
    63 
    63 
    64   G1MMUTracker* _mmu_tracker;
    64   G1MMUTracker* _mmu_tracker;
    65 
    65 
    66   void initialize_alignments();
    66   void initialize_alignments();
    67   void initialize_flags();
    67   void initialize_flags();
    68 
       
    69   CollectionSetChooser* _cset_chooser;
       
    70 
    68 
    71   double _full_collection_start_sec;
    69   double _full_collection_start_sec;
    72 
    70 
    73   // These exclude marking times.
    71   // These exclude marking times.
    74   TruncatedSeq* _recent_gc_times_ms;
    72   TruncatedSeq* _recent_gc_times_ms;
   126 
   124 
   127   TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
   125   TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
   128 
   126 
   129   G1YoungGenSizer* _young_gen_sizer;
   127   G1YoungGenSizer* _young_gen_sizer;
   130 
   128 
   131   uint _eden_cset_region_length;
       
   132   uint _survivor_cset_region_length;
       
   133   uint _old_cset_region_length;
       
   134 
       
   135   void init_cset_region_lengths(uint eden_cset_region_length,
       
   136                                 uint survivor_cset_region_length);
       
   137 
       
   138   uint eden_cset_region_length() const     { return _eden_cset_region_length;     }
       
   139   uint survivor_cset_region_length() const { return _survivor_cset_region_length; }
       
   140   uint old_cset_region_length() const      { return _old_cset_region_length;      }
       
   141 
       
   142   uint _free_regions_at_end_of_collection;
   129   uint _free_regions_at_end_of_collection;
   143 
   130 
   144   size_t _recorded_rs_lengths;
       
   145   size_t _max_rs_lengths;
   131   size_t _max_rs_lengths;
   146 
   132 
   147   size_t _rs_lengths_prediction;
   133   size_t _rs_lengths_prediction;
   148 
   134 
   149 #ifndef PRODUCT
   135 #ifndef PRODUCT
   227   double predict_base_elapsed_time_ms(size_t pending_cards,
   213   double predict_base_elapsed_time_ms(size_t pending_cards,
   228                                       size_t scanned_cards) const;
   214                                       size_t scanned_cards) const;
   229   size_t predict_bytes_to_copy(HeapRegion* hr) const;
   215   size_t predict_bytes_to_copy(HeapRegion* hr) const;
   230   double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc) const;
   216   double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc) const;
   231 
   217 
   232   void set_recorded_rs_lengths(size_t rs_lengths);
       
   233 
       
   234   uint cset_region_length() const       { return young_cset_region_length() +
       
   235                                            old_cset_region_length(); }
       
   236   uint young_cset_region_length() const { return eden_cset_region_length() +
       
   237                                            survivor_cset_region_length(); }
       
   238 
       
   239   double predict_survivor_regions_evac_time() const;
   218   double predict_survivor_regions_evac_time() const;
   240 
   219 
   241   bool should_update_surv_rate_group_predictors() {
   220   bool should_update_surv_rate_group_predictors() {
   242     return collector_state()->last_gc_was_young() && !collector_state()->in_marking_window();
   221     return collector_state()->last_gc_was_young() && !collector_state()->in_marking_window();
   243   }
   222   }
   272   double predict_yg_surv_rate(int age) const;
   251   double predict_yg_surv_rate(int age) const;
   273 
   252 
   274   double accum_yg_surv_rate_pred(int age) const;
   253   double accum_yg_surv_rate_pred(int age) const;
   275 
   254 
   276 protected:
   255 protected:
       
   256   G1CollectionSet* _collection_set;
   277   virtual double average_time_ms(G1GCPhaseTimes::GCParPhases phase) const;
   257   virtual double average_time_ms(G1GCPhaseTimes::GCParPhases phase) const;
   278   virtual double other_time_ms(double pause_time_ms) const;
   258   virtual double other_time_ms(double pause_time_ms) const;
   279 
   259 
   280   double young_other_time_ms() const;
   260   double young_other_time_ms() const;
   281   double non_young_other_time_ms() const;
   261   double non_young_other_time_ms() const;
   282   double constant_other_time_ms(double pause_time_ms) const;
   262   double constant_other_time_ms(double pause_time_ms) const;
   283 
   263 
   284   CollectionSetChooser* cset_chooser() const {
   264   CollectionSetChooser* cset_chooser() const;
   285     return _cset_chooser;
       
   286   }
       
   287 
       
   288 private:
   265 private:
   289   // Statistics kept per GC stoppage, pause or full.
   266   // Statistics kept per GC stoppage, pause or full.
   290   TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec;
   267   TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec;
   291 
   268 
   292   // Add a new GC of the given duration and end time to the record.
   269   // Add a new GC of the given duration and end time to the record.
   293   void update_recent_gc_times(double end_time_sec, double elapsed_ms);
   270   void update_recent_gc_times(double end_time_sec, double elapsed_ms);
   294 
   271 
   295   // The head of the list (via "next_in_collection_set()") representing the
       
   296   // current collection set. Set from the incrementally built collection
       
   297   // set at the start of the pause.
       
   298   HeapRegion* _collection_set;
       
   299 
       
   300   // The number of bytes in the collection set before the pause. Set from
       
   301   // the incrementally built collection set at the start of an evacuation
       
   302   // pause, and incremented in finalize_old_cset_part() when adding old regions
       
   303   // (if any) to the collection set.
       
   304   size_t _collection_set_bytes_used_before;
       
   305 
       
   306   // The number of bytes copied during the GC.
   272   // The number of bytes copied during the GC.
   307   size_t _bytes_copied_during_gc;
   273   size_t _bytes_copied_during_gc;
   308 
       
   309   // The associated information that is maintained while the incremental
       
   310   // collection set is being built with young regions. Used to populate
       
   311   // the recorded info for the evacuation pause.
       
   312 
       
   313   enum CSetBuildType {
       
   314     Active,             // We are actively building the collection set
       
   315     Inactive            // We are not actively building the collection set
       
   316   };
       
   317 
       
   318   CSetBuildType _inc_cset_build_state;
       
   319 
       
   320   // The head of the incrementally built collection set.
       
   321   HeapRegion* _inc_cset_head;
       
   322 
       
   323   // The tail of the incrementally built collection set.
       
   324   HeapRegion* _inc_cset_tail;
       
   325 
       
   326   // The number of bytes in the incrementally built collection set.
       
   327   // Used to set _collection_set_bytes_used_before at the start of
       
   328   // an evacuation pause.
       
   329   size_t _inc_cset_bytes_used_before;
       
   330 
       
   331   // The RSet lengths recorded for regions in the CSet. It is updated
       
   332   // by the thread that adds a new region to the CSet. We assume that
       
   333   // only one thread can be allocating a new CSet region (currently,
       
   334   // it does so after taking the Heap_lock) hence no need to
       
   335   // synchronize updates to this field.
       
   336   size_t _inc_cset_recorded_rs_lengths;
       
   337 
       
   338   // A concurrent refinement thread periodically samples the young
       
   339   // region RSets and needs to update _inc_cset_recorded_rs_lengths as
       
   340   // the RSets grow. Instead of having to synchronize updates to that
       
   341   // field we accumulate them in this field and add it to
       
   342   // _inc_cset_recorded_rs_lengths_diffs at the start of a GC.
       
   343   ssize_t _inc_cset_recorded_rs_lengths_diffs;
       
   344 
       
   345   // The predicted elapsed time it will take to collect the regions in
       
   346   // the CSet. This is updated by the thread that adds a new region to
       
   347   // the CSet. See the comment for _inc_cset_recorded_rs_lengths about
       
   348   // MT-safety assumptions.
       
   349   double _inc_cset_predicted_elapsed_time_ms;
       
   350 
       
   351   // See the comment for _inc_cset_recorded_rs_lengths_diffs.
       
   352   double _inc_cset_predicted_elapsed_time_ms_diffs;
       
   353 
   274 
   354   // Stash a pointer to the g1 heap.
   275   // Stash a pointer to the g1 heap.
   355   G1CollectedHeap* _g1;
   276   G1CollectedHeap* _g1;
   356 
   277 
   357   G1GCPhaseTimes* _phase_times;
   278   G1GCPhaseTimes* _phase_times;
   422   // given free space (expressed by base_free_regions).  It is used by
   343   // given free space (expressed by base_free_regions).  It is used by
   423   // calculate_young_list_target_length().
   344   // calculate_young_list_target_length().
   424   bool predict_will_fit(uint young_length, double base_time_ms,
   345   bool predict_will_fit(uint young_length, double base_time_ms,
   425                         uint base_free_regions, double target_pause_time_ms) const;
   346                         uint base_free_regions, double target_pause_time_ms) const;
   426 
   347 
       
   348 public:
       
   349   size_t pending_cards() const { return _pending_cards; }
       
   350 
   427   // Calculate the minimum number of old regions we'll add to the CSet
   351   // Calculate the minimum number of old regions we'll add to the CSet
   428   // during a mixed GC.
   352   // during a mixed GC.
   429   uint calc_min_old_cset_length() const;
   353   uint calc_min_old_cset_length() const;
   430 
   354 
   431   // Calculate the maximum number of old regions we'll add to the CSet
   355   // Calculate the maximum number of old regions we'll add to the CSet
   434 
   358 
   435   // Returns the given amount of uncollected reclaimable space
   359   // Returns the given amount of uncollected reclaimable space
   436   // as a percentage of the current heap capacity.
   360   // as a percentage of the current heap capacity.
   437   double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
   361   double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
   438 
   362 
       
   363 private:
   439   // Sets up marking if proper conditions are met.
   364   // Sets up marking if proper conditions are met.
   440   void maybe_start_marking();
   365   void maybe_start_marking();
   441 
   366 
   442   // The kind of STW pause.
   367   // The kind of STW pause.
   443   enum PauseKind {
   368   enum PauseKind {
   518   // The amount of space we copied during a GC.
   443   // The amount of space we copied during a GC.
   519   size_t bytes_copied_during_gc() const {
   444   size_t bytes_copied_during_gc() const {
   520     return _bytes_copied_during_gc;
   445     return _bytes_copied_during_gc;
   521   }
   446   }
   522 
   447 
   523   size_t collection_set_bytes_used_before() const {
       
   524     return _collection_set_bytes_used_before;
       
   525   }
       
   526 
       
   527   // Determine whether there are candidate regions so that the
   448   // Determine whether there are candidate regions so that the
   528   // next GC should be mixed. The two action strings are used
   449   // next GC should be mixed. The two action strings are used
   529   // in the ergo output when the method returns true or false.
   450   // in the ergo output when the method returns true or false.
   530   bool next_gc_should_be_mixed(const char* true_action_str,
   451   bool next_gc_should_be_mixed(const char* true_action_str,
   531                                const char* false_action_str) const;
   452                                const char* false_action_str) const;
   532 
   453 
   533   // Choose a new collection set.  Marks the chosen regions as being
   454   virtual void finalize_collection_set(double target_pause_time_ms);
   534   // "in_collection_set", and links them together.  The head and number of
       
   535   // the collection set are available via access methods.
       
   536   double finalize_young_cset_part(double target_pause_time_ms);
       
   537   virtual void finalize_old_cset_part(double time_remaining_ms);
       
   538 
       
   539   // The head of the list (via "next_in_collection_set()") representing the
       
   540   // current collection set.
       
   541   HeapRegion* collection_set() { return _collection_set; }
       
   542 
       
   543   void clear_collection_set() { _collection_set = NULL; }
       
   544 
       
   545   // Add old region "hr" to the CSet.
       
   546   void add_old_region_to_cset(HeapRegion* hr);
       
   547 
       
   548   // Incremental CSet Support
       
   549 
       
   550   // The head of the incrementally built collection set.
       
   551   HeapRegion* inc_cset_head() { return _inc_cset_head; }
       
   552 
       
   553   // The tail of the incrementally built collection set.
       
   554   HeapRegion* inc_set_tail() { return _inc_cset_tail; }
       
   555 
       
   556   // Initialize incremental collection set info.
       
   557   void start_incremental_cset_building();
       
   558 
       
   559   // Perform any final calculations on the incremental CSet fields
       
   560   // before we can use them.
       
   561   void finalize_incremental_cset_building();
       
   562 
       
   563   void clear_incremental_cset() {
       
   564     _inc_cset_head = NULL;
       
   565     _inc_cset_tail = NULL;
       
   566   }
       
   567 
       
   568   // Stop adding regions to the incremental collection set
       
   569   void stop_incremental_cset_building() { _inc_cset_build_state = Inactive; }
       
   570 
       
   571   // Add information about hr to the aggregated information for the
       
   572   // incrementally built collection set.
       
   573   void add_to_incremental_cset_info(HeapRegion* hr, size_t rs_length);
       
   574 
       
   575   // Update information about hr in the aggregated information for
       
   576   // the incrementally built collection set.
       
   577   void update_incremental_cset_info(HeapRegion* hr, size_t new_rs_length);
       
   578 
       
   579 private:
   455 private:
   580   // Update the incremental cset information when adding a region
       
   581   // (should not be called directly).
       
   582   void add_region_to_incremental_cset_common(HeapRegion* hr);
       
   583 
       
   584   // Set the state to start a concurrent marking cycle and clear
   456   // Set the state to start a concurrent marking cycle and clear
   585   // _initiate_conc_mark_if_possible because it has now been
   457   // _initiate_conc_mark_if_possible because it has now been
   586   // acted on.
   458   // acted on.
   587   void initiate_conc_mark();
   459   void initiate_conc_mark();
   588 
   460 
   589 public:
   461 public:
   590   // Add hr to the LHS of the incremental collection set.
       
   591   void add_region_to_incremental_cset_lhs(HeapRegion* hr);
       
   592 
       
   593   // Add hr to the RHS of the incremental collection set.
       
   594   void add_region_to_incremental_cset_rhs(HeapRegion* hr);
       
   595 
       
   596 #ifndef PRODUCT
       
   597   void print_collection_set(HeapRegion* list_head, outputStream* st);
       
   598 #endif // !PRODUCT
       
   599 
       
   600   // This sets the initiate_conc_mark_if_possible() flag to start a
   462   // This sets the initiate_conc_mark_if_possible() flag to start a
   601   // new cycle, as long as we are not already in one. It's best if it
   463   // new cycle, as long as we are not already in one. It's best if it
   602   // is called during a safepoint when the test whether a cycle is in
   464   // is called during a safepoint when the test whether a cycle is in
   603   // progress or not is stable.
   465   // progress or not is stable.
   604   bool force_initial_mark_if_outside_cycle(GCCause::Cause gc_cause);
   466   bool force_initial_mark_if_outside_cycle(GCCause::Cause gc_cause);