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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6267
a034dc5e910b
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial