src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp

changeset 435
a61af66fc99e
child 1822
0bfd3fb24150
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,384 @@
     1.4 +/*
     1.5 + * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// This class keeps statistical information and computes the
    1.29 +// optimal free space for both the young and old generation
    1.30 +// based on current application characteristics (based on gc cost
    1.31 +// and application footprint).
    1.32 +//
    1.33 +// It also computes an optimal tenuring threshold between the young
    1.34 +// and old generations, so as to equalize the cost of collections
    1.35 +// of those generations, as well as optimial survivor space sizes
    1.36 +// for the young generation.
    1.37 +//
    1.38 +// While this class is specifically intended for a generational system
    1.39 +// consisting of a young gen (containing an Eden and two semi-spaces)
    1.40 +// and a tenured gen, as well as a perm gen for reflective data, it
    1.41 +// makes NO references to specific generations.
    1.42 +//
    1.43 +// 05/02/2003 Update
    1.44 +// The 1.5 policy makes use of data gathered for the costs of GC on
    1.45 +// specific generations.  That data does reference specific
    1.46 +// generation.  Also diagnostics specific to generations have
    1.47 +// been added.
    1.48 +
    1.49 +// Forward decls
    1.50 +class elapsedTimer;
    1.51 +
    1.52 +class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
    1.53 + friend class PSGCAdaptivePolicyCounters;
    1.54 + private:
    1.55 +  // These values are used to record decisions made during the
    1.56 +  // policy.  For example, if the young generation was decreased
    1.57 +  // to decrease the GC cost of minor collections the value
    1.58 +  // decrease_young_gen_for_throughput_true is used.
    1.59 +
    1.60 +  // Last calculated sizes, in bytes, and aligned
    1.61 +  // NEEDS_CLEANUP should use sizes.hpp,  but it works in ints, not size_t's
    1.62 +
    1.63 +  // Time statistics
    1.64 +  AdaptivePaddedAverage* _avg_major_pause;
    1.65 +
    1.66 +  // Footprint statistics
    1.67 +  AdaptiveWeightedAverage* _avg_base_footprint;
    1.68 +
    1.69 +  // Statistical data gathered for GC
    1.70 +  GCStats _gc_stats;
    1.71 +
    1.72 +  size_t _survivor_size_limit;   // Limit in bytes of survivor size
    1.73 +  const double _collection_cost_margin_fraction;
    1.74 +
    1.75 +  // Variable for estimating the major and minor pause times.
    1.76 +  // These variables represent linear least-squares fits of
    1.77 +  // the data.
    1.78 +  //   major pause time vs. old gen size
    1.79 +  LinearLeastSquareFit* _major_pause_old_estimator;
    1.80 +  //   major pause time vs. young gen size
    1.81 +  LinearLeastSquareFit* _major_pause_young_estimator;
    1.82 +
    1.83 +
    1.84 +  // These record the most recent collection times.  They
    1.85 +  // are available as an alternative to using the averages
    1.86 +  // for making ergonomic decisions.
    1.87 +  double _latest_major_mutator_interval_seconds;
    1.88 +
    1.89 +  const size_t _intra_generation_alignment; // alignment for eden, survivors
    1.90 +
    1.91 +  const double _gc_minor_pause_goal_sec;    // goal for maximum minor gc pause
    1.92 +
    1.93 +  // The amount of live data in the heap at the last full GC, used
    1.94 +  // as a baseline to help us determine when we need to perform the
    1.95 +  // next full GC.
    1.96 +  size_t _live_at_last_full_gc;
    1.97 +
    1.98 +  // decrease/increase the old generation for minor pause time
    1.99 +  int _change_old_gen_for_min_pauses;
   1.100 +
   1.101 +  // increase/decrease the young generation for major pause time
   1.102 +  int _change_young_gen_for_maj_pauses;
   1.103 +
   1.104 +
   1.105 +  // Flag indicating that the adaptive policy is ready to use
   1.106 +  bool _old_gen_policy_is_ready;
   1.107 +
   1.108 +  // Changing the generation sizing depends on the data that is
   1.109 +  // gathered about the effects of changes on the pause times and
   1.110 +  // throughput.  These variable count the number of data points
   1.111 +  // gathered.  The policy may use these counters as a threshhold
   1.112 +  // for reliable data.
   1.113 +  julong _young_gen_change_for_major_pause_count;
   1.114 +
   1.115 +  // To facilitate faster growth at start up, supplement the normal
   1.116 +  // growth percentage for the young gen eden and the
   1.117 +  // old gen space for promotion with these value which decay
   1.118 +  // with increasing collections.
   1.119 +  uint _young_gen_size_increment_supplement;
   1.120 +  uint _old_gen_size_increment_supplement;
   1.121 +
   1.122 +  // The number of bytes absorbed from eden into the old gen by moving the
   1.123 +  // boundary over live data.
   1.124 +  size_t _bytes_absorbed_from_eden;
   1.125 +
   1.126 + private:
   1.127 +
   1.128 +  // Accessors
   1.129 +  AdaptivePaddedAverage* avg_major_pause() const { return _avg_major_pause; }
   1.130 +  double gc_minor_pause_goal_sec() const { return _gc_minor_pause_goal_sec; }
   1.131 +
   1.132 +  // Change the young generation size to achieve a minor GC pause time goal
   1.133 +  void adjust_for_minor_pause_time(bool is_full_gc,
   1.134 +                                   size_t* desired_promo_size_ptr,
   1.135 +                                   size_t* desired_eden_size_ptr);
   1.136 +  // Change the generation sizes to achieve a GC pause time goal
   1.137 +  // Returned sizes are not necessarily aligned.
   1.138 +  void adjust_for_pause_time(bool is_full_gc,
   1.139 +                         size_t* desired_promo_size_ptr,
   1.140 +                         size_t* desired_eden_size_ptr);
   1.141 +  // Change the generation sizes to achieve an application throughput goal
   1.142 +  // Returned sizes are not necessarily aligned.
   1.143 +  void adjust_for_throughput(bool is_full_gc,
   1.144 +                             size_t* desired_promo_size_ptr,
   1.145 +                             size_t* desired_eden_size_ptr);
   1.146 +  // Change the generation sizes to achieve minimum footprint
   1.147 +  // Returned sizes are not aligned.
   1.148 +  size_t adjust_promo_for_footprint(size_t desired_promo_size,
   1.149 +                                    size_t desired_total);
   1.150 +  size_t adjust_eden_for_footprint(size_t desired_promo_size,
   1.151 +                                   size_t desired_total);
   1.152 +
   1.153 +  // Size in bytes for an increment or decrement of eden.
   1.154 +  virtual size_t eden_increment(size_t cur_eden, uint percent_change);
   1.155 +  virtual size_t eden_decrement(size_t cur_eden);
   1.156 +  size_t eden_decrement_aligned_down(size_t cur_eden);
   1.157 +  size_t eden_increment_with_supplement_aligned_up(size_t cur_eden);
   1.158 +
   1.159 +  // Size in bytes for an increment or decrement of the promotion area
   1.160 +  virtual size_t promo_increment(size_t cur_promo, uint percent_change);
   1.161 +  virtual size_t promo_decrement(size_t cur_promo);
   1.162 +  size_t promo_decrement_aligned_down(size_t cur_promo);
   1.163 +  size_t promo_increment_with_supplement_aligned_up(size_t cur_promo);
   1.164 +
   1.165 +  // Decay the supplemental growth additive.
   1.166 +  void decay_supplemental_growth(bool is_full_gc);
   1.167 +
   1.168 +  // Returns a change that has been scaled down.  Result
   1.169 +  // is not aligned.  (If useful, move to some shared
   1.170 +  // location.)
   1.171 +  size_t scale_down(size_t change, double part, double total);
   1.172 +
   1.173 + protected:
   1.174 +  // Time accessors
   1.175 +
   1.176 +  // Footprint accessors
   1.177 +  size_t live_space() const {
   1.178 +    return (size_t)(avg_base_footprint()->average() +
   1.179 +                    avg_young_live()->average() +
   1.180 +                    avg_old_live()->average());
   1.181 +  }
   1.182 +  size_t free_space() const {
   1.183 +    return _eden_size + _promo_size;
   1.184 +  }
   1.185 +
   1.186 +  void set_promo_size(size_t new_size) {
   1.187 +    _promo_size = new_size;
   1.188 +  }
   1.189 +  void set_survivor_size(size_t new_size) {
   1.190 +    _survivor_size = new_size;
   1.191 +  }
   1.192 +
   1.193 +  // Update estimators
   1.194 +  void update_minor_pause_old_estimator(double minor_pause_in_ms);
   1.195 +
   1.196 +  virtual GCPolicyKind kind() const { return _gc_ps_adaptive_size_policy; }
   1.197 +
   1.198 + public:
   1.199 +  // Use by ASPSYoungGen and ASPSOldGen to limit boundary moving.
   1.200 +  size_t eden_increment_aligned_up(size_t cur_eden);
   1.201 +  size_t eden_increment_aligned_down(size_t cur_eden);
   1.202 +  size_t promo_increment_aligned_up(size_t cur_promo);
   1.203 +  size_t promo_increment_aligned_down(size_t cur_promo);
   1.204 +
   1.205 +  virtual size_t eden_increment(size_t cur_eden);
   1.206 +  virtual size_t promo_increment(size_t cur_promo);
   1.207 +
   1.208 +  // Accessors for use by performance counters
   1.209 +  AdaptivePaddedNoZeroDevAverage*  avg_promoted() const {
   1.210 +    return _gc_stats.avg_promoted();
   1.211 +  }
   1.212 +  AdaptiveWeightedAverage* avg_base_footprint() const {
   1.213 +    return _avg_base_footprint;
   1.214 +  }
   1.215 +
   1.216 +  // Input arguments are initial free space sizes for young and old
   1.217 +  // generations, the initial survivor space size, the
   1.218 +  // alignment values and the pause & throughput goals.
   1.219 +  //
   1.220 +  // NEEDS_CLEANUP this is a singleton object
   1.221 +  PSAdaptiveSizePolicy(size_t init_eden_size,
   1.222 +                       size_t init_promo_size,
   1.223 +                       size_t init_survivor_size,
   1.224 +                       size_t intra_generation_alignment,
   1.225 +                       double gc_pause_goal_sec,
   1.226 +                       double gc_minor_pause_goal_sec,
   1.227 +                       uint gc_time_ratio);
   1.228 +
   1.229 +  // Methods indicating events of interest to the adaptive size policy,
   1.230 +  // called by GC algorithms. It is the responsibility of users of this
   1.231 +  // policy to call these methods at the correct times!
   1.232 +  void major_collection_begin();
   1.233 +  void major_collection_end(size_t amount_live, GCCause::Cause gc_cause);
   1.234 +
   1.235 +  //
   1.236 +  void tenured_allocation(size_t size) {
   1.237 +    _avg_pretenured->sample(size);
   1.238 +  }
   1.239 +
   1.240 +  // Accessors
   1.241 +  // NEEDS_CLEANUP   should use sizes.hpp
   1.242 +
   1.243 +  size_t calculated_old_free_size_in_bytes() const {
   1.244 +    return (size_t)(_promo_size + avg_promoted()->padded_average());
   1.245 +  }
   1.246 +
   1.247 +  size_t average_old_live_in_bytes() const {
   1.248 +    return (size_t) avg_old_live()->average();
   1.249 +  }
   1.250 +
   1.251 +  size_t average_promoted_in_bytes() const {
   1.252 +    return (size_t)avg_promoted()->average();
   1.253 +  }
   1.254 +
   1.255 +  size_t padded_average_promoted_in_bytes() const {
   1.256 +    return (size_t)avg_promoted()->padded_average();
   1.257 +  }
   1.258 +
   1.259 +  int change_young_gen_for_maj_pauses() {
   1.260 +    return _change_young_gen_for_maj_pauses;
   1.261 +  }
   1.262 +  void set_change_young_gen_for_maj_pauses(int v) {
   1.263 +    _change_young_gen_for_maj_pauses = v;
   1.264 +  }
   1.265 +
   1.266 +  int change_old_gen_for_min_pauses() {
   1.267 +    return _change_old_gen_for_min_pauses;
   1.268 +  }
   1.269 +  void set_change_old_gen_for_min_pauses(int v) {
   1.270 +    _change_old_gen_for_min_pauses = v;
   1.271 +  }
   1.272 +
   1.273 +  // Return true if the old generation size was changed
   1.274 +  // to try to reach a pause time goal.
   1.275 +  bool old_gen_changed_for_pauses() {
   1.276 +    bool result = _change_old_gen_for_maj_pauses != 0 ||
   1.277 +                  _change_old_gen_for_min_pauses != 0;
   1.278 +    return result;
   1.279 +  }
   1.280 +
   1.281 +  // Return true if the young generation size was changed
   1.282 +  // to try to reach a pause time goal.
   1.283 +  bool young_gen_changed_for_pauses() {
   1.284 +    bool result = _change_young_gen_for_min_pauses != 0 ||
   1.285 +                  _change_young_gen_for_maj_pauses != 0;
   1.286 +    return result;
   1.287 +  }
   1.288 +  // end flags for pause goal
   1.289 +
   1.290 +  // Return true if the old generation size was changed
   1.291 +  // to try to reach a throughput goal.
   1.292 +  bool old_gen_changed_for_throughput() {
   1.293 +    bool result = _change_old_gen_for_throughput != 0;
   1.294 +    return result;
   1.295 +  }
   1.296 +
   1.297 +  // Return true if the young generation size was changed
   1.298 +  // to try to reach a throughput goal.
   1.299 +  bool young_gen_changed_for_throughput() {
   1.300 +    bool result = _change_young_gen_for_throughput != 0;
   1.301 +    return result;
   1.302 +  }
   1.303 +
   1.304 +  int decrease_for_footprint() { return _decrease_for_footprint; }
   1.305 +
   1.306 +
   1.307 +  // Accessors for estimators.  The slope of the linear fit is
   1.308 +  // currently all that is used for making decisions.
   1.309 +
   1.310 +  LinearLeastSquareFit* major_pause_old_estimator() {
   1.311 +    return _major_pause_old_estimator;
   1.312 +  }
   1.313 +
   1.314 +  LinearLeastSquareFit* major_pause_young_estimator() {
   1.315 +    return _major_pause_young_estimator;
   1.316 +  }
   1.317 +
   1.318 +
   1.319 +  virtual void clear_generation_free_space_flags();
   1.320 +
   1.321 +  float major_pause_old_slope() { return _major_pause_old_estimator->slope(); }
   1.322 +  float major_pause_young_slope() {
   1.323 +    return _major_pause_young_estimator->slope();
   1.324 +  }
   1.325 +  float major_collection_slope() { return _major_collection_estimator->slope();}
   1.326 +
   1.327 +  bool old_gen_policy_is_ready() { return _old_gen_policy_is_ready; }
   1.328 +
   1.329 +  // Given the amount of live data in the heap, should we
   1.330 +  // perform a Full GC?
   1.331 +  bool should_full_GC(size_t live_in_old_gen);
   1.332 +
   1.333 +  // Calculates optimial free space sizes for both the old and young
   1.334 +  // generations.  Stores results in _eden_size and _promo_size.
   1.335 +  // Takes current used space in all generations as input, as well
   1.336 +  // as an indication if a full gc has just been performed, for use
   1.337 +  // in deciding if an OOM error should be thrown.
   1.338 +  void compute_generation_free_space(size_t young_live,
   1.339 +                                     size_t eden_live,
   1.340 +                                     size_t old_live,
   1.341 +                                     size_t perm_live,
   1.342 +                                     size_t cur_eden,  // current eden in bytes
   1.343 +                                     size_t max_old_gen_size,
   1.344 +                                     size_t max_eden_size,
   1.345 +                                     bool   is_full_gc,
   1.346 +                                     GCCause::Cause gc_cause);
   1.347 +
   1.348 +  // Calculates new survivor space size;  returns a new tenuring threshold
   1.349 +  // value. Stores new survivor size in _survivor_size.
   1.350 +  int compute_survivor_space_size_and_threshold(bool   is_survivor_overflow,
   1.351 +                                                int    tenuring_threshold,
   1.352 +                                                size_t survivor_limit);
   1.353 +
   1.354 +  // Return the maximum size of a survivor space if the young generation were of
   1.355 +  // size gen_size.
   1.356 +  size_t max_survivor_size(size_t gen_size) {
   1.357 +    // Never allow the target survivor size to grow more than MinSurvivorRatio
   1.358 +    // of the young generation size.  We cannot grow into a two semi-space
   1.359 +    // system, with Eden zero sized.  Even if the survivor space grows, from()
   1.360 +    // might grow by moving the bottom boundary "down" -- so from space will
   1.361 +    // remain almost full anyway (top() will be near end(), but there will be a
   1.362 +    // large filler object at the bottom).
   1.363 +    const size_t sz = gen_size / MinSurvivorRatio;
   1.364 +    const size_t alignment = _intra_generation_alignment;
   1.365 +    return sz > alignment ? align_size_down(sz, alignment) : alignment;
   1.366 +  }
   1.367 +
   1.368 +  size_t live_at_last_full_gc() {
   1.369 +    return _live_at_last_full_gc;
   1.370 +  }
   1.371 +
   1.372 +  size_t bytes_absorbed_from_eden() const { return _bytes_absorbed_from_eden; }
   1.373 +  void   reset_bytes_absorbed_from_eden() { _bytes_absorbed_from_eden = 0; }
   1.374 +
   1.375 +  void set_bytes_absorbed_from_eden(size_t val) {
   1.376 +    _bytes_absorbed_from_eden = val;
   1.377 +  }
   1.378 +
   1.379 +  // Update averages that are always used (even
   1.380 +  // if adaptive sizing is turned off).
   1.381 +  void update_averages(bool is_survivor_overflow,
   1.382 +                       size_t survived,
   1.383 +                       size_t promoted);
   1.384 +
   1.385 +  // Printing support
   1.386 +  virtual bool print_adaptive_size_policy_on(outputStream* st) const;
   1.387 +};

mercurial