< prev index next >

src/share/vm/gc/g1/g1CollectorPolicy.hpp

Print this page
rev 9416 : dihop-changes
rev 9418 : imported patch erik-jmasa-review
rev 9419 : imported patch fix-evac-failure-needs-stats


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
  26 #define SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
  27 
  28 #include "gc/g1/collectionSetChooser.hpp"
  29 #include "gc/g1/g1CollectorState.hpp"
  30 #include "gc/g1/g1GCPhaseTimes.hpp"
  31 #include "gc/g1/g1InCSetState.hpp"

  32 #include "gc/g1/g1MMUTracker.hpp"
  33 #include "gc/g1/g1Predictions.hpp"
  34 #include "gc/shared/collectorPolicy.hpp"

  35 
  36 // A G1CollectorPolicy makes policy decisions that determine the
  37 // characteristics of the collector.  Examples include:
  38 //   * choice of collection set.
  39 //   * when to collect.
  40 
  41 class HeapRegion;
  42 class CollectionSetChooser;

  43 
  44 // TraceYoungGenTime collects data on _both_ young and mixed evacuation pauses
  45 // (the latter may contain non-young regions - i.e. regions that are
  46 // technically in old) while TraceOldGenTime collects data about full GCs.
  47 class TraceYoungGenTimeData : public CHeapObj<mtGC> {
  48  private:
  49   unsigned  _young_pause_num;
  50   unsigned  _mixed_pause_num;
  51 
  52   NumberSeq _all_stop_world_times_ms;
  53   NumberSeq _all_yield_times_ms;
  54 
  55   NumberSeq _total;
  56   NumberSeq _other;
  57   NumberSeq _root_region_scan_wait;
  58   NumberSeq _parallel;
  59   NumberSeq _ext_root_scan;
  60   NumberSeq _satb_filtering;
  61   NumberSeq _update_rs;
  62   NumberSeq _scan_rs;


 146 public:
 147   G1YoungGenSizer();
 148   // Calculate the maximum length of the young gen given the number of regions
 149   // depending on the sizing algorithm.
 150   uint max_young_length(uint number_of_heap_regions);
 151 
 152   void heap_size_changed(uint new_number_of_heap_regions);
 153   uint min_desired_young_length() {
 154     return _min_desired_young_length;
 155   }
 156   uint max_desired_young_length() {
 157     return _max_desired_young_length;
 158   }
 159   bool adaptive_young_list_length() const {
 160     return _adaptive_size;
 161   }
 162 };
 163 
 164 class G1CollectorPolicy: public CollectorPolicy {
 165  private:









 166   G1Predictions _predictor;
 167 
 168   double get_new_prediction(TruncatedSeq const* seq) const;
 169 
 170   // either equal to the number of parallel threads, if ParallelGCThreads
 171   // has been set, or 1 otherwise
 172   int _parallel_gc_threads;
 173 
 174   // The number of GC threads currently active.
 175   uintx _no_of_gc_threads;
 176 
 177   G1MMUTracker* _mmu_tracker;
 178 
 179   void initialize_alignments();
 180   void initialize_flags();
 181 
 182   CollectionSetChooser* _collectionSetChooser;
 183 
 184   double _full_collection_start_sec;
 185   uint   _cur_collection_pause_used_regions_at_start;


 254   size_t _recorded_rs_lengths;
 255   size_t _max_rs_lengths;
 256 
 257   size_t _rs_lengths_prediction;
 258 
 259 #ifndef PRODUCT
 260   bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group);
 261 #endif // PRODUCT
 262 
 263   void adjust_concurrent_refinement(double update_rs_time,
 264                                     double update_rs_processed_buffers,
 265                                     double goal_ms);
 266 
 267   uintx no_of_gc_threads() { return _no_of_gc_threads; }
 268   void set_no_of_gc_threads(uintx v) { _no_of_gc_threads = v; }
 269 
 270   double _pause_time_target_ms;
 271 
 272   size_t _pending_cards;
 273 





 274 public:
 275   const G1Predictions& predictor() const { return _predictor; }
 276 



 277   // Accessors
 278 
 279   void set_region_eden(HeapRegion* hr, int young_index_in_cset) {
 280     hr->set_eden();
 281     hr->install_surv_rate_group(_short_lived_surv_rate_group);
 282     hr->set_young_index_in_cset(young_index_in_cset);
 283   }
 284 
 285   void set_region_survivor(HeapRegion* hr, int young_index_in_cset) {
 286     assert(hr->is_survivor(), "pre-condition");
 287     hr->install_surv_rate_group(_survivor_surv_rate_group);
 288     hr->set_young_index_in_cset(young_index_in_cset);
 289   }
 290 
 291 #ifndef PRODUCT
 292   bool verify_young_ages();
 293 #endif // PRODUCT
 294 
 295   void record_max_rs_lengths(size_t rs_lengths) {
 296     _max_rs_lengths = rs_lengths;


 456   double _inc_cset_predicted_elapsed_time_ms_diffs;
 457 
 458   // Stash a pointer to the g1 heap.
 459   G1CollectedHeap* _g1;
 460 
 461   G1GCPhaseTimes* _phase_times;
 462 
 463   // The ratio of gc time to elapsed time, computed over recent pauses.
 464   double _recent_avg_pause_time_ratio;
 465 
 466   double recent_avg_pause_time_ratio() const {
 467     return _recent_avg_pause_time_ratio;
 468   }
 469 
 470   // This set of variables tracks the collector efficiency, in order to
 471   // determine whether we should initiate a new marking.
 472   double _cur_mark_stop_world_time_ms;
 473   double _mark_remark_start_sec;
 474   double _mark_cleanup_start_sec;
 475 
 476   void update_young_list_max_and_target_length();
 477   void update_young_list_max_and_target_length(size_t rs_lengths);


 478 
 479   // Update the young list target length either by setting it to the
 480   // desired fixed value or by calculating it using G1's pause
 481   // prediction model. If no rs_lengths parameter is passed, predict
 482   // the RS lengths using the prediction model, otherwise use the
 483   // given rs_lengths as the prediction.
 484   void update_young_list_target_length();
 485   void update_young_list_target_length(size_t rs_lengths);
 486 
 487   // Calculate and return the minimum desired young list target
 488   // length. This is the minimum desired young list length according
 489   // to the user's inputs.
 490   uint calculate_young_list_desired_min_length(uint base_min_length) const;
 491 
 492   // Calculate and return the maximum desired young list target
 493   // length. This is the maximum desired young list length according
 494   // to the user's inputs.
 495   uint calculate_young_list_desired_max_length() const;
 496 
 497   // Calculate and return the maximum young list target length that
 498   // can fit into the pause time goal. The parameters are: rs_lengths
 499   // represent the prediction of how large the young RSet lengths will
 500   // be, base_min_length is the already existing number of regions in
 501   // the young list, min_length and max_length are the desired min and
 502   // max young list length according to the user's inputs.
 503   uint calculate_young_list_target_length(size_t rs_lengths,
 504                                           uint base_min_length,
 505                                           uint desired_min_length,
 506                                           uint desired_max_length) const;
 507 
 508   uint bounded_young_list_target_length(size_t rs_lengths) const;



 509 
 510   void update_rs_lengths_prediction();
 511   void update_rs_lengths_prediction(size_t prediction);
 512 
 513   // Calculate and return chunk size (in number of regions) for parallel
 514   // concurrent mark cleanup.
 515   uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
 516 
 517   // Check whether a given young length (young_length) fits into the
 518   // given target pause time and whether the prediction for the amount
 519   // of objects to be copied for the given length will fit into the
 520   // given free space (expressed by base_free_regions).  It is used by
 521   // calculate_young_list_target_length().
 522   bool predict_will_fit(uint young_length, double base_time_ms,
 523                         uint base_free_regions, double target_pause_time_ms) const;
 524 
 525   // Calculate the minimum number of old regions we'll add to the CSet
 526   // during a mixed GC.
 527   uint calc_min_old_cset_length() const;
 528 
 529   // Calculate the maximum number of old regions we'll add to the CSet
 530   // during a mixed GC.
 531   uint calc_max_old_cset_length() const;
 532 
 533   // Returns the given amount of uncollected reclaimable space
 534   // as a percentage of the current heap capacity.
 535   double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
 536 
 537   // Sets up marking if proper conditions are met.
 538   void maybe_start_marking();


















 539 public:
 540 
 541   G1CollectorPolicy();


 542 
 543   virtual G1CollectorPolicy* as_g1_policy() { return this; }
 544 
 545   G1CollectorState* collector_state() const;
 546 
 547   G1GCPhaseTimes* phase_times() const { return _phase_times; }
 548 
 549   // Check the current value of the young list RSet lengths and
 550   // compare it against the last prediction. If the current value is
 551   // higher, recalculate the young list target length prediction.
 552   void revise_young_list_target_length_if_necessary();
 553 
 554   // This should be called after the heap is resized.
 555   void record_new_heap_size(uint new_number_of_regions);
 556 
 557   void init();
 558 
 559   virtual void note_gc_start(uint num_active_workers);
 560 
 561   // Create jstat counters for the policy.




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
  26 #define SHARE_VM_GC_G1_G1COLLECTORPOLICY_HPP
  27 
  28 #include "gc/g1/collectionSetChooser.hpp"
  29 #include "gc/g1/g1CollectorState.hpp"
  30 #include "gc/g1/g1GCPhaseTimes.hpp"
  31 #include "gc/g1/g1InCSetState.hpp"
  32 #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp"
  33 #include "gc/g1/g1MMUTracker.hpp"
  34 #include "gc/g1/g1Predictions.hpp"
  35 #include "gc/shared/collectorPolicy.hpp"
  36 #include "utilities/pair.hpp"
  37 
  38 // A G1CollectorPolicy makes policy decisions that determine the
  39 // characteristics of the collector.  Examples include:
  40 //   * choice of collection set.
  41 //   * when to collect.
  42 
  43 class HeapRegion;
  44 class CollectionSetChooser;
  45 class G1IHOPControl;
  46 
  47 // TraceYoungGenTime collects data on _both_ young and mixed evacuation pauses
  48 // (the latter may contain non-young regions - i.e. regions that are
  49 // technically in old) while TraceOldGenTime collects data about full GCs.
  50 class TraceYoungGenTimeData : public CHeapObj<mtGC> {
  51  private:
  52   unsigned  _young_pause_num;
  53   unsigned  _mixed_pause_num;
  54 
  55   NumberSeq _all_stop_world_times_ms;
  56   NumberSeq _all_yield_times_ms;
  57 
  58   NumberSeq _total;
  59   NumberSeq _other;
  60   NumberSeq _root_region_scan_wait;
  61   NumberSeq _parallel;
  62   NumberSeq _ext_root_scan;
  63   NumberSeq _satb_filtering;
  64   NumberSeq _update_rs;
  65   NumberSeq _scan_rs;


 149 public:
 150   G1YoungGenSizer();
 151   // Calculate the maximum length of the young gen given the number of regions
 152   // depending on the sizing algorithm.
 153   uint max_young_length(uint number_of_heap_regions);
 154 
 155   void heap_size_changed(uint new_number_of_heap_regions);
 156   uint min_desired_young_length() {
 157     return _min_desired_young_length;
 158   }
 159   uint max_desired_young_length() {
 160     return _max_desired_young_length;
 161   }
 162   bool adaptive_young_list_length() const {
 163     return _adaptive_size;
 164   }
 165 };
 166 
 167 class G1CollectorPolicy: public CollectorPolicy {
 168  private:
 169   G1IHOPControl* _ihop_control;
 170 
 171   G1IHOPControl* create_ihop_control() const;
 172   // Update the IHOP control with necessary statistics.
 173   void update_ihop_prediction(double mutator_time_s,
 174                               size_t mutator_alloc_bytes,
 175                               size_t young_gen_size);
 176   void report_ihop_statistics();
 177 
 178   G1Predictions _predictor;
 179 
 180   double get_new_prediction(TruncatedSeq const* seq) const;
 181 
 182   // either equal to the number of parallel threads, if ParallelGCThreads
 183   // has been set, or 1 otherwise
 184   int _parallel_gc_threads;
 185 
 186   // The number of GC threads currently active.
 187   uintx _no_of_gc_threads;
 188 
 189   G1MMUTracker* _mmu_tracker;
 190 
 191   void initialize_alignments();
 192   void initialize_flags();
 193 
 194   CollectionSetChooser* _collectionSetChooser;
 195 
 196   double _full_collection_start_sec;
 197   uint   _cur_collection_pause_used_regions_at_start;


 266   size_t _recorded_rs_lengths;
 267   size_t _max_rs_lengths;
 268 
 269   size_t _rs_lengths_prediction;
 270 
 271 #ifndef PRODUCT
 272   bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group);
 273 #endif // PRODUCT
 274 
 275   void adjust_concurrent_refinement(double update_rs_time,
 276                                     double update_rs_processed_buffers,
 277                                     double goal_ms);
 278 
 279   uintx no_of_gc_threads() { return _no_of_gc_threads; }
 280   void set_no_of_gc_threads(uintx v) { _no_of_gc_threads = v; }
 281 
 282   double _pause_time_target_ms;
 283 
 284   size_t _pending_cards;
 285 
 286   // The amount of allocated bytes in old gen during the last mutator and the following
 287   // young GC phase.
 288   size_t _last_old_allocated_bytes;
 289 
 290   G1InitialMarkToMixedTimeTracker _initial_mark_to_mixed;
 291 public:
 292   const G1Predictions& predictor() const { return _predictor; }
 293 
 294   // Add the given number of bytes to the total number of allocated bytes in the old gen.
 295   void add_last_old_allocated_bytes(size_t bytes) { _last_old_allocated_bytes += bytes; }
 296 
 297   // Accessors
 298 
 299   void set_region_eden(HeapRegion* hr, int young_index_in_cset) {
 300     hr->set_eden();
 301     hr->install_surv_rate_group(_short_lived_surv_rate_group);
 302     hr->set_young_index_in_cset(young_index_in_cset);
 303   }
 304 
 305   void set_region_survivor(HeapRegion* hr, int young_index_in_cset) {
 306     assert(hr->is_survivor(), "pre-condition");
 307     hr->install_surv_rate_group(_survivor_surv_rate_group);
 308     hr->set_young_index_in_cset(young_index_in_cset);
 309   }
 310 
 311 #ifndef PRODUCT
 312   bool verify_young_ages();
 313 #endif // PRODUCT
 314 
 315   void record_max_rs_lengths(size_t rs_lengths) {
 316     _max_rs_lengths = rs_lengths;


 476   double _inc_cset_predicted_elapsed_time_ms_diffs;
 477 
 478   // Stash a pointer to the g1 heap.
 479   G1CollectedHeap* _g1;
 480 
 481   G1GCPhaseTimes* _phase_times;
 482 
 483   // The ratio of gc time to elapsed time, computed over recent pauses.
 484   double _recent_avg_pause_time_ratio;
 485 
 486   double recent_avg_pause_time_ratio() const {
 487     return _recent_avg_pause_time_ratio;
 488   }
 489 
 490   // This set of variables tracks the collector efficiency, in order to
 491   // determine whether we should initiate a new marking.
 492   double _cur_mark_stop_world_time_ms;
 493   double _mark_remark_start_sec;
 494   double _mark_cleanup_start_sec;
 495 
 496   // Updates the internal young list maximum and target lengths. Returns the
 497   // unbounded young list target length.
 498   uint update_young_list_max_and_target_length();
 499   uint update_young_list_max_and_target_length(size_t rs_lengths);
 500 
 501   // Update the young list target length either by setting it to the
 502   // desired fixed value or by calculating it using G1's pause
 503   // prediction model. If no rs_lengths parameter is passed, predict
 504   // the RS lengths using the prediction model, otherwise use the
 505   // given rs_lengths as the prediction.
 506   // Returns the unbounded young list target length.
 507   uint update_young_list_target_length(size_t rs_lengths);
 508 
 509   // Calculate and return the minimum desired young list target
 510   // length. This is the minimum desired young list length according
 511   // to the user's inputs.
 512   uint calculate_young_list_desired_min_length(uint base_min_length) const;
 513 
 514   // Calculate and return the maximum desired young list target
 515   // length. This is the maximum desired young list length according
 516   // to the user's inputs.
 517   uint calculate_young_list_desired_max_length() const;
 518 
 519   // Calculate and return the maximum young list target length that
 520   // can fit into the pause time goal. The parameters are: rs_lengths
 521   // represent the prediction of how large the young RSet lengths will
 522   // be, base_min_length is the already existing number of regions in
 523   // the young list, min_length and max_length are the desired min and
 524   // max young list length according to the user's inputs.
 525   uint calculate_young_list_target_length(size_t rs_lengths,
 526                                           uint base_min_length,
 527                                           uint desired_min_length,
 528                                           uint desired_max_length) const;
 529 
 530   // Result of the bounded_young_list_target_length() method, containing both the
 531   // bounded as well as the unbounded young list target lengths in this order.
 532   typedef Pair<uint, uint, StackObj> YoungTargetLengths;
 533   YoungTargetLengths young_list_target_lengths(size_t rs_lengths) const;
 534 
 535   void update_rs_lengths_prediction();
 536   void update_rs_lengths_prediction(size_t prediction);
 537 
 538   // Calculate and return chunk size (in number of regions) for parallel
 539   // concurrent mark cleanup.
 540   uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
 541 
 542   // Check whether a given young length (young_length) fits into the
 543   // given target pause time and whether the prediction for the amount
 544   // of objects to be copied for the given length will fit into the
 545   // given free space (expressed by base_free_regions).  It is used by
 546   // calculate_young_list_target_length().
 547   bool predict_will_fit(uint young_length, double base_time_ms,
 548                         uint base_free_regions, double target_pause_time_ms) const;
 549 
 550   // Calculate the minimum number of old regions we'll add to the CSet
 551   // during a mixed GC.
 552   uint calc_min_old_cset_length() const;
 553 
 554   // Calculate the maximum number of old regions we'll add to the CSet
 555   // during a mixed GC.
 556   uint calc_max_old_cset_length() const;
 557 
 558   // Returns the given amount of uncollected reclaimable space
 559   // as a percentage of the current heap capacity.
 560   double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
 561 
 562   // Sets up marking if proper conditions are met.
 563   void maybe_start_marking();
 564 
 565   // The kind of STW pause.
 566   enum PauseKind {
 567     FullGC,
 568     YoungOnlyGC,
 569     MixedGC,
 570     LastYoungGC,
 571     InitialMarkGC,
 572     Cleanup,
 573     Remark
 574   };
 575 
 576   // Calculate PauseKind from internal state.
 577   PauseKind young_gc_pause_kind() const;
 578   // Record the given STW pause with the given start and end times (in s).
 579   void record_pause(PauseKind kind, double start, double end);
 580   // Indicate that we aborted marking before doing any mixed GCs.
 581   void abort_time_to_mixed_tracking();
 582 public:
 583 
 584   G1CollectorPolicy();
 585 
 586   virtual ~G1CollectorPolicy();
 587 
 588   virtual G1CollectorPolicy* as_g1_policy() { return this; }
 589 
 590   G1CollectorState* collector_state() const;
 591 
 592   G1GCPhaseTimes* phase_times() const { return _phase_times; }
 593 
 594   // Check the current value of the young list RSet lengths and
 595   // compare it against the last prediction. If the current value is
 596   // higher, recalculate the young list target length prediction.
 597   void revise_young_list_target_length_if_necessary();
 598 
 599   // This should be called after the heap is resized.
 600   void record_new_heap_size(uint new_number_of_regions);
 601 
 602   void init();
 603 
 604   virtual void note_gc_start(uint num_active_workers);
 605 
 606   // Create jstat counters for the policy.


< prev index next >