hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp
changeset 11397 7dc5c8f572b0
parent 11395 33260c27554b
child 11455 a6ab3d8b9a4c
equal deleted inserted replaced
11396:917d8673b5ef 11397:7dc5c8f572b0
    81                public MainBodySummary {
    81                public MainBodySummary {
    82 public:
    82 public:
    83   virtual MainBodySummary*    main_body_summary()    { return this; }
    83   virtual MainBodySummary*    main_body_summary()    { return this; }
    84 };
    84 };
    85 
    85 
       
    86 // There are three command line options related to the young gen size:
       
    87 // NewSize, MaxNewSize and NewRatio (There is also -Xmn, but that is
       
    88 // just a short form for NewSize==MaxNewSize). G1 will use its internal
       
    89 // heuristics to calculate the actual young gen size, so these options
       
    90 // basically only limit the range within which G1 can pick a young gen
       
    91 // size. Also, these are general options taking byte sizes. G1 will
       
    92 // internally work with a number of regions instead. So, some rounding
       
    93 // will occur.
       
    94 //
       
    95 // If nothing related to the the young gen size is set on the command
       
    96 // line we should allow the young gen to be between
       
    97 // G1DefaultMinNewGenPercent and G1DefaultMaxNewGenPercent of the
       
    98 // heap size. This means that every time the heap size changes the
       
    99 // limits for the young gen size will be updated.
       
   100 //
       
   101 // If only -XX:NewSize is set we should use the specified value as the
       
   102 // minimum size for young gen. Still using G1DefaultMaxNewGenPercent
       
   103 // of the heap as maximum.
       
   104 //
       
   105 // If only -XX:MaxNewSize is set we should use the specified value as the
       
   106 // maximum size for young gen. Still using G1DefaultMinNewGenPercent
       
   107 // of the heap as minimum.
       
   108 //
       
   109 // If -XX:NewSize and -XX:MaxNewSize are both specified we use these values.
       
   110 // No updates when the heap size changes. There is a special case when
       
   111 // NewSize==MaxNewSize. This is interpreted as "fixed" and will use a
       
   112 // different heuristic for calculating the collection set when we do mixed
       
   113 // collection.
       
   114 //
       
   115 // If only -XX:NewRatio is set we should use the specified ratio of the heap
       
   116 // as both min and max. This will be interpreted as "fixed" just like the
       
   117 // NewSize==MaxNewSize case above. But we will update the min and max
       
   118 // everytime the heap size changes.
       
   119 //
       
   120 // NewSize and MaxNewSize override NewRatio. So, NewRatio is ignored if it is
       
   121 // combined with either NewSize or MaxNewSize. (A warning message is printed.)
       
   122 class G1YoungGenSizer : public CHeapObj {
       
   123 private:
       
   124   enum SizerKind {
       
   125     SizerDefaults,
       
   126     SizerNewSizeOnly,
       
   127     SizerMaxNewSizeOnly,
       
   128     SizerMaxAndNewSize,
       
   129     SizerNewRatio
       
   130   };
       
   131   SizerKind _sizer_kind;
       
   132   size_t _min_desired_young_length;
       
   133   size_t _max_desired_young_length;
       
   134   bool _adaptive_size;
       
   135   size_t calculate_default_min_length(size_t new_number_of_heap_regions);
       
   136   size_t calculate_default_max_length(size_t new_number_of_heap_regions);
       
   137 
       
   138 public:
       
   139   G1YoungGenSizer();
       
   140   void heap_size_changed(size_t new_number_of_heap_regions);
       
   141   size_t min_desired_young_length() {
       
   142     return _min_desired_young_length;
       
   143   }
       
   144   size_t max_desired_young_length() {
       
   145     return _max_desired_young_length;
       
   146   }
       
   147   bool adaptive_young_list_length() {
       
   148     return _adaptive_size;
       
   149   }
       
   150 };
       
   151 
    86 class G1CollectorPolicy: public CollectorPolicy {
   152 class G1CollectorPolicy: public CollectorPolicy {
    87 private:
   153 private:
    88   // either equal to the number of parallel threads, if ParallelGCThreads
   154   // either equal to the number of parallel threads, if ParallelGCThreads
    89   // has been set, or 1 otherwise
   155   // has been set, or 1 otherwise
    90   int _parallel_gc_threads;
   156   int _parallel_gc_threads;
   165   double* _par_last_gc_worker_other_times_ms;
   231   double* _par_last_gc_worker_other_times_ms;
   166 
   232 
   167   // indicates whether we are in young or mixed GC mode
   233   // indicates whether we are in young or mixed GC mode
   168   bool _gcs_are_young;
   234   bool _gcs_are_young;
   169 
   235 
   170   // if true, then it tries to dynamically adjust the length of the
       
   171   // young list
       
   172   bool _adaptive_young_list_length;
       
   173   size_t _young_list_target_length;
   236   size_t _young_list_target_length;
   174   size_t _young_list_fixed_length;
   237   size_t _young_list_fixed_length;
   175   size_t _prev_eden_capacity; // used for logging
   238   size_t _prev_eden_capacity; // used for logging
   176 
   239 
   177   // The max number of regions we can extend the eden by while the GC
   240   // The max number of regions we can extend the eden by while the GC
   225 
   288 
   226   TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
   289   TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
   227 
   290 
   228   TruncatedSeq* _young_gc_eff_seq;
   291   TruncatedSeq* _young_gc_eff_seq;
   229 
   292 
   230   bool   _using_new_ratio_calculations;
   293   G1YoungGenSizer* _young_gen_sizer;
   231   size_t _min_desired_young_length; // as set on the command line or default calculations
       
   232   size_t _max_desired_young_length; // as set on the command line or default calculations
       
   233 
   294 
   234   size_t _eden_cset_region_length;
   295   size_t _eden_cset_region_length;
   235   size_t _survivor_cset_region_length;
   296   size_t _survivor_cset_region_length;
   236   size_t _old_cset_region_length;
   297   size_t _old_cset_region_length;
   237 
   298 
   693                         size_t base_free_regions, double target_pause_time_ms);
   754                         size_t base_free_regions, double target_pause_time_ms);
   694 
   755 
   695   // Count the number of bytes used in the CS.
   756   // Count the number of bytes used in the CS.
   696   void count_CS_bytes_used();
   757   void count_CS_bytes_used();
   697 
   758 
   698   void update_young_list_size_using_newratio(size_t number_of_heap_regions);
       
   699 
       
   700 public:
   759 public:
   701 
   760 
   702   G1CollectorPolicy();
   761   G1CollectorPolicy();
   703 
   762 
   704   virtual G1CollectorPolicy* as_g1_policy() { return this; }
   763   virtual G1CollectorPolicy* as_g1_policy() { return this; }
   720     return _all_pause_times_ms->num() + 1;
   779     return _all_pause_times_ms->num() + 1;
   721   }
   780   }
   722 
   781 
   723   // This should be called after the heap is resized.
   782   // This should be called after the heap is resized.
   724   void record_new_heap_size(size_t new_number_of_regions);
   783   void record_new_heap_size(size_t new_number_of_regions);
   725 
       
   726 public:
       
   727 
   784 
   728   void init();
   785   void init();
   729 
   786 
   730   // Create jstat counters for the policy.
   787   // Create jstat counters for the policy.
   731   virtual void initialize_gc_policy_counters();
   788   virtual void initialize_gc_policy_counters();
  1012   void set_gcs_are_young(bool gcs_are_young) {
  1069   void set_gcs_are_young(bool gcs_are_young) {
  1013     _gcs_are_young = gcs_are_young;
  1070     _gcs_are_young = gcs_are_young;
  1014   }
  1071   }
  1015 
  1072 
  1016   bool adaptive_young_list_length() {
  1073   bool adaptive_young_list_length() {
  1017     return _adaptive_young_list_length;
  1074     return _young_gen_sizer->adaptive_young_list_length();
  1018   }
       
  1019   void set_adaptive_young_list_length(bool adaptive_young_list_length) {
       
  1020     _adaptive_young_list_length = adaptive_young_list_length;
       
  1021   }
  1075   }
  1022 
  1076 
  1023   inline double get_gc_eff_factor() {
  1077   inline double get_gc_eff_factor() {
  1024     double ratio = _known_garbage_ratio;
  1078     double ratio = _known_garbage_ratio;
  1025 
  1079