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

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 435
a61af66fc99e
child 1822
0bfd3fb24150
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

duke@435 1 /*
duke@435 2 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // This class keeps statistical information and computes the
duke@435 26 // optimal free space for both the young and old generation
duke@435 27 // based on current application characteristics (based on gc cost
duke@435 28 // and application footprint).
duke@435 29 //
duke@435 30 // It also computes an optimal tenuring threshold between the young
duke@435 31 // and old generations, so as to equalize the cost of collections
duke@435 32 // of those generations, as well as optimial survivor space sizes
duke@435 33 // for the young generation.
duke@435 34 //
duke@435 35 // While this class is specifically intended for a generational system
duke@435 36 // consisting of a young gen (containing an Eden and two semi-spaces)
duke@435 37 // and a tenured gen, as well as a perm gen for reflective data, it
duke@435 38 // makes NO references to specific generations.
duke@435 39 //
duke@435 40 // 05/02/2003 Update
duke@435 41 // The 1.5 policy makes use of data gathered for the costs of GC on
duke@435 42 // specific generations. That data does reference specific
duke@435 43 // generation. Also diagnostics specific to generations have
duke@435 44 // been added.
duke@435 45
duke@435 46 // Forward decls
duke@435 47 class elapsedTimer;
duke@435 48
duke@435 49 class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
duke@435 50 friend class PSGCAdaptivePolicyCounters;
duke@435 51 private:
duke@435 52 // These values are used to record decisions made during the
duke@435 53 // policy. For example, if the young generation was decreased
duke@435 54 // to decrease the GC cost of minor collections the value
duke@435 55 // decrease_young_gen_for_throughput_true is used.
duke@435 56
duke@435 57 // Last calculated sizes, in bytes, and aligned
duke@435 58 // NEEDS_CLEANUP should use sizes.hpp, but it works in ints, not size_t's
duke@435 59
duke@435 60 // Time statistics
duke@435 61 AdaptivePaddedAverage* _avg_major_pause;
duke@435 62
duke@435 63 // Footprint statistics
duke@435 64 AdaptiveWeightedAverage* _avg_base_footprint;
duke@435 65
duke@435 66 // Statistical data gathered for GC
duke@435 67 GCStats _gc_stats;
duke@435 68
duke@435 69 size_t _survivor_size_limit; // Limit in bytes of survivor size
duke@435 70 const double _collection_cost_margin_fraction;
duke@435 71
duke@435 72 // Variable for estimating the major and minor pause times.
duke@435 73 // These variables represent linear least-squares fits of
duke@435 74 // the data.
duke@435 75 // major pause time vs. old gen size
duke@435 76 LinearLeastSquareFit* _major_pause_old_estimator;
duke@435 77 // major pause time vs. young gen size
duke@435 78 LinearLeastSquareFit* _major_pause_young_estimator;
duke@435 79
duke@435 80
duke@435 81 // These record the most recent collection times. They
duke@435 82 // are available as an alternative to using the averages
duke@435 83 // for making ergonomic decisions.
duke@435 84 double _latest_major_mutator_interval_seconds;
duke@435 85
duke@435 86 const size_t _intra_generation_alignment; // alignment for eden, survivors
duke@435 87
duke@435 88 const double _gc_minor_pause_goal_sec; // goal for maximum minor gc pause
duke@435 89
duke@435 90 // The amount of live data in the heap at the last full GC, used
duke@435 91 // as a baseline to help us determine when we need to perform the
duke@435 92 // next full GC.
duke@435 93 size_t _live_at_last_full_gc;
duke@435 94
duke@435 95 // decrease/increase the old generation for minor pause time
duke@435 96 int _change_old_gen_for_min_pauses;
duke@435 97
duke@435 98 // increase/decrease the young generation for major pause time
duke@435 99 int _change_young_gen_for_maj_pauses;
duke@435 100
duke@435 101
duke@435 102 // Flag indicating that the adaptive policy is ready to use
duke@435 103 bool _old_gen_policy_is_ready;
duke@435 104
duke@435 105 // Changing the generation sizing depends on the data that is
duke@435 106 // gathered about the effects of changes on the pause times and
duke@435 107 // throughput. These variable count the number of data points
duke@435 108 // gathered. The policy may use these counters as a threshhold
duke@435 109 // for reliable data.
duke@435 110 julong _young_gen_change_for_major_pause_count;
duke@435 111
duke@435 112 // To facilitate faster growth at start up, supplement the normal
duke@435 113 // growth percentage for the young gen eden and the
duke@435 114 // old gen space for promotion with these value which decay
duke@435 115 // with increasing collections.
duke@435 116 uint _young_gen_size_increment_supplement;
duke@435 117 uint _old_gen_size_increment_supplement;
duke@435 118
duke@435 119 // The number of bytes absorbed from eden into the old gen by moving the
duke@435 120 // boundary over live data.
duke@435 121 size_t _bytes_absorbed_from_eden;
duke@435 122
duke@435 123 private:
duke@435 124
duke@435 125 // Accessors
duke@435 126 AdaptivePaddedAverage* avg_major_pause() const { return _avg_major_pause; }
duke@435 127 double gc_minor_pause_goal_sec() const { return _gc_minor_pause_goal_sec; }
duke@435 128
duke@435 129 // Change the young generation size to achieve a minor GC pause time goal
duke@435 130 void adjust_for_minor_pause_time(bool is_full_gc,
duke@435 131 size_t* desired_promo_size_ptr,
duke@435 132 size_t* desired_eden_size_ptr);
duke@435 133 // Change the generation sizes to achieve a GC pause time goal
duke@435 134 // Returned sizes are not necessarily aligned.
duke@435 135 void adjust_for_pause_time(bool is_full_gc,
duke@435 136 size_t* desired_promo_size_ptr,
duke@435 137 size_t* desired_eden_size_ptr);
duke@435 138 // Change the generation sizes to achieve an application throughput goal
duke@435 139 // Returned sizes are not necessarily aligned.
duke@435 140 void adjust_for_throughput(bool is_full_gc,
duke@435 141 size_t* desired_promo_size_ptr,
duke@435 142 size_t* desired_eden_size_ptr);
duke@435 143 // Change the generation sizes to achieve minimum footprint
duke@435 144 // Returned sizes are not aligned.
duke@435 145 size_t adjust_promo_for_footprint(size_t desired_promo_size,
duke@435 146 size_t desired_total);
duke@435 147 size_t adjust_eden_for_footprint(size_t desired_promo_size,
duke@435 148 size_t desired_total);
duke@435 149
duke@435 150 // Size in bytes for an increment or decrement of eden.
duke@435 151 virtual size_t eden_increment(size_t cur_eden, uint percent_change);
duke@435 152 virtual size_t eden_decrement(size_t cur_eden);
duke@435 153 size_t eden_decrement_aligned_down(size_t cur_eden);
duke@435 154 size_t eden_increment_with_supplement_aligned_up(size_t cur_eden);
duke@435 155
duke@435 156 // Size in bytes for an increment or decrement of the promotion area
duke@435 157 virtual size_t promo_increment(size_t cur_promo, uint percent_change);
duke@435 158 virtual size_t promo_decrement(size_t cur_promo);
duke@435 159 size_t promo_decrement_aligned_down(size_t cur_promo);
duke@435 160 size_t promo_increment_with_supplement_aligned_up(size_t cur_promo);
duke@435 161
duke@435 162 // Decay the supplemental growth additive.
duke@435 163 void decay_supplemental_growth(bool is_full_gc);
duke@435 164
duke@435 165 // Returns a change that has been scaled down. Result
duke@435 166 // is not aligned. (If useful, move to some shared
duke@435 167 // location.)
duke@435 168 size_t scale_down(size_t change, double part, double total);
duke@435 169
duke@435 170 protected:
duke@435 171 // Time accessors
duke@435 172
duke@435 173 // Footprint accessors
duke@435 174 size_t live_space() const {
duke@435 175 return (size_t)(avg_base_footprint()->average() +
duke@435 176 avg_young_live()->average() +
duke@435 177 avg_old_live()->average());
duke@435 178 }
duke@435 179 size_t free_space() const {
duke@435 180 return _eden_size + _promo_size;
duke@435 181 }
duke@435 182
duke@435 183 void set_promo_size(size_t new_size) {
duke@435 184 _promo_size = new_size;
duke@435 185 }
duke@435 186 void set_survivor_size(size_t new_size) {
duke@435 187 _survivor_size = new_size;
duke@435 188 }
duke@435 189
duke@435 190 // Update estimators
duke@435 191 void update_minor_pause_old_estimator(double minor_pause_in_ms);
duke@435 192
duke@435 193 virtual GCPolicyKind kind() const { return _gc_ps_adaptive_size_policy; }
duke@435 194
duke@435 195 public:
duke@435 196 // Use by ASPSYoungGen and ASPSOldGen to limit boundary moving.
duke@435 197 size_t eden_increment_aligned_up(size_t cur_eden);
duke@435 198 size_t eden_increment_aligned_down(size_t cur_eden);
duke@435 199 size_t promo_increment_aligned_up(size_t cur_promo);
duke@435 200 size_t promo_increment_aligned_down(size_t cur_promo);
duke@435 201
duke@435 202 virtual size_t eden_increment(size_t cur_eden);
duke@435 203 virtual size_t promo_increment(size_t cur_promo);
duke@435 204
duke@435 205 // Accessors for use by performance counters
duke@435 206 AdaptivePaddedNoZeroDevAverage* avg_promoted() const {
duke@435 207 return _gc_stats.avg_promoted();
duke@435 208 }
duke@435 209 AdaptiveWeightedAverage* avg_base_footprint() const {
duke@435 210 return _avg_base_footprint;
duke@435 211 }
duke@435 212
duke@435 213 // Input arguments are initial free space sizes for young and old
duke@435 214 // generations, the initial survivor space size, the
duke@435 215 // alignment values and the pause & throughput goals.
duke@435 216 //
duke@435 217 // NEEDS_CLEANUP this is a singleton object
duke@435 218 PSAdaptiveSizePolicy(size_t init_eden_size,
duke@435 219 size_t init_promo_size,
duke@435 220 size_t init_survivor_size,
duke@435 221 size_t intra_generation_alignment,
duke@435 222 double gc_pause_goal_sec,
duke@435 223 double gc_minor_pause_goal_sec,
duke@435 224 uint gc_time_ratio);
duke@435 225
duke@435 226 // Methods indicating events of interest to the adaptive size policy,
duke@435 227 // called by GC algorithms. It is the responsibility of users of this
duke@435 228 // policy to call these methods at the correct times!
duke@435 229 void major_collection_begin();
duke@435 230 void major_collection_end(size_t amount_live, GCCause::Cause gc_cause);
duke@435 231
duke@435 232 //
duke@435 233 void tenured_allocation(size_t size) {
duke@435 234 _avg_pretenured->sample(size);
duke@435 235 }
duke@435 236
duke@435 237 // Accessors
duke@435 238 // NEEDS_CLEANUP should use sizes.hpp
duke@435 239
duke@435 240 size_t calculated_old_free_size_in_bytes() const {
duke@435 241 return (size_t)(_promo_size + avg_promoted()->padded_average());
duke@435 242 }
duke@435 243
duke@435 244 size_t average_old_live_in_bytes() const {
duke@435 245 return (size_t) avg_old_live()->average();
duke@435 246 }
duke@435 247
duke@435 248 size_t average_promoted_in_bytes() const {
duke@435 249 return (size_t)avg_promoted()->average();
duke@435 250 }
duke@435 251
duke@435 252 size_t padded_average_promoted_in_bytes() const {
duke@435 253 return (size_t)avg_promoted()->padded_average();
duke@435 254 }
duke@435 255
duke@435 256 int change_young_gen_for_maj_pauses() {
duke@435 257 return _change_young_gen_for_maj_pauses;
duke@435 258 }
duke@435 259 void set_change_young_gen_for_maj_pauses(int v) {
duke@435 260 _change_young_gen_for_maj_pauses = v;
duke@435 261 }
duke@435 262
duke@435 263 int change_old_gen_for_min_pauses() {
duke@435 264 return _change_old_gen_for_min_pauses;
duke@435 265 }
duke@435 266 void set_change_old_gen_for_min_pauses(int v) {
duke@435 267 _change_old_gen_for_min_pauses = v;
duke@435 268 }
duke@435 269
duke@435 270 // Return true if the old generation size was changed
duke@435 271 // to try to reach a pause time goal.
duke@435 272 bool old_gen_changed_for_pauses() {
duke@435 273 bool result = _change_old_gen_for_maj_pauses != 0 ||
duke@435 274 _change_old_gen_for_min_pauses != 0;
duke@435 275 return result;
duke@435 276 }
duke@435 277
duke@435 278 // Return true if the young generation size was changed
duke@435 279 // to try to reach a pause time goal.
duke@435 280 bool young_gen_changed_for_pauses() {
duke@435 281 bool result = _change_young_gen_for_min_pauses != 0 ||
duke@435 282 _change_young_gen_for_maj_pauses != 0;
duke@435 283 return result;
duke@435 284 }
duke@435 285 // end flags for pause goal
duke@435 286
duke@435 287 // Return true if the old generation size was changed
duke@435 288 // to try to reach a throughput goal.
duke@435 289 bool old_gen_changed_for_throughput() {
duke@435 290 bool result = _change_old_gen_for_throughput != 0;
duke@435 291 return result;
duke@435 292 }
duke@435 293
duke@435 294 // Return true if the young generation size was changed
duke@435 295 // to try to reach a throughput goal.
duke@435 296 bool young_gen_changed_for_throughput() {
duke@435 297 bool result = _change_young_gen_for_throughput != 0;
duke@435 298 return result;
duke@435 299 }
duke@435 300
duke@435 301 int decrease_for_footprint() { return _decrease_for_footprint; }
duke@435 302
duke@435 303
duke@435 304 // Accessors for estimators. The slope of the linear fit is
duke@435 305 // currently all that is used for making decisions.
duke@435 306
duke@435 307 LinearLeastSquareFit* major_pause_old_estimator() {
duke@435 308 return _major_pause_old_estimator;
duke@435 309 }
duke@435 310
duke@435 311 LinearLeastSquareFit* major_pause_young_estimator() {
duke@435 312 return _major_pause_young_estimator;
duke@435 313 }
duke@435 314
duke@435 315
duke@435 316 virtual void clear_generation_free_space_flags();
duke@435 317
duke@435 318 float major_pause_old_slope() { return _major_pause_old_estimator->slope(); }
duke@435 319 float major_pause_young_slope() {
duke@435 320 return _major_pause_young_estimator->slope();
duke@435 321 }
duke@435 322 float major_collection_slope() { return _major_collection_estimator->slope();}
duke@435 323
duke@435 324 bool old_gen_policy_is_ready() { return _old_gen_policy_is_ready; }
duke@435 325
duke@435 326 // Given the amount of live data in the heap, should we
duke@435 327 // perform a Full GC?
duke@435 328 bool should_full_GC(size_t live_in_old_gen);
duke@435 329
duke@435 330 // Calculates optimial free space sizes for both the old and young
duke@435 331 // generations. Stores results in _eden_size and _promo_size.
duke@435 332 // Takes current used space in all generations as input, as well
duke@435 333 // as an indication if a full gc has just been performed, for use
duke@435 334 // in deciding if an OOM error should be thrown.
duke@435 335 void compute_generation_free_space(size_t young_live,
duke@435 336 size_t eden_live,
duke@435 337 size_t old_live,
duke@435 338 size_t perm_live,
duke@435 339 size_t cur_eden, // current eden in bytes
duke@435 340 size_t max_old_gen_size,
duke@435 341 size_t max_eden_size,
duke@435 342 bool is_full_gc,
duke@435 343 GCCause::Cause gc_cause);
duke@435 344
duke@435 345 // Calculates new survivor space size; returns a new tenuring threshold
duke@435 346 // value. Stores new survivor size in _survivor_size.
duke@435 347 int compute_survivor_space_size_and_threshold(bool is_survivor_overflow,
duke@435 348 int tenuring_threshold,
duke@435 349 size_t survivor_limit);
duke@435 350
duke@435 351 // Return the maximum size of a survivor space if the young generation were of
duke@435 352 // size gen_size.
duke@435 353 size_t max_survivor_size(size_t gen_size) {
duke@435 354 // Never allow the target survivor size to grow more than MinSurvivorRatio
duke@435 355 // of the young generation size. We cannot grow into a two semi-space
duke@435 356 // system, with Eden zero sized. Even if the survivor space grows, from()
duke@435 357 // might grow by moving the bottom boundary "down" -- so from space will
duke@435 358 // remain almost full anyway (top() will be near end(), but there will be a
duke@435 359 // large filler object at the bottom).
duke@435 360 const size_t sz = gen_size / MinSurvivorRatio;
duke@435 361 const size_t alignment = _intra_generation_alignment;
duke@435 362 return sz > alignment ? align_size_down(sz, alignment) : alignment;
duke@435 363 }
duke@435 364
duke@435 365 size_t live_at_last_full_gc() {
duke@435 366 return _live_at_last_full_gc;
duke@435 367 }
duke@435 368
duke@435 369 size_t bytes_absorbed_from_eden() const { return _bytes_absorbed_from_eden; }
duke@435 370 void reset_bytes_absorbed_from_eden() { _bytes_absorbed_from_eden = 0; }
duke@435 371
duke@435 372 void set_bytes_absorbed_from_eden(size_t val) {
duke@435 373 _bytes_absorbed_from_eden = val;
duke@435 374 }
duke@435 375
duke@435 376 // Update averages that are always used (even
duke@435 377 // if adaptive sizing is turned off).
duke@435 378 void update_averages(bool is_survivor_overflow,
duke@435 379 size_t survived,
duke@435 380 size_t promoted);
duke@435 381
duke@435 382 // Printing support
duke@435 383 virtual bool print_adaptive_size_policy_on(outputStream* st) const;
duke@435 384 };

mercurial