< prev index next >

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

Print this page
rev 9277 : imported patch 8140597-forcing-initial-mark-causes-abort-mixed-collections
rev 9279 : imported patch 8138740-start-initial-mark-right-after-mixed-gc-if-needed
rev 9282 : dihop-changes


  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   G1Predictions& predictor() { 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.




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


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


 264   size_t _recorded_rs_lengths;
 265   size_t _max_rs_lengths;
 266 
 267   size_t _rs_lengths_prediction;
 268 
 269 #ifndef PRODUCT
 270   bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group);
 271 #endif // PRODUCT
 272 
 273   void adjust_concurrent_refinement(double update_rs_time,
 274                                     double update_rs_processed_buffers,
 275                                     double goal_ms);
 276 
 277   uintx no_of_gc_threads() { return _no_of_gc_threads; }
 278   void set_no_of_gc_threads(uintx v) { _no_of_gc_threads = v; }
 279 
 280   double _pause_time_target_ms;
 281 
 282   size_t _pending_cards;
 283 
 284   // The amount of allocated bytes in old gen during the last mutator and the following
 285   // young GC phase.
 286   size_t _last_old_allocated_bytes;
 287 
 288   // Used to track time from the end of initial mark to the first mixed GC.
 289   class InitialMarkToMixedTimeTracker {
 290    private:
 291     bool _active;
 292     double _initial_mark_end_time;
 293     double _mixed_start_time;
 294     double _total_pause_time;
 295 
 296     double wall_time() const {
 297       return _mixed_start_time - _initial_mark_end_time;
 298     }
 299    public:
 300     InitialMarkToMixedTimeTracker() { reset(); }
 301 
 302     void record_initial_mark_end(double end_time) {
 303       assert(!_active, "Initial mark out of order.");
 304       _initial_mark_end_time = end_time;
 305       _active = true;
 306     }
 307 
 308     void record_mixed_gc_start(double start_time) {
 309       if (_active) {
 310         _mixed_start_time = start_time;
 311         _active = false;
 312       }
 313     }
 314 
 315     double last_marking_time() {
 316       assert(has_result(), "Do not have all measurements yet.");
 317       double result = (_mixed_start_time - _initial_mark_end_time) - _total_pause_time;
 318       reset();
 319       return result;
 320     }
 321 
 322     void reset() {
 323       _active = false;
 324       _total_pause_time = 0.0;
 325       _initial_mark_end_time = -1.0;
 326       _mixed_start_time = -1.0;
 327     }
 328 
 329     void add_pause(double time) {
 330       if (_active) {
 331         _total_pause_time += time;
 332       }
 333     }
 334 
 335     bool has_result() const { return _mixed_start_time > 0.0 && _initial_mark_end_time > 0.0; }
 336   };
 337 
 338   InitialMarkToMixedTimeTracker _initial_mark_to_mixed;
 339 public:
 340   G1Predictions& predictor() { return _predictor; }
 341 
 342   // Add the given number of bytes to the total number of allocated bytes in the old gen.
 343   void add_last_old_allocated_bytes(size_t bytes) { _last_old_allocated_bytes += bytes; }
 344 
 345   // Accessors
 346 
 347   void set_region_eden(HeapRegion* hr, int young_index_in_cset) {
 348     hr->set_eden();
 349     hr->install_surv_rate_group(_short_lived_surv_rate_group);
 350     hr->set_young_index_in_cset(young_index_in_cset);
 351   }
 352 
 353   void set_region_survivor(HeapRegion* hr, int young_index_in_cset) {
 354     assert(hr->is_survivor(), "pre-condition");
 355     hr->install_surv_rate_group(_survivor_surv_rate_group);
 356     hr->set_young_index_in_cset(young_index_in_cset);
 357   }
 358 
 359 #ifndef PRODUCT
 360   bool verify_young_ages();
 361 #endif // PRODUCT
 362 
 363   void record_max_rs_lengths(size_t rs_lengths) {
 364     _max_rs_lengths = rs_lengths;


 524   double _inc_cset_predicted_elapsed_time_ms_diffs;
 525 
 526   // Stash a pointer to the g1 heap.
 527   G1CollectedHeap* _g1;
 528 
 529   G1GCPhaseTimes* _phase_times;
 530 
 531   // The ratio of gc time to elapsed time, computed over recent pauses.
 532   double _recent_avg_pause_time_ratio;
 533 
 534   double recent_avg_pause_time_ratio() const {
 535     return _recent_avg_pause_time_ratio;
 536   }
 537 
 538   // This set of variables tracks the collector efficiency, in order to
 539   // determine whether we should initiate a new marking.
 540   double _cur_mark_stop_world_time_ms;
 541   double _mark_remark_start_sec;
 542   double _mark_cleanup_start_sec;
 543 
 544   void update_young_list_max_and_target_length(size_t* unbounded_target_length = NULL);
 545   void update_young_list_max_and_target_length(size_t rs_lengths, size_t* unbounded_target_length = NULL);
 546 
 547   // Update the young list target length either by setting it to the
 548   // desired fixed value or by calculating it using G1's pause
 549   // prediction model. If no rs_lengths parameter is passed, predict
 550   // the RS lengths using the prediction model, otherwise use the
 551   // given rs_lengths as the prediction.
 552   void update_young_list_target_length();
 553   void update_young_list_target_length(size_t rs_lengths, size_t* unbounded_target_length = NULL);
 554 
 555   // Calculate and return the minimum desired young list target
 556   // length. This is the minimum desired young list length according
 557   // to the user's inputs.
 558   uint calculate_young_list_desired_min_length(uint base_min_length) const;
 559 
 560   // Calculate and return the maximum desired young list target
 561   // length. This is the maximum desired young list length according
 562   // to the user's inputs.
 563   uint calculate_young_list_desired_max_length() const;
 564 
 565   // Calculate and return the maximum young list target length that
 566   // can fit into the pause time goal. The parameters are: rs_lengths
 567   // represent the prediction of how large the young RSet lengths will
 568   // be, base_min_length is the already existing number of regions in
 569   // the young list, min_length and max_length are the desired min and
 570   // max young list length according to the user's inputs.
 571   uint calculate_young_list_target_length(size_t rs_lengths,
 572                                           uint base_min_length,
 573                                           uint desired_min_length,
 574                                           uint desired_max_length) const;
 575 
 576   uint bounded_young_list_target_length(size_t rs_lengths, size_t* unbounded_target_length = NULL) const;
 577 
 578   void update_rs_lengths_prediction();
 579   void update_rs_lengths_prediction(size_t prediction);
 580 
 581   // Calculate and return chunk size (in number of regions) for parallel
 582   // concurrent mark cleanup.
 583   uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
 584 
 585   // Check whether a given young length (young_length) fits into the
 586   // given target pause time and whether the prediction for the amount
 587   // of objects to be copied for the given length will fit into the
 588   // given free space (expressed by base_free_regions).  It is used by
 589   // calculate_young_list_target_length().
 590   bool predict_will_fit(uint young_length, double base_time_ms,
 591                         uint base_free_regions, double target_pause_time_ms) const;
 592 
 593   // Calculate the minimum number of old regions we'll add to the CSet
 594   // during a mixed GC.
 595   uint calc_min_old_cset_length() const;
 596 
 597   // Calculate the maximum number of old regions we'll add to the CSet
 598   // during a mixed GC.
 599   uint calc_max_old_cset_length() const;
 600 
 601   // Returns the given amount of uncollected reclaimable space
 602   // as a percentage of the current heap capacity.
 603   double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
 604 
 605   // Sets up marking if proper conditions are met.
 606   void maybe_start_marking();
 607 
 608   // The kind of STW pause.
 609   enum PauseKind {
 610     FullGC,
 611     YoungOnlyGC,
 612     MixedGC,
 613     LastYoungGC,
 614     InitialMarkGC,
 615     Cleanup,
 616     Remark
 617   };
 618 
 619   // Calculate PauseKind from internal state.
 620   PauseKind young_gc_pause_kind() const;
 621   // Record the given STW pause with the given start and end times (in s).
 622   void record_pause(PauseKind kind, double start, double end);
 623   // Indicate that we aborted marking before doing any mixed GCs.
 624   void abort_time_to_mixed_tracking();
 625 public:
 626 
 627   G1CollectorPolicy();
 628 
 629   virtual ~G1CollectorPolicy();
 630 
 631   virtual G1CollectorPolicy* as_g1_policy() { return this; }
 632 
 633   G1CollectorState* collector_state() const;
 634 
 635   G1GCPhaseTimes* phase_times() const { return _phase_times; }
 636 
 637   // Check the current value of the young list RSet lengths and
 638   // compare it against the last prediction. If the current value is
 639   // higher, recalculate the young list target length prediction.
 640   void revise_young_list_target_length_if_necessary();
 641 
 642   // This should be called after the heap is resized.
 643   void record_new_heap_size(uint new_number_of_regions);
 644 
 645   void init();
 646 
 647   virtual void note_gc_start(uint num_active_workers);
 648 
 649   // Create jstat counters for the policy.


< prev index next >