annotate src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp @ 1387:0bfd3fb24150

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