src/share/vm/gc_implementation/shared/adaptiveSizePolicy.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2012, 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_SHARED_ADAPTIVESIZEPOLICY_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_ADAPTIVESIZEPOLICY_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/shared/gcUtil.hpp"
aoqi@0 29 #include "gc_interface/collectedHeap.hpp"
aoqi@0 30 #include "gc_interface/gcCause.hpp"
aoqi@0 31 #include "memory/allocation.hpp"
aoqi@0 32 #include "memory/universe.hpp"
aoqi@0 33
aoqi@0 34 // This class keeps statistical information and computes the
aoqi@0 35 // size of the heap.
aoqi@0 36
aoqi@0 37 // Forward decls
aoqi@0 38 class elapsedTimer;
aoqi@0 39 class CollectorPolicy;
aoqi@0 40
aoqi@0 41 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
aoqi@0 42 friend class GCAdaptivePolicyCounters;
aoqi@0 43 friend class PSGCAdaptivePolicyCounters;
aoqi@0 44 friend class CMSGCAdaptivePolicyCounters;
aoqi@0 45 protected:
aoqi@0 46
aoqi@0 47 enum GCPolicyKind {
aoqi@0 48 _gc_adaptive_size_policy,
aoqi@0 49 _gc_ps_adaptive_size_policy,
aoqi@0 50 _gc_cms_adaptive_size_policy
aoqi@0 51 };
aoqi@0 52 virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
aoqi@0 53
aoqi@0 54 enum SizePolicyTrueValues {
aoqi@0 55 decrease_old_gen_for_throughput_true = -7,
aoqi@0 56 decrease_young_gen_for_througput_true = -6,
aoqi@0 57
aoqi@0 58 increase_old_gen_for_min_pauses_true = -5,
aoqi@0 59 decrease_old_gen_for_min_pauses_true = -4,
aoqi@0 60 decrease_young_gen_for_maj_pauses_true = -3,
aoqi@0 61 increase_young_gen_for_min_pauses_true = -2,
aoqi@0 62 increase_old_gen_for_maj_pauses_true = -1,
aoqi@0 63
aoqi@0 64 decrease_young_gen_for_min_pauses_true = 1,
aoqi@0 65 decrease_old_gen_for_maj_pauses_true = 2,
aoqi@0 66 increase_young_gen_for_maj_pauses_true = 3,
aoqi@0 67
aoqi@0 68 increase_old_gen_for_throughput_true = 4,
aoqi@0 69 increase_young_gen_for_througput_true = 5,
aoqi@0 70
aoqi@0 71 decrease_young_gen_for_footprint_true = 6,
aoqi@0 72 decrease_old_gen_for_footprint_true = 7,
aoqi@0 73 decide_at_full_gc_true = 8
aoqi@0 74 };
aoqi@0 75
aoqi@0 76 // Goal for the fraction of the total time during which application
aoqi@0 77 // threads run.
aoqi@0 78 const double _throughput_goal;
aoqi@0 79
aoqi@0 80 // Last calculated sizes, in bytes, and aligned
aoqi@0 81 size_t _eden_size; // calculated eden free space in bytes
aoqi@0 82 size_t _promo_size; // calculated cms gen free space in bytes
aoqi@0 83
aoqi@0 84 size_t _survivor_size; // calculated survivor size in bytes
aoqi@0 85
aoqi@0 86 // This is a hint for the heap: we've detected that gc times
aoqi@0 87 // are taking longer than GCTimeLimit allows.
aoqi@0 88 bool _gc_overhead_limit_exceeded;
aoqi@0 89 // Use for diagnostics only. If UseGCOverheadLimit is false,
aoqi@0 90 // this variable is still set.
aoqi@0 91 bool _print_gc_overhead_limit_would_be_exceeded;
aoqi@0 92 // Count of consecutive GC that have exceeded the
aoqi@0 93 // GC time limit criterion.
aoqi@0 94 uint _gc_overhead_limit_count;
aoqi@0 95 // This flag signals that GCTimeLimit is being exceeded
aoqi@0 96 // but may not have done so for the required number of consequetive
aoqi@0 97 // collections.
aoqi@0 98
aoqi@0 99 // Minor collection timers used to determine both
aoqi@0 100 // pause and interval times for collections.
aoqi@0 101 static elapsedTimer _minor_timer;
aoqi@0 102
aoqi@0 103 // Major collection timers, used to determine both
aoqi@0 104 // pause and interval times for collections
aoqi@0 105 static elapsedTimer _major_timer;
aoqi@0 106
aoqi@0 107 // Time statistics
aoqi@0 108 AdaptivePaddedAverage* _avg_minor_pause;
aoqi@0 109 AdaptiveWeightedAverage* _avg_minor_interval;
aoqi@0 110 AdaptiveWeightedAverage* _avg_minor_gc_cost;
aoqi@0 111
aoqi@0 112 AdaptiveWeightedAverage* _avg_major_interval;
aoqi@0 113 AdaptiveWeightedAverage* _avg_major_gc_cost;
aoqi@0 114
aoqi@0 115 // Footprint statistics
aoqi@0 116 AdaptiveWeightedAverage* _avg_young_live;
aoqi@0 117 AdaptiveWeightedAverage* _avg_eden_live;
aoqi@0 118 AdaptiveWeightedAverage* _avg_old_live;
aoqi@0 119
aoqi@0 120 // Statistics for survivor space calculation for young generation
aoqi@0 121 AdaptivePaddedAverage* _avg_survived;
aoqi@0 122
aoqi@0 123 // Objects that have been directly allocated in the old generation.
aoqi@0 124 AdaptivePaddedNoZeroDevAverage* _avg_pretenured;
aoqi@0 125
aoqi@0 126 // Variable for estimating the major and minor pause times.
aoqi@0 127 // These variables represent linear least-squares fits of
aoqi@0 128 // the data.
aoqi@0 129 // minor pause time vs. old gen size
aoqi@0 130 LinearLeastSquareFit* _minor_pause_old_estimator;
aoqi@0 131 // minor pause time vs. young gen size
aoqi@0 132 LinearLeastSquareFit* _minor_pause_young_estimator;
aoqi@0 133
aoqi@0 134 // Variables for estimating the major and minor collection costs
aoqi@0 135 // minor collection time vs. young gen size
aoqi@0 136 LinearLeastSquareFit* _minor_collection_estimator;
aoqi@0 137 // major collection time vs. cms gen size
aoqi@0 138 LinearLeastSquareFit* _major_collection_estimator;
aoqi@0 139
aoqi@0 140 // These record the most recent collection times. They
aoqi@0 141 // are available as an alternative to using the averages
aoqi@0 142 // for making ergonomic decisions.
aoqi@0 143 double _latest_minor_mutator_interval_seconds;
aoqi@0 144
aoqi@0 145 // Allowed difference between major and minor gc times, used
aoqi@0 146 // for computing tenuring_threshold.
aoqi@0 147 const double _threshold_tolerance_percent;
aoqi@0 148
aoqi@0 149 const double _gc_pause_goal_sec; // goal for maximum gc pause
aoqi@0 150
aoqi@0 151 // Flag indicating that the adaptive policy is ready to use
aoqi@0 152 bool _young_gen_policy_is_ready;
aoqi@0 153
aoqi@0 154 // decrease/increase the young generation for minor pause time
aoqi@0 155 int _change_young_gen_for_min_pauses;
aoqi@0 156
aoqi@0 157 // decrease/increase the old generation for major pause time
aoqi@0 158 int _change_old_gen_for_maj_pauses;
aoqi@0 159
aoqi@0 160 // change old geneneration for throughput
aoqi@0 161 int _change_old_gen_for_throughput;
aoqi@0 162
aoqi@0 163 // change young generation for throughput
aoqi@0 164 int _change_young_gen_for_throughput;
aoqi@0 165
aoqi@0 166 // Flag indicating that the policy would
aoqi@0 167 // increase the tenuring threshold because of the total major gc cost
aoqi@0 168 // is greater than the total minor gc cost
aoqi@0 169 bool _increment_tenuring_threshold_for_gc_cost;
aoqi@0 170 // decrease the tenuring threshold because of the the total minor gc
aoqi@0 171 // cost is greater than the total major gc cost
aoqi@0 172 bool _decrement_tenuring_threshold_for_gc_cost;
aoqi@0 173 // decrease due to survivor size limit
aoqi@0 174 bool _decrement_tenuring_threshold_for_survivor_limit;
aoqi@0 175
aoqi@0 176 // decrease generation sizes for footprint
aoqi@0 177 int _decrease_for_footprint;
aoqi@0 178
aoqi@0 179 // Set if the ergonomic decisions were made at a full GC.
aoqi@0 180 int _decide_at_full_gc;
aoqi@0 181
aoqi@0 182 // Changing the generation sizing depends on the data that is
aoqi@0 183 // gathered about the effects of changes on the pause times and
aoqi@0 184 // throughput. These variable count the number of data points
aoqi@0 185 // gathered. The policy may use these counters as a threshhold
aoqi@0 186 // for reliable data.
aoqi@0 187 julong _young_gen_change_for_minor_throughput;
aoqi@0 188 julong _old_gen_change_for_major_throughput;
aoqi@0 189
aoqi@0 190 static const uint GCWorkersPerJavaThread = 2;
aoqi@0 191
aoqi@0 192 // Accessors
aoqi@0 193
aoqi@0 194 double gc_pause_goal_sec() const { return _gc_pause_goal_sec; }
aoqi@0 195 // The value returned is unitless: it's the proportion of time
aoqi@0 196 // spent in a particular collection type.
aoqi@0 197 // An interval time will be 0.0 if a collection type hasn't occurred yet.
aoqi@0 198 // The 1.4.2 implementation put a floor on the values of major_gc_cost
aoqi@0 199 // and minor_gc_cost. This was useful because of the way major_gc_cost
aoqi@0 200 // and minor_gc_cost was used in calculating the sizes of the generations.
aoqi@0 201 // Do not use a floor in this implementation because any finite value
aoqi@0 202 // will put a limit on the throughput that can be achieved and any
aoqi@0 203 // throughput goal above that limit will drive the generations sizes
aoqi@0 204 // to extremes.
aoqi@0 205 double major_gc_cost() const {
aoqi@0 206 return MAX2(0.0F, _avg_major_gc_cost->average());
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 // The value returned is unitless: it's the proportion of time
aoqi@0 210 // spent in a particular collection type.
aoqi@0 211 // An interval time will be 0.0 if a collection type hasn't occurred yet.
aoqi@0 212 // The 1.4.2 implementation put a floor on the values of major_gc_cost
aoqi@0 213 // and minor_gc_cost. This was useful because of the way major_gc_cost
aoqi@0 214 // and minor_gc_cost was used in calculating the sizes of the generations.
aoqi@0 215 // Do not use a floor in this implementation because any finite value
aoqi@0 216 // will put a limit on the throughput that can be achieved and any
aoqi@0 217 // throughput goal above that limit will drive the generations sizes
aoqi@0 218 // to extremes.
aoqi@0 219
aoqi@0 220 double minor_gc_cost() const {
aoqi@0 221 return MAX2(0.0F, _avg_minor_gc_cost->average());
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 // Because we're dealing with averages, gc_cost() can be
aoqi@0 225 // larger than 1.0 if just the sum of the minor cost the
aoqi@0 226 // the major cost is used. Worse than that is the
aoqi@0 227 // fact that the minor cost and the major cost each
aoqi@0 228 // tend toward 1.0 in the extreme of high gc costs.
aoqi@0 229 // Limit the value of gc_cost to 1.0 so that the mutator
aoqi@0 230 // cost stays non-negative.
aoqi@0 231 virtual double gc_cost() const {
aoqi@0 232 double result = MIN2(1.0, minor_gc_cost() + major_gc_cost());
aoqi@0 233 assert(result >= 0.0, "Both minor and major costs are non-negative");
aoqi@0 234 return result;
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 // Elapsed time since the last major collection.
aoqi@0 238 virtual double time_since_major_gc() const;
aoqi@0 239
aoqi@0 240 // Average interval between major collections to be used
aoqi@0 241 // in calculating the decaying major gc cost. An overestimate
aoqi@0 242 // of this time would be a conservative estimate because
aoqi@0 243 // this time is used to decide if the major GC cost
aoqi@0 244 // should be decayed (i.e., if the time since the last
aoqi@0 245 // major gc is long compared to the time returned here,
aoqi@0 246 // then the major GC cost will be decayed). See the
aoqi@0 247 // implementations for the specifics.
aoqi@0 248 virtual double major_gc_interval_average_for_decay() const {
aoqi@0 249 return _avg_major_interval->average();
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 // Return the cost of the GC where the major gc cost
aoqi@0 253 // has been decayed based on the time since the last
aoqi@0 254 // major collection.
aoqi@0 255 double decaying_gc_cost() const;
aoqi@0 256
aoqi@0 257 // Decay the major gc cost. Use this only for decisions on
aoqi@0 258 // whether to adjust, not to determine by how much to adjust.
aoqi@0 259 // This approximation is crude and may not be good enough for the
aoqi@0 260 // latter.
aoqi@0 261 double decaying_major_gc_cost() const;
aoqi@0 262
aoqi@0 263 // Return the mutator cost using the decayed
aoqi@0 264 // GC cost.
aoqi@0 265 double adjusted_mutator_cost() const {
aoqi@0 266 double result = 1.0 - decaying_gc_cost();
aoqi@0 267 assert(result >= 0.0, "adjusted mutator cost calculation is incorrect");
aoqi@0 268 return result;
aoqi@0 269 }
aoqi@0 270
aoqi@0 271 virtual double mutator_cost() const {
aoqi@0 272 double result = 1.0 - gc_cost();
aoqi@0 273 assert(result >= 0.0, "mutator cost calculation is incorrect");
aoqi@0 274 return result;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277
aoqi@0 278 bool young_gen_policy_is_ready() { return _young_gen_policy_is_ready; }
aoqi@0 279
aoqi@0 280 void update_minor_pause_young_estimator(double minor_pause_in_ms);
aoqi@0 281 virtual void update_minor_pause_old_estimator(double minor_pause_in_ms) {
aoqi@0 282 // This is not meaningful for all policies but needs to be present
aoqi@0 283 // to use minor_collection_end() in its current form.
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 virtual size_t eden_increment(size_t cur_eden);
aoqi@0 287 virtual size_t eden_increment(size_t cur_eden, uint percent_change);
aoqi@0 288 virtual size_t eden_decrement(size_t cur_eden);
aoqi@0 289 virtual size_t promo_increment(size_t cur_eden);
aoqi@0 290 virtual size_t promo_increment(size_t cur_eden, uint percent_change);
aoqi@0 291 virtual size_t promo_decrement(size_t cur_eden);
aoqi@0 292
aoqi@0 293 virtual void clear_generation_free_space_flags();
aoqi@0 294
aoqi@0 295 int change_old_gen_for_throughput() const {
aoqi@0 296 return _change_old_gen_for_throughput;
aoqi@0 297 }
aoqi@0 298 void set_change_old_gen_for_throughput(int v) {
aoqi@0 299 _change_old_gen_for_throughput = v;
aoqi@0 300 }
aoqi@0 301 int change_young_gen_for_throughput() const {
aoqi@0 302 return _change_young_gen_for_throughput;
aoqi@0 303 }
aoqi@0 304 void set_change_young_gen_for_throughput(int v) {
aoqi@0 305 _change_young_gen_for_throughput = v;
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 int change_old_gen_for_maj_pauses() const {
aoqi@0 309 return _change_old_gen_for_maj_pauses;
aoqi@0 310 }
aoqi@0 311 void set_change_old_gen_for_maj_pauses(int v) {
aoqi@0 312 _change_old_gen_for_maj_pauses = v;
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 bool decrement_tenuring_threshold_for_gc_cost() const {
aoqi@0 316 return _decrement_tenuring_threshold_for_gc_cost;
aoqi@0 317 }
aoqi@0 318 void set_decrement_tenuring_threshold_for_gc_cost(bool v) {
aoqi@0 319 _decrement_tenuring_threshold_for_gc_cost = v;
aoqi@0 320 }
aoqi@0 321 bool increment_tenuring_threshold_for_gc_cost() const {
aoqi@0 322 return _increment_tenuring_threshold_for_gc_cost;
aoqi@0 323 }
aoqi@0 324 void set_increment_tenuring_threshold_for_gc_cost(bool v) {
aoqi@0 325 _increment_tenuring_threshold_for_gc_cost = v;
aoqi@0 326 }
aoqi@0 327 bool decrement_tenuring_threshold_for_survivor_limit() const {
aoqi@0 328 return _decrement_tenuring_threshold_for_survivor_limit;
aoqi@0 329 }
aoqi@0 330 void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
aoqi@0 331 _decrement_tenuring_threshold_for_survivor_limit = v;
aoqi@0 332 }
aoqi@0 333 // Return true if the policy suggested a change.
aoqi@0 334 bool tenuring_threshold_change() const;
aoqi@0 335
aoqi@0 336 static bool _debug_perturbation;
aoqi@0 337
aoqi@0 338 public:
aoqi@0 339 AdaptiveSizePolicy(size_t init_eden_size,
aoqi@0 340 size_t init_promo_size,
aoqi@0 341 size_t init_survivor_size,
aoqi@0 342 double gc_pause_goal_sec,
aoqi@0 343 uint gc_cost_ratio);
aoqi@0 344
aoqi@0 345 // Return number default GC threads to use in the next GC.
aoqi@0 346 static int calc_default_active_workers(uintx total_workers,
aoqi@0 347 const uintx min_workers,
aoqi@0 348 uintx active_workers,
aoqi@0 349 uintx application_workers);
aoqi@0 350
aoqi@0 351 // Return number of GC threads to use in the next GC.
aoqi@0 352 // This is called sparingly so as not to change the
aoqi@0 353 // number of GC workers gratuitously.
aoqi@0 354 // For ParNew collections
aoqi@0 355 // For PS scavenge and ParOld collections
aoqi@0 356 // For G1 evacuation pauses (subject to update)
aoqi@0 357 // Other collection phases inherit the number of
aoqi@0 358 // GC workers from the calls above. For example,
aoqi@0 359 // a CMS parallel remark uses the same number of GC
aoqi@0 360 // workers as the most recent ParNew collection.
aoqi@0 361 static int calc_active_workers(uintx total_workers,
aoqi@0 362 uintx active_workers,
aoqi@0 363 uintx application_workers);
aoqi@0 364
aoqi@0 365 // Return number of GC threads to use in the next concurrent GC phase.
aoqi@0 366 static int calc_active_conc_workers(uintx total_workers,
aoqi@0 367 uintx active_workers,
aoqi@0 368 uintx application_workers);
aoqi@0 369
aoqi@0 370 bool is_gc_cms_adaptive_size_policy() {
aoqi@0 371 return kind() == _gc_cms_adaptive_size_policy;
aoqi@0 372 }
aoqi@0 373 bool is_gc_ps_adaptive_size_policy() {
aoqi@0 374 return kind() == _gc_ps_adaptive_size_policy;
aoqi@0 375 }
aoqi@0 376
aoqi@0 377 AdaptivePaddedAverage* avg_minor_pause() const { return _avg_minor_pause; }
aoqi@0 378 AdaptiveWeightedAverage* avg_minor_interval() const {
aoqi@0 379 return _avg_minor_interval;
aoqi@0 380 }
aoqi@0 381 AdaptiveWeightedAverage* avg_minor_gc_cost() const {
aoqi@0 382 return _avg_minor_gc_cost;
aoqi@0 383 }
aoqi@0 384
aoqi@0 385 AdaptiveWeightedAverage* avg_major_gc_cost() const {
aoqi@0 386 return _avg_major_gc_cost;
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 AdaptiveWeightedAverage* avg_young_live() const { return _avg_young_live; }
aoqi@0 390 AdaptiveWeightedAverage* avg_eden_live() const { return _avg_eden_live; }
aoqi@0 391 AdaptiveWeightedAverage* avg_old_live() const { return _avg_old_live; }
aoqi@0 392
aoqi@0 393 AdaptivePaddedAverage* avg_survived() const { return _avg_survived; }
aoqi@0 394 AdaptivePaddedNoZeroDevAverage* avg_pretenured() { return _avg_pretenured; }
aoqi@0 395
aoqi@0 396 // Methods indicating events of interest to the adaptive size policy,
aoqi@0 397 // called by GC algorithms. It is the responsibility of users of this
aoqi@0 398 // policy to call these methods at the correct times!
aoqi@0 399 virtual void minor_collection_begin();
aoqi@0 400 virtual void minor_collection_end(GCCause::Cause gc_cause);
aoqi@0 401 virtual LinearLeastSquareFit* minor_pause_old_estimator() const {
aoqi@0 402 return _minor_pause_old_estimator;
aoqi@0 403 }
aoqi@0 404
aoqi@0 405 LinearLeastSquareFit* minor_pause_young_estimator() {
aoqi@0 406 return _minor_pause_young_estimator;
aoqi@0 407 }
aoqi@0 408 LinearLeastSquareFit* minor_collection_estimator() {
aoqi@0 409 return _minor_collection_estimator;
aoqi@0 410 }
aoqi@0 411
aoqi@0 412 LinearLeastSquareFit* major_collection_estimator() {
aoqi@0 413 return _major_collection_estimator;
aoqi@0 414 }
aoqi@0 415
aoqi@0 416 float minor_pause_young_slope() {
aoqi@0 417 return _minor_pause_young_estimator->slope();
aoqi@0 418 }
aoqi@0 419
aoqi@0 420 float minor_collection_slope() { return _minor_collection_estimator->slope();}
aoqi@0 421 float major_collection_slope() { return _major_collection_estimator->slope();}
aoqi@0 422
aoqi@0 423 float minor_pause_old_slope() {
aoqi@0 424 return _minor_pause_old_estimator->slope();
aoqi@0 425 }
aoqi@0 426
aoqi@0 427 void set_eden_size(size_t new_size) {
aoqi@0 428 _eden_size = new_size;
aoqi@0 429 }
aoqi@0 430 void set_survivor_size(size_t new_size) {
aoqi@0 431 _survivor_size = new_size;
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 size_t calculated_eden_size_in_bytes() const {
aoqi@0 435 return _eden_size;
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 size_t calculated_promo_size_in_bytes() const {
aoqi@0 439 return _promo_size;
aoqi@0 440 }
aoqi@0 441
aoqi@0 442 size_t calculated_survivor_size_in_bytes() const {
aoqi@0 443 return _survivor_size;
aoqi@0 444 }
aoqi@0 445
aoqi@0 446 // This is a hint for the heap: we've detected that gc times
aoqi@0 447 // are taking longer than GCTimeLimit allows.
aoqi@0 448 // Most heaps will choose to throw an OutOfMemoryError when
aoqi@0 449 // this occurs but it is up to the heap to request this information
aoqi@0 450 // of the policy
aoqi@0 451 bool gc_overhead_limit_exceeded() {
aoqi@0 452 return _gc_overhead_limit_exceeded;
aoqi@0 453 }
aoqi@0 454 void set_gc_overhead_limit_exceeded(bool v) {
aoqi@0 455 _gc_overhead_limit_exceeded = v;
aoqi@0 456 }
aoqi@0 457
aoqi@0 458 // Tests conditions indicate the GC overhead limit is being approached.
aoqi@0 459 bool gc_overhead_limit_near() {
aoqi@0 460 return gc_overhead_limit_count() >=
aoqi@0 461 (AdaptiveSizePolicyGCTimeLimitThreshold - 1);
aoqi@0 462 }
aoqi@0 463 uint gc_overhead_limit_count() { return _gc_overhead_limit_count; }
aoqi@0 464 void reset_gc_overhead_limit_count() { _gc_overhead_limit_count = 0; }
aoqi@0 465 void inc_gc_overhead_limit_count() { _gc_overhead_limit_count++; }
aoqi@0 466 // accessors for flags recording the decisions to resize the
aoqi@0 467 // generations to meet the pause goal.
aoqi@0 468
aoqi@0 469 int change_young_gen_for_min_pauses() const {
aoqi@0 470 return _change_young_gen_for_min_pauses;
aoqi@0 471 }
aoqi@0 472 void set_change_young_gen_for_min_pauses(int v) {
aoqi@0 473 _change_young_gen_for_min_pauses = v;
aoqi@0 474 }
aoqi@0 475 void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
aoqi@0 476 int decrease_for_footprint() const { return _decrease_for_footprint; }
aoqi@0 477 int decide_at_full_gc() { return _decide_at_full_gc; }
aoqi@0 478 void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
aoqi@0 479
aoqi@0 480 // Check the conditions for an out-of-memory due to excessive GC time.
aoqi@0 481 // Set _gc_overhead_limit_exceeded if all the conditions have been met.
aoqi@0 482 void check_gc_overhead_limit(size_t young_live,
aoqi@0 483 size_t eden_live,
aoqi@0 484 size_t max_old_gen_size,
aoqi@0 485 size_t max_eden_size,
aoqi@0 486 bool is_full_gc,
aoqi@0 487 GCCause::Cause gc_cause,
aoqi@0 488 CollectorPolicy* collector_policy);
aoqi@0 489
aoqi@0 490 // Printing support
aoqi@0 491 virtual bool print_adaptive_size_policy_on(outputStream* st) const;
aoqi@0 492 bool print_adaptive_size_policy_on(outputStream* st,
aoqi@0 493 uint tenuring_threshold) const;
aoqi@0 494 };
aoqi@0 495
aoqi@0 496 // Class that can be used to print information about the
aoqi@0 497 // adaptive size policy at intervals specified by
aoqi@0 498 // AdaptiveSizePolicyOutputInterval. Only print information
aoqi@0 499 // if an adaptive size policy is in use.
aoqi@0 500 class AdaptiveSizePolicyOutput : StackObj {
aoqi@0 501 AdaptiveSizePolicy* _size_policy;
aoqi@0 502 bool _do_print;
aoqi@0 503 bool print_test(uint count) {
aoqi@0 504 // A count of zero is a special value that indicates that the
aoqi@0 505 // interval test should be ignored. An interval is of zero is
aoqi@0 506 // a special value that indicates that the interval test should
aoqi@0 507 // always fail (never do the print based on the interval test).
aoqi@0 508 return PrintGCDetails &&
aoqi@0 509 UseAdaptiveSizePolicy &&
aoqi@0 510 (UseParallelGC || UseConcMarkSweepGC) &&
aoqi@0 511 (AdaptiveSizePolicyOutputInterval > 0) &&
aoqi@0 512 ((count == 0) ||
aoqi@0 513 ((count % AdaptiveSizePolicyOutputInterval) == 0));
aoqi@0 514 }
aoqi@0 515 public:
aoqi@0 516 // The special value of a zero count can be used to ignore
aoqi@0 517 // the count test.
aoqi@0 518 AdaptiveSizePolicyOutput(uint count) {
aoqi@0 519 if (UseAdaptiveSizePolicy && (AdaptiveSizePolicyOutputInterval > 0)) {
aoqi@0 520 CollectedHeap* heap = Universe::heap();
aoqi@0 521 _size_policy = heap->size_policy();
aoqi@0 522 _do_print = print_test(count);
aoqi@0 523 } else {
aoqi@0 524 _size_policy = NULL;
aoqi@0 525 _do_print = false;
aoqi@0 526 }
aoqi@0 527 }
aoqi@0 528 AdaptiveSizePolicyOutput(AdaptiveSizePolicy* size_policy,
aoqi@0 529 uint count) :
aoqi@0 530 _size_policy(size_policy) {
aoqi@0 531 if (UseAdaptiveSizePolicy && (AdaptiveSizePolicyOutputInterval > 0)) {
aoqi@0 532 _do_print = print_test(count);
aoqi@0 533 } else {
aoqi@0 534 _do_print = false;
aoqi@0 535 }
aoqi@0 536 }
aoqi@0 537 ~AdaptiveSizePolicyOutput() {
aoqi@0 538 if (_do_print) {
aoqi@0 539 assert(UseAdaptiveSizePolicy, "Should not be in use");
aoqi@0 540 _size_policy->print_adaptive_size_policy_on(gclog_or_tty);
aoqi@0 541 }
aoqi@0 542 }
aoqi@0 543 };
aoqi@0 544
aoqi@0 545 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ADAPTIVESIZEPOLICY_HPP

mercurial