1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,1175 @@ 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 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_psAdaptiveSizePolicy.cpp.incl" 1.30 + 1.31 +#include <math.h> 1.32 + 1.33 +PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size, 1.34 + size_t init_promo_size, 1.35 + size_t init_survivor_size, 1.36 + size_t intra_generation_alignment, 1.37 + double gc_pause_goal_sec, 1.38 + double gc_minor_pause_goal_sec, 1.39 + uint gc_cost_ratio) : 1.40 + AdaptiveSizePolicy(init_eden_size, 1.41 + init_promo_size, 1.42 + init_survivor_size, 1.43 + gc_pause_goal_sec, 1.44 + gc_cost_ratio), 1.45 + _collection_cost_margin_fraction(AdaptiveSizePolicyCollectionCostMargin/ 1.46 + 100.0), 1.47 + _intra_generation_alignment(intra_generation_alignment), 1.48 + _live_at_last_full_gc(init_promo_size), 1.49 + _gc_minor_pause_goal_sec(gc_minor_pause_goal_sec), 1.50 + _latest_major_mutator_interval_seconds(0), 1.51 + _young_gen_change_for_major_pause_count(0) 1.52 +{ 1.53 + // Sizing policy statistics 1.54 + _avg_major_pause = 1.55 + new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding); 1.56 + _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight); 1.57 + _avg_major_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight); 1.58 + 1.59 + _avg_base_footprint = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight); 1.60 + _major_pause_old_estimator = 1.61 + new LinearLeastSquareFit(AdaptiveSizePolicyWeight); 1.62 + _major_pause_young_estimator = 1.63 + new LinearLeastSquareFit(AdaptiveSizePolicyWeight); 1.64 + _major_collection_estimator = 1.65 + new LinearLeastSquareFit(AdaptiveSizePolicyWeight); 1.66 + 1.67 + _young_gen_size_increment_supplement = YoungGenerationSizeSupplement; 1.68 + _old_gen_size_increment_supplement = TenuredGenerationSizeSupplement; 1.69 + 1.70 + // Start the timers 1.71 + _major_timer.start(); 1.72 + 1.73 + _old_gen_policy_is_ready = false; 1.74 +} 1.75 + 1.76 +void PSAdaptiveSizePolicy::major_collection_begin() { 1.77 + // Update the interval time 1.78 + _major_timer.stop(); 1.79 + // Save most recent collection time 1.80 + _latest_major_mutator_interval_seconds = _major_timer.seconds(); 1.81 + _major_timer.reset(); 1.82 + _major_timer.start(); 1.83 +} 1.84 + 1.85 +void PSAdaptiveSizePolicy::update_minor_pause_old_estimator( 1.86 + double minor_pause_in_ms) { 1.87 + double promo_size_in_mbytes = ((double)_promo_size)/((double)M); 1.88 + _minor_pause_old_estimator->update(promo_size_in_mbytes, 1.89 + minor_pause_in_ms); 1.90 +} 1.91 + 1.92 +void PSAdaptiveSizePolicy::major_collection_end(size_t amount_live, 1.93 + GCCause::Cause gc_cause) { 1.94 + // Update the pause time. 1.95 + _major_timer.stop(); 1.96 + 1.97 + if (gc_cause != GCCause::_java_lang_system_gc || 1.98 + UseAdaptiveSizePolicyWithSystemGC) { 1.99 + double major_pause_in_seconds = _major_timer.seconds(); 1.100 + double major_pause_in_ms = major_pause_in_seconds * MILLIUNITS; 1.101 + 1.102 + // Sample for performance counter 1.103 + _avg_major_pause->sample(major_pause_in_seconds); 1.104 + 1.105 + // Cost of collection (unit-less) 1.106 + double collection_cost = 0.0; 1.107 + if ((_latest_major_mutator_interval_seconds > 0.0) && 1.108 + (major_pause_in_seconds > 0.0)) { 1.109 + double interval_in_seconds = 1.110 + _latest_major_mutator_interval_seconds + major_pause_in_seconds; 1.111 + collection_cost = 1.112 + major_pause_in_seconds / interval_in_seconds; 1.113 + avg_major_gc_cost()->sample(collection_cost); 1.114 + 1.115 + // Sample for performance counter 1.116 + _avg_major_interval->sample(interval_in_seconds); 1.117 + } 1.118 + 1.119 + // Calculate variables used to estimate pause time vs. gen sizes 1.120 + double eden_size_in_mbytes = ((double)_eden_size)/((double)M); 1.121 + double promo_size_in_mbytes = ((double)_promo_size)/((double)M); 1.122 + _major_pause_old_estimator->update(promo_size_in_mbytes, 1.123 + major_pause_in_ms); 1.124 + _major_pause_young_estimator->update(eden_size_in_mbytes, 1.125 + major_pause_in_ms); 1.126 + 1.127 + if (PrintAdaptiveSizePolicy && Verbose) { 1.128 + gclog_or_tty->print("psAdaptiveSizePolicy::major_collection_end: " 1.129 + "major gc cost: %f average: %f", collection_cost, 1.130 + avg_major_gc_cost()->average()); 1.131 + gclog_or_tty->print_cr(" major pause: %f major period %f", 1.132 + major_pause_in_ms, 1.133 + _latest_major_mutator_interval_seconds * MILLIUNITS); 1.134 + } 1.135 + 1.136 + // Calculate variable used to estimate collection cost vs. gen sizes 1.137 + assert(collection_cost >= 0.0, "Expected to be non-negative"); 1.138 + _major_collection_estimator->update(promo_size_in_mbytes, 1.139 + collection_cost); 1.140 + } 1.141 + 1.142 + // Update the amount live at the end of a full GC 1.143 + _live_at_last_full_gc = amount_live; 1.144 + 1.145 + // The policy does not have enough data until at least some major collections 1.146 + // have been done. 1.147 + if (_avg_major_pause->count() >= AdaptiveSizePolicyReadyThreshold) { 1.148 + _old_gen_policy_is_ready = true; 1.149 + } 1.150 + 1.151 + // Interval times use this timer to measure the interval that 1.152 + // the mutator runs. Reset after the GC pause has been measured. 1.153 + _major_timer.reset(); 1.154 + _major_timer.start(); 1.155 +} 1.156 + 1.157 +// If the remaining free space in the old generation is less that 1.158 +// that expected to be needed by the next collection, do a full 1.159 +// collection now. 1.160 +bool PSAdaptiveSizePolicy::should_full_GC(size_t old_free_in_bytes) { 1.161 + 1.162 + // A similar test is done in the scavenge's should_attempt_scavenge(). If 1.163 + // this is changed, decide if that test should also be changed. 1.164 + bool result = padded_average_promoted_in_bytes() > (float) old_free_in_bytes; 1.165 + if (PrintGCDetails && Verbose) { 1.166 + if (result) { 1.167 + gclog_or_tty->print(" full after scavenge: "); 1.168 + } else { 1.169 + gclog_or_tty->print(" no full after scavenge: "); 1.170 + } 1.171 + gclog_or_tty->print_cr(" average_promoted " SIZE_FORMAT 1.172 + " padded_average_promoted " SIZE_FORMAT 1.173 + " free in old gen " SIZE_FORMAT, 1.174 + (size_t) average_promoted_in_bytes(), 1.175 + (size_t) padded_average_promoted_in_bytes(), 1.176 + old_free_in_bytes); 1.177 + } 1.178 + return result; 1.179 +} 1.180 + 1.181 +void PSAdaptiveSizePolicy::clear_generation_free_space_flags() { 1.182 + 1.183 + AdaptiveSizePolicy::clear_generation_free_space_flags(); 1.184 + 1.185 + set_change_old_gen_for_min_pauses(0); 1.186 + 1.187 + set_change_young_gen_for_maj_pauses(0); 1.188 +} 1.189 + 1.190 + 1.191 +// If this is not a full GC, only test and modify the young generation. 1.192 + 1.193 +void PSAdaptiveSizePolicy::compute_generation_free_space(size_t young_live, 1.194 + size_t eden_live, 1.195 + size_t old_live, 1.196 + size_t perm_live, 1.197 + size_t cur_eden, 1.198 + size_t max_old_gen_size, 1.199 + size_t max_eden_size, 1.200 + bool is_full_gc, 1.201 + GCCause::Cause gc_cause) { 1.202 + 1.203 + // Update statistics 1.204 + // Time statistics are updated as we go, update footprint stats here 1.205 + _avg_base_footprint->sample(BaseFootPrintEstimate + perm_live); 1.206 + avg_young_live()->sample(young_live); 1.207 + avg_eden_live()->sample(eden_live); 1.208 + if (is_full_gc) { 1.209 + // old_live is only accurate after a full gc 1.210 + avg_old_live()->sample(old_live); 1.211 + } 1.212 + 1.213 + // This code used to return if the policy was not ready , i.e., 1.214 + // policy_is_ready() returning false. The intent was that 1.215 + // decisions below needed major collection times and so could 1.216 + // not be made before two major collections. A consequence was 1.217 + // adjustments to the young generation were not done until after 1.218 + // two major collections even if the minor collections times 1.219 + // exceeded the requested goals. Now let the young generation 1.220 + // adjust for the minor collection times. Major collection times 1.221 + // will be zero for the first collection and will naturally be 1.222 + // ignored. Tenured generation adjustments are only made at the 1.223 + // full collections so until the second major collection has 1.224 + // been reached, no tenured generation adjustments will be made. 1.225 + 1.226 + // Until we know better, desired promotion size uses the last calculation 1.227 + size_t desired_promo_size = _promo_size; 1.228 + 1.229 + // Start eden at the current value. The desired value that is stored 1.230 + // in _eden_size is not bounded by constraints of the heap and can 1.231 + // run away. 1.232 + // 1.233 + // As expected setting desired_eden_size to the current 1.234 + // value of desired_eden_size as a starting point 1.235 + // caused desired_eden_size to grow way too large and caused 1.236 + // an overflow down stream. It may have improved performance in 1.237 + // some case but is dangerous. 1.238 + size_t desired_eden_size = cur_eden; 1.239 + 1.240 +#ifdef ASSERT 1.241 + size_t original_promo_size = desired_promo_size; 1.242 + size_t original_eden_size = desired_eden_size; 1.243 +#endif 1.244 + 1.245 + // Cache some values. There's a bit of work getting these, so 1.246 + // we might save a little time. 1.247 + const double major_cost = major_gc_cost(); 1.248 + const double minor_cost = minor_gc_cost(); 1.249 + 1.250 + // Used for diagnostics 1.251 + clear_generation_free_space_flags(); 1.252 + 1.253 + // Limits on our growth 1.254 + size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average()); 1.255 + 1.256 + // This method sets the desired eden size. That plus the 1.257 + // desired survivor space sizes sets the desired young generation 1.258 + // size. This methods does not know what the desired survivor 1.259 + // size is but expects that other policy will attempt to make 1.260 + // the survivor sizes compatible with the live data in the 1.261 + // young generation. This limit is an estimate of the space left 1.262 + // in the young generation after the survivor spaces have been 1.263 + // subtracted out. 1.264 + size_t eden_limit = max_eden_size; 1.265 + 1.266 + // But don't force a promo size below the current promo size. Otherwise, 1.267 + // the promo size will shrink for no good reason. 1.268 + promo_limit = MAX2(promo_limit, _promo_size); 1.269 + 1.270 + const double gc_cost_limit = GCTimeLimit/100.0; 1.271 + 1.272 + // Which way should we go? 1.273 + // if pause requirement is not met 1.274 + // adjust size of any generation with average paus exceeding 1.275 + // the pause limit. Adjust one pause at a time (the larger) 1.276 + // and only make adjustments for the major pause at full collections. 1.277 + // else if throughput requirement not met 1.278 + // adjust the size of the generation with larger gc time. Only 1.279 + // adjust one generation at a time. 1.280 + // else 1.281 + // adjust down the total heap size. Adjust down the larger of the 1.282 + // generations. 1.283 + 1.284 + // Add some checks for a threshhold for a change. For example, 1.285 + // a change less than the necessary alignment is probably not worth 1.286 + // attempting. 1.287 + 1.288 + 1.289 + if ((_avg_minor_pause->padded_average() > gc_pause_goal_sec()) || 1.290 + (_avg_major_pause->padded_average() > gc_pause_goal_sec())) { 1.291 + // 1.292 + // Check pauses 1.293 + // 1.294 + // Make changes only to affect one of the pauses (the larger) 1.295 + // at a time. 1.296 + adjust_for_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size); 1.297 + 1.298 + } else if (_avg_minor_pause->padded_average() > gc_minor_pause_goal_sec()) { 1.299 + // Adjust only for the minor pause time goal 1.300 + adjust_for_minor_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size); 1.301 + 1.302 + } else if(adjusted_mutator_cost() < _throughput_goal) { 1.303 + // This branch used to require that (mutator_cost() > 0.0 in 1.4.2. 1.304 + // This sometimes resulted in skipping to the minimize footprint 1.305 + // code. Change this to try and reduce GC time if mutator time is 1.306 + // negative for whatever reason. Or for future consideration, 1.307 + // bail out of the code if mutator time is negative. 1.308 + // 1.309 + // Throughput 1.310 + // 1.311 + assert(major_cost >= 0.0, "major cost is < 0.0"); 1.312 + assert(minor_cost >= 0.0, "minor cost is < 0.0"); 1.313 + // Try to reduce the GC times. 1.314 + adjust_for_throughput(is_full_gc, &desired_promo_size, &desired_eden_size); 1.315 + 1.316 + } else { 1.317 + 1.318 + // Be conservative about reducing the footprint. 1.319 + // Do a minimum number of major collections first. 1.320 + // Have reasonable averages for major and minor collections costs. 1.321 + if (UseAdaptiveSizePolicyFootprintGoal && 1.322 + young_gen_policy_is_ready() && 1.323 + avg_major_gc_cost()->average() >= 0.0 && 1.324 + avg_minor_gc_cost()->average() >= 0.0) { 1.325 + size_t desired_sum = desired_eden_size + desired_promo_size; 1.326 + desired_eden_size = adjust_eden_for_footprint(desired_eden_size, 1.327 + desired_sum); 1.328 + if (is_full_gc) { 1.329 + set_decide_at_full_gc(decide_at_full_gc_true); 1.330 + desired_promo_size = adjust_promo_for_footprint(desired_promo_size, 1.331 + desired_sum); 1.332 + } 1.333 + } 1.334 + } 1.335 + 1.336 + // Note we make the same tests as in the code block below; the code 1.337 + // seems a little easier to read with the printing in another block. 1.338 + if (PrintAdaptiveSizePolicy) { 1.339 + if (desired_promo_size > promo_limit) { 1.340 + // "free_in_old_gen" was the original value for used for promo_limit 1.341 + size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); 1.342 + gclog_or_tty->print_cr( 1.343 + "PSAdaptiveSizePolicy::compute_generation_free_space limits:" 1.344 + " desired_promo_size: " SIZE_FORMAT 1.345 + " promo_limit: " SIZE_FORMAT 1.346 + " free_in_old_gen: " SIZE_FORMAT 1.347 + " max_old_gen_size: " SIZE_FORMAT 1.348 + " avg_old_live: " SIZE_FORMAT, 1.349 + desired_promo_size, promo_limit, free_in_old_gen, 1.350 + max_old_gen_size, (size_t) avg_old_live()->average()); 1.351 + } 1.352 + if (desired_eden_size > eden_limit) { 1.353 + gclog_or_tty->print_cr( 1.354 + "AdaptiveSizePolicy::compute_generation_free_space limits:" 1.355 + " desired_eden_size: " SIZE_FORMAT 1.356 + " old_eden_size: " SIZE_FORMAT 1.357 + " eden_limit: " SIZE_FORMAT 1.358 + " cur_eden: " SIZE_FORMAT 1.359 + " max_eden_size: " SIZE_FORMAT 1.360 + " avg_young_live: " SIZE_FORMAT, 1.361 + desired_eden_size, _eden_size, eden_limit, cur_eden, 1.362 + max_eden_size, (size_t)avg_young_live()->average()); 1.363 + } 1.364 + if (gc_cost() > gc_cost_limit) { 1.365 + gclog_or_tty->print_cr( 1.366 + "AdaptiveSizePolicy::compute_generation_free_space: gc time limit" 1.367 + " gc_cost: %f " 1.368 + " GCTimeLimit: %d", 1.369 + gc_cost(), GCTimeLimit); 1.370 + } 1.371 + } 1.372 + 1.373 + // Align everything and make a final limit check 1.374 + const size_t alignment = _intra_generation_alignment; 1.375 + desired_eden_size = align_size_up(desired_eden_size, alignment); 1.376 + desired_eden_size = MAX2(desired_eden_size, alignment); 1.377 + desired_promo_size = align_size_up(desired_promo_size, alignment); 1.378 + desired_promo_size = MAX2(desired_promo_size, alignment); 1.379 + 1.380 + eden_limit = align_size_down(eden_limit, alignment); 1.381 + promo_limit = align_size_down(promo_limit, alignment); 1.382 + 1.383 + // Is too much time being spent in GC? 1.384 + // Is the heap trying to grow beyond it's limits? 1.385 + 1.386 + const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); 1.387 + if (desired_promo_size > free_in_old_gen && desired_eden_size > eden_limit) { 1.388 + 1.389 + // eden_limit is the upper limit on the size of eden based on 1.390 + // the maximum size of the young generation and the sizes 1.391 + // of the survivor space. 1.392 + // The question being asked is whether the gc costs are high 1.393 + // and the space being recovered by a collection is low. 1.394 + // free_in_young_gen is the free space in the young generation 1.395 + // after a collection and promo_live is the free space in the old 1.396 + // generation after a collection. 1.397 + // 1.398 + // Use the minimum of the current value of the live in the 1.399 + // young gen or the average of the live in the young gen. 1.400 + // If the current value drops quickly, that should be taken 1.401 + // into account (i.e., don't trigger if the amount of free 1.402 + // space has suddenly jumped up). If the current is much 1.403 + // higher than the average, use the average since it represents 1.404 + // the longer term behavor. 1.405 + const size_t live_in_eden = MIN2(eden_live, (size_t) avg_eden_live()->average()); 1.406 + const size_t free_in_eden = eden_limit > live_in_eden ? 1.407 + eden_limit - live_in_eden : 0; 1.408 + const size_t total_free_limit = free_in_old_gen + free_in_eden; 1.409 + const size_t total_mem = max_old_gen_size + max_eden_size; 1.410 + const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0); 1.411 + if (PrintAdaptiveSizePolicy && (Verbose || 1.412 + (total_free_limit < (size_t) mem_free_limit))) { 1.413 + gclog_or_tty->print_cr( 1.414 + "PSAdaptiveSizePolicy::compute_generation_free_space limits:" 1.415 + " promo_limit: " SIZE_FORMAT 1.416 + " eden_limit: " SIZE_FORMAT 1.417 + " total_free_limit: " SIZE_FORMAT 1.418 + " max_old_gen_size: " SIZE_FORMAT 1.419 + " max_eden_size: " SIZE_FORMAT 1.420 + " mem_free_limit: " SIZE_FORMAT, 1.421 + promo_limit, eden_limit, total_free_limit, 1.422 + max_old_gen_size, max_eden_size, 1.423 + (size_t) mem_free_limit); 1.424 + } 1.425 + 1.426 + if (is_full_gc) { 1.427 + if (gc_cost() > gc_cost_limit && 1.428 + total_free_limit < (size_t) mem_free_limit) { 1.429 + // Collections, on average, are taking too much time, and 1.430 + // gc_cost() > gc_cost_limit 1.431 + // we have too little space available after a full gc. 1.432 + // total_free_limit < mem_free_limit 1.433 + // where 1.434 + // total_free_limit is the free space available in 1.435 + // both generations 1.436 + // total_mem is the total space available for allocation 1.437 + // in both generations (survivor spaces are not included 1.438 + // just as they are not included in eden_limit). 1.439 + // mem_free_limit is a fraction of total_mem judged to be an 1.440 + // acceptable amount that is still unused. 1.441 + // The heap can ask for the value of this variable when deciding 1.442 + // whether to thrown an OutOfMemory error. 1.443 + // Note that the gc time limit test only works for the collections 1.444 + // of the young gen + tenured gen and not for collections of the 1.445 + // permanent gen. That is because the calculation of the space 1.446 + // freed by the collection is the free space in the young gen + 1.447 + // tenured gen. 1.448 + // Ignore explicit GC's. Ignoring explicit GC's at this level 1.449 + // is the equivalent of the GC did not happen as far as the 1.450 + // overhead calculation is concerted (i.e., the flag is not set 1.451 + // and the count is not affected). Also the average will not 1.452 + // have been updated unless UseAdaptiveSizePolicyWithSystemGC is on. 1.453 + if (!GCCause::is_user_requested_gc(gc_cause) && 1.454 + !GCCause::is_serviceability_requested_gc(gc_cause)) { 1.455 + inc_gc_time_limit_count(); 1.456 + if (UseGCOverheadLimit && 1.457 + (gc_time_limit_count() > AdaptiveSizePolicyGCTimeLimitThreshold)){ 1.458 + // All conditions have been met for throwing an out-of-memory 1.459 + _gc_time_limit_exceeded = true; 1.460 + // Avoid consecutive OOM due to the gc time limit by resetting 1.461 + // the counter. 1.462 + reset_gc_time_limit_count(); 1.463 + } 1.464 + _print_gc_time_limit_would_be_exceeded = true; 1.465 + } 1.466 + } else { 1.467 + // Did not exceed overhead limits 1.468 + reset_gc_time_limit_count(); 1.469 + } 1.470 + } 1.471 + } 1.472 + 1.473 + 1.474 + // And one last limit check, now that we've aligned things. 1.475 + if (desired_eden_size > eden_limit) { 1.476 + // If the policy says to get a larger eden but 1.477 + // is hitting the limit, don't decrease eden. 1.478 + // This can lead to a general drifting down of the 1.479 + // eden size. Let the tenuring calculation push more 1.480 + // into the old gen. 1.481 + desired_eden_size = MAX2(eden_limit, cur_eden); 1.482 + } 1.483 + desired_promo_size = MIN2(desired_promo_size, promo_limit); 1.484 + 1.485 + 1.486 + if (PrintAdaptiveSizePolicy) { 1.487 + // Timing stats 1.488 + gclog_or_tty->print( 1.489 + "PSAdaptiveSizePolicy::compute_generation_free_space: costs" 1.490 + " minor_time: %f" 1.491 + " major_cost: %f" 1.492 + " mutator_cost: %f" 1.493 + " throughput_goal: %f", 1.494 + minor_gc_cost(), major_gc_cost(), mutator_cost(), 1.495 + _throughput_goal); 1.496 + 1.497 + // We give more details if Verbose is set 1.498 + if (Verbose) { 1.499 + gclog_or_tty->print( " minor_pause: %f" 1.500 + " major_pause: %f" 1.501 + " minor_interval: %f" 1.502 + " major_interval: %f" 1.503 + " pause_goal: %f", 1.504 + _avg_minor_pause->padded_average(), 1.505 + _avg_major_pause->padded_average(), 1.506 + _avg_minor_interval->average(), 1.507 + _avg_major_interval->average(), 1.508 + gc_pause_goal_sec()); 1.509 + } 1.510 + 1.511 + // Footprint stats 1.512 + gclog_or_tty->print( " live_space: " SIZE_FORMAT 1.513 + " free_space: " SIZE_FORMAT, 1.514 + live_space(), free_space()); 1.515 + // More detail 1.516 + if (Verbose) { 1.517 + gclog_or_tty->print( " base_footprint: " SIZE_FORMAT 1.518 + " avg_young_live: " SIZE_FORMAT 1.519 + " avg_old_live: " SIZE_FORMAT, 1.520 + (size_t)_avg_base_footprint->average(), 1.521 + (size_t)avg_young_live()->average(), 1.522 + (size_t)avg_old_live()->average()); 1.523 + } 1.524 + 1.525 + // And finally, our old and new sizes. 1.526 + gclog_or_tty->print(" old_promo_size: " SIZE_FORMAT 1.527 + " old_eden_size: " SIZE_FORMAT 1.528 + " desired_promo_size: " SIZE_FORMAT 1.529 + " desired_eden_size: " SIZE_FORMAT, 1.530 + _promo_size, _eden_size, 1.531 + desired_promo_size, desired_eden_size); 1.532 + gclog_or_tty->cr(); 1.533 + } 1.534 + 1.535 + decay_supplemental_growth(is_full_gc); 1.536 + 1.537 + set_promo_size(desired_promo_size); 1.538 + set_eden_size(desired_eden_size); 1.539 +}; 1.540 + 1.541 +void PSAdaptiveSizePolicy::decay_supplemental_growth(bool is_full_gc) { 1.542 + // Decay the supplemental increment? Decay the supplement growth 1.543 + // factor even if it is not used. It is only meant to give a boost 1.544 + // to the initial growth and if it is not used, then it was not 1.545 + // needed. 1.546 + if (is_full_gc) { 1.547 + // Don't wait for the threshold value for the major collections. If 1.548 + // here, the supplemental growth term was used and should decay. 1.549 + if ((_avg_major_pause->count() % TenuredGenerationSizeSupplementDecay) 1.550 + == 0) { 1.551 + _old_gen_size_increment_supplement = 1.552 + _old_gen_size_increment_supplement >> 1; 1.553 + } 1.554 + } else { 1.555 + if ((_avg_minor_pause->count() >= AdaptiveSizePolicyReadyThreshold) && 1.556 + (_avg_minor_pause->count() % YoungGenerationSizeSupplementDecay) == 0) { 1.557 + _young_gen_size_increment_supplement = 1.558 + _young_gen_size_increment_supplement >> 1; 1.559 + } 1.560 + } 1.561 +} 1.562 + 1.563 +void PSAdaptiveSizePolicy::adjust_for_minor_pause_time(bool is_full_gc, 1.564 + size_t* desired_promo_size_ptr, size_t* desired_eden_size_ptr) { 1.565 + 1.566 + // Adjust the young generation size to reduce pause time of 1.567 + // of collections. 1.568 + // 1.569 + // The AdaptiveSizePolicyInitializingSteps test is not used 1.570 + // here. It has not seemed to be needed but perhaps should 1.571 + // be added for consistency. 1.572 + if (minor_pause_young_estimator()->decrement_will_decrease()) { 1.573 + // reduce eden size 1.574 + set_change_young_gen_for_min_pauses( 1.575 + decrease_young_gen_for_min_pauses_true); 1.576 + *desired_eden_size_ptr = *desired_eden_size_ptr - 1.577 + eden_decrement_aligned_down(*desired_eden_size_ptr); 1.578 + } else { 1.579 + // EXPERIMENTAL ADJUSTMENT 1.580 + // Only record that the estimator indicated such an action. 1.581 + // *desired_eden_size_ptr = *desired_eden_size_ptr + eden_heap_delta; 1.582 + set_change_young_gen_for_min_pauses( 1.583 + increase_young_gen_for_min_pauses_true); 1.584 + } 1.585 + if (PSAdjustTenuredGenForMinorPause) { 1.586 + // If the desired eden size is as small as it will get, 1.587 + // try to adjust the old gen size. 1.588 + if (*desired_eden_size_ptr <= _intra_generation_alignment) { 1.589 + // Vary the old gen size to reduce the young gen pause. This 1.590 + // may not be a good idea. This is just a test. 1.591 + if (minor_pause_old_estimator()->decrement_will_decrease()) { 1.592 + set_change_old_gen_for_min_pauses( 1.593 + decrease_old_gen_for_min_pauses_true); 1.594 + *desired_promo_size_ptr = 1.595 + _promo_size - promo_decrement_aligned_down(*desired_promo_size_ptr); 1.596 + } else { 1.597 + set_change_old_gen_for_min_pauses( 1.598 + increase_old_gen_for_min_pauses_true); 1.599 + size_t promo_heap_delta = 1.600 + promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr); 1.601 + if ((*desired_promo_size_ptr + promo_heap_delta) > 1.602 + *desired_promo_size_ptr) { 1.603 + *desired_promo_size_ptr = 1.604 + _promo_size + promo_heap_delta; 1.605 + } 1.606 + } 1.607 + } 1.608 + } 1.609 +} 1.610 + 1.611 +void PSAdaptiveSizePolicy::adjust_for_pause_time(bool is_full_gc, 1.612 + size_t* desired_promo_size_ptr, 1.613 + size_t* desired_eden_size_ptr) { 1.614 + 1.615 + size_t promo_heap_delta = 0; 1.616 + size_t eden_heap_delta = 0; 1.617 + // Add some checks for a threshhold for a change. For example, 1.618 + // a change less than the required alignment is probably not worth 1.619 + // attempting. 1.620 + if (is_full_gc) { 1.621 + set_decide_at_full_gc(decide_at_full_gc_true); 1.622 + } 1.623 + 1.624 + if (_avg_minor_pause->padded_average() > _avg_major_pause->padded_average()) { 1.625 + adjust_for_minor_pause_time(is_full_gc, 1.626 + desired_promo_size_ptr, 1.627 + desired_eden_size_ptr); 1.628 + // major pause adjustments 1.629 + } else if (is_full_gc) { 1.630 + // Adjust for the major pause time only at full gc's because the 1.631 + // affects of a change can only be seen at full gc's. 1.632 + 1.633 + // Reduce old generation size to reduce pause? 1.634 + if (major_pause_old_estimator()->decrement_will_decrease()) { 1.635 + // reduce old generation size 1.636 + set_change_old_gen_for_maj_pauses(decrease_old_gen_for_maj_pauses_true); 1.637 + promo_heap_delta = promo_decrement_aligned_down(*desired_promo_size_ptr); 1.638 + *desired_promo_size_ptr = _promo_size - promo_heap_delta; 1.639 + } else { 1.640 + // EXPERIMENTAL ADJUSTMENT 1.641 + // Only record that the estimator indicated such an action. 1.642 + // *desired_promo_size_ptr = _promo_size + 1.643 + // promo_increment_aligned_up(*desired_promo_size_ptr); 1.644 + set_change_old_gen_for_maj_pauses(increase_old_gen_for_maj_pauses_true); 1.645 + } 1.646 + if (PSAdjustYoungGenForMajorPause) { 1.647 + // If the promo size is at the minimum (i.e., the old gen 1.648 + // size will not actually decrease), consider changing the 1.649 + // young gen size. 1.650 + if (*desired_promo_size_ptr < _intra_generation_alignment) { 1.651 + // If increasing the young generation will decrease the old gen 1.652 + // pause, do it. 1.653 + // During startup there is noise in the statistics for deciding 1.654 + // on whether to increase or decrease the young gen size. For 1.655 + // some number of iterations, just try to increase the young 1.656 + // gen size if the major pause is too long to try and establish 1.657 + // good statistics for later decisions. 1.658 + if (major_pause_young_estimator()->increment_will_decrease() || 1.659 + (_young_gen_change_for_major_pause_count 1.660 + <= AdaptiveSizePolicyInitializingSteps)) { 1.661 + set_change_young_gen_for_maj_pauses( 1.662 + increase_young_gen_for_maj_pauses_true); 1.663 + eden_heap_delta = eden_increment_aligned_up(*desired_eden_size_ptr); 1.664 + *desired_eden_size_ptr = _eden_size + eden_heap_delta; 1.665 + _young_gen_change_for_major_pause_count++; 1.666 + } else { 1.667 + // Record that decreasing the young gen size would decrease 1.668 + // the major pause 1.669 + set_change_young_gen_for_maj_pauses( 1.670 + decrease_young_gen_for_maj_pauses_true); 1.671 + eden_heap_delta = eden_decrement_aligned_down(*desired_eden_size_ptr); 1.672 + *desired_eden_size_ptr = _eden_size - eden_heap_delta; 1.673 + } 1.674 + } 1.675 + } 1.676 + } 1.677 + 1.678 + if (PrintAdaptiveSizePolicy && Verbose) { 1.679 + gclog_or_tty->print_cr( 1.680 + "AdaptiveSizePolicy::compute_generation_free_space " 1.681 + "adjusting gen sizes for major pause (avg %f goal %f). " 1.682 + "desired_promo_size " SIZE_FORMAT "desired_eden_size " 1.683 + SIZE_FORMAT 1.684 + " promo delta " SIZE_FORMAT " eden delta " SIZE_FORMAT, 1.685 + _avg_major_pause->average(), gc_pause_goal_sec(), 1.686 + *desired_promo_size_ptr, *desired_eden_size_ptr, 1.687 + promo_heap_delta, eden_heap_delta); 1.688 + } 1.689 +} 1.690 + 1.691 +void PSAdaptiveSizePolicy::adjust_for_throughput(bool is_full_gc, 1.692 + size_t* desired_promo_size_ptr, 1.693 + size_t* desired_eden_size_ptr) { 1.694 + 1.695 + // Add some checks for a threshhold for a change. For example, 1.696 + // a change less than the required alignment is probably not worth 1.697 + // attempting. 1.698 + if (is_full_gc) { 1.699 + set_decide_at_full_gc(decide_at_full_gc_true); 1.700 + } 1.701 + 1.702 + if ((gc_cost() + mutator_cost()) == 0.0) { 1.703 + return; 1.704 + } 1.705 + 1.706 + if (PrintAdaptiveSizePolicy && Verbose) { 1.707 + gclog_or_tty->print("\nPSAdaptiveSizePolicy::adjust_for_throughput(" 1.708 + "is_full: %d, promo: " SIZE_FORMAT ", cur_eden: " SIZE_FORMAT "): ", 1.709 + is_full_gc, *desired_promo_size_ptr, *desired_eden_size_ptr); 1.710 + gclog_or_tty->print_cr("mutator_cost %f major_gc_cost %f " 1.711 + "minor_gc_cost %f", mutator_cost(), major_gc_cost(), minor_gc_cost()); 1.712 + } 1.713 + 1.714 + // Tenured generation 1.715 + if (is_full_gc) { 1.716 + 1.717 + // Calculate the change to use for the tenured gen. 1.718 + size_t scaled_promo_heap_delta = 0; 1.719 + // Can the increment to the generation be scaled? 1.720 + if (gc_cost() >= 0.0 && major_gc_cost() >= 0.0) { 1.721 + size_t promo_heap_delta = 1.722 + promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr); 1.723 + double scale_by_ratio = major_gc_cost() / gc_cost(); 1.724 + scaled_promo_heap_delta = 1.725 + (size_t) (scale_by_ratio * (double) promo_heap_delta); 1.726 + if (PrintAdaptiveSizePolicy && Verbose) { 1.727 + gclog_or_tty->print_cr( 1.728 + "Scaled tenured increment: " SIZE_FORMAT " by %f down to " 1.729 + SIZE_FORMAT, 1.730 + promo_heap_delta, scale_by_ratio, scaled_promo_heap_delta); 1.731 + } 1.732 + } else if (major_gc_cost() >= 0.0) { 1.733 + // Scaling is not going to work. If the major gc time is the 1.734 + // larger, give it a full increment. 1.735 + if (major_gc_cost() >= minor_gc_cost()) { 1.736 + scaled_promo_heap_delta = 1.737 + promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr); 1.738 + } 1.739 + } else { 1.740 + // Don't expect to get here but it's ok if it does 1.741 + // in the product build since the delta will be 0 1.742 + // and nothing will change. 1.743 + assert(false, "Unexpected value for gc costs"); 1.744 + } 1.745 + 1.746 + switch (AdaptiveSizeThroughPutPolicy) { 1.747 + case 1: 1.748 + // Early in the run the statistics might not be good. Until 1.749 + // a specific number of collections have been, use the heuristic 1.750 + // that a larger generation size means lower collection costs. 1.751 + if (major_collection_estimator()->increment_will_decrease() || 1.752 + (_old_gen_change_for_major_throughput 1.753 + <= AdaptiveSizePolicyInitializingSteps)) { 1.754 + // Increase tenured generation size to reduce major collection cost 1.755 + if ((*desired_promo_size_ptr + scaled_promo_heap_delta) > 1.756 + *desired_promo_size_ptr) { 1.757 + *desired_promo_size_ptr = _promo_size + scaled_promo_heap_delta; 1.758 + } 1.759 + set_change_old_gen_for_throughput( 1.760 + increase_old_gen_for_throughput_true); 1.761 + _old_gen_change_for_major_throughput++; 1.762 + } else { 1.763 + // EXPERIMENTAL ADJUSTMENT 1.764 + // Record that decreasing the old gen size would decrease 1.765 + // the major collection cost but don't do it. 1.766 + // *desired_promo_size_ptr = _promo_size - 1.767 + // promo_decrement_aligned_down(*desired_promo_size_ptr); 1.768 + set_change_old_gen_for_throughput( 1.769 + decrease_old_gen_for_throughput_true); 1.770 + } 1.771 + 1.772 + break; 1.773 + default: 1.774 + // Simplest strategy 1.775 + if ((*desired_promo_size_ptr + scaled_promo_heap_delta) > 1.776 + *desired_promo_size_ptr) { 1.777 + *desired_promo_size_ptr = *desired_promo_size_ptr + 1.778 + scaled_promo_heap_delta; 1.779 + } 1.780 + set_change_old_gen_for_throughput( 1.781 + increase_old_gen_for_throughput_true); 1.782 + _old_gen_change_for_major_throughput++; 1.783 + } 1.784 + 1.785 + if (PrintAdaptiveSizePolicy && Verbose) { 1.786 + gclog_or_tty->print_cr( 1.787 + "adjusting tenured gen for throughput (avg %f goal %f). " 1.788 + "desired_promo_size " SIZE_FORMAT " promo_delta " SIZE_FORMAT , 1.789 + mutator_cost(), _throughput_goal, 1.790 + *desired_promo_size_ptr, scaled_promo_heap_delta); 1.791 + } 1.792 + } 1.793 + 1.794 + // Young generation 1.795 + size_t scaled_eden_heap_delta = 0; 1.796 + // Can the increment to the generation be scaled? 1.797 + if (gc_cost() >= 0.0 && minor_gc_cost() >= 0.0) { 1.798 + size_t eden_heap_delta = 1.799 + eden_increment_with_supplement_aligned_up(*desired_eden_size_ptr); 1.800 + double scale_by_ratio = minor_gc_cost() / gc_cost(); 1.801 + assert(scale_by_ratio <= 1.0 && scale_by_ratio >= 0.0, "Scaling is wrong"); 1.802 + scaled_eden_heap_delta = 1.803 + (size_t) (scale_by_ratio * (double) eden_heap_delta); 1.804 + if (PrintAdaptiveSizePolicy && Verbose) { 1.805 + gclog_or_tty->print_cr( 1.806 + "Scaled eden increment: " SIZE_FORMAT " by %f down to " 1.807 + SIZE_FORMAT, 1.808 + eden_heap_delta, scale_by_ratio, scaled_eden_heap_delta); 1.809 + } 1.810 + } else if (minor_gc_cost() >= 0.0) { 1.811 + // Scaling is not going to work. If the minor gc time is the 1.812 + // larger, give it a full increment. 1.813 + if (minor_gc_cost() > major_gc_cost()) { 1.814 + scaled_eden_heap_delta = 1.815 + eden_increment_with_supplement_aligned_up(*desired_eden_size_ptr); 1.816 + } 1.817 + } else { 1.818 + // Don't expect to get here but it's ok if it does 1.819 + // in the product build since the delta will be 0 1.820 + // and nothing will change. 1.821 + assert(false, "Unexpected value for gc costs"); 1.822 + } 1.823 + 1.824 + // Use a heuristic for some number of collections to give 1.825 + // the averages time to settle down. 1.826 + switch (AdaptiveSizeThroughPutPolicy) { 1.827 + case 1: 1.828 + if (minor_collection_estimator()->increment_will_decrease() || 1.829 + (_young_gen_change_for_minor_throughput 1.830 + <= AdaptiveSizePolicyInitializingSteps)) { 1.831 + // Expand young generation size to reduce frequency of 1.832 + // of collections. 1.833 + if ((*desired_eden_size_ptr + scaled_eden_heap_delta) > 1.834 + *desired_eden_size_ptr) { 1.835 + *desired_eden_size_ptr = 1.836 + *desired_eden_size_ptr + scaled_eden_heap_delta; 1.837 + } 1.838 + set_change_young_gen_for_throughput( 1.839 + increase_young_gen_for_througput_true); 1.840 + _young_gen_change_for_minor_throughput++; 1.841 + } else { 1.842 + // EXPERIMENTAL ADJUSTMENT 1.843 + // Record that decreasing the young gen size would decrease 1.844 + // the minor collection cost but don't do it. 1.845 + // *desired_eden_size_ptr = _eden_size - 1.846 + // eden_decrement_aligned_down(*desired_eden_size_ptr); 1.847 + set_change_young_gen_for_throughput( 1.848 + decrease_young_gen_for_througput_true); 1.849 + } 1.850 + break; 1.851 + default: 1.852 + if ((*desired_eden_size_ptr + scaled_eden_heap_delta) > 1.853 + *desired_eden_size_ptr) { 1.854 + *desired_eden_size_ptr = 1.855 + *desired_eden_size_ptr + scaled_eden_heap_delta; 1.856 + } 1.857 + set_change_young_gen_for_throughput( 1.858 + increase_young_gen_for_througput_true); 1.859 + _young_gen_change_for_minor_throughput++; 1.860 + } 1.861 + 1.862 + if (PrintAdaptiveSizePolicy && Verbose) { 1.863 + gclog_or_tty->print_cr( 1.864 + "adjusting eden for throughput (avg %f goal %f). desired_eden_size " 1.865 + SIZE_FORMAT " eden delta " SIZE_FORMAT "\n", 1.866 + mutator_cost(), _throughput_goal, 1.867 + *desired_eden_size_ptr, scaled_eden_heap_delta); 1.868 + } 1.869 +} 1.870 + 1.871 +size_t PSAdaptiveSizePolicy::adjust_promo_for_footprint( 1.872 + size_t desired_promo_size, size_t desired_sum) { 1.873 + assert(desired_promo_size <= desired_sum, "Inconsistent parameters"); 1.874 + set_decrease_for_footprint(decrease_old_gen_for_footprint_true); 1.875 + 1.876 + size_t change = promo_decrement(desired_promo_size); 1.877 + change = scale_down(change, desired_promo_size, desired_sum); 1.878 + 1.879 + size_t reduced_size = desired_promo_size - change; 1.880 + 1.881 + if (PrintAdaptiveSizePolicy && Verbose) { 1.882 + gclog_or_tty->print_cr( 1.883 + "AdaptiveSizePolicy::compute_generation_free_space " 1.884 + "adjusting tenured gen for footprint. " 1.885 + "starting promo size " SIZE_FORMAT 1.886 + " reduced promo size " SIZE_FORMAT, 1.887 + " promo delta " SIZE_FORMAT, 1.888 + desired_promo_size, reduced_size, change ); 1.889 + } 1.890 + 1.891 + assert(reduced_size <= desired_promo_size, "Inconsistent result"); 1.892 + return reduced_size; 1.893 +} 1.894 + 1.895 +size_t PSAdaptiveSizePolicy::adjust_eden_for_footprint( 1.896 + size_t desired_eden_size, size_t desired_sum) { 1.897 + assert(desired_eden_size <= desired_sum, "Inconsistent parameters"); 1.898 + set_decrease_for_footprint(decrease_young_gen_for_footprint_true); 1.899 + 1.900 + size_t change = eden_decrement(desired_eden_size); 1.901 + change = scale_down(change, desired_eden_size, desired_sum); 1.902 + 1.903 + size_t reduced_size = desired_eden_size - change; 1.904 + 1.905 + if (PrintAdaptiveSizePolicy && Verbose) { 1.906 + gclog_or_tty->print_cr( 1.907 + "AdaptiveSizePolicy::compute_generation_free_space " 1.908 + "adjusting eden for footprint. " 1.909 + " starting eden size " SIZE_FORMAT 1.910 + " reduced eden size " SIZE_FORMAT 1.911 + " eden delta " SIZE_FORMAT, 1.912 + desired_eden_size, reduced_size, change); 1.913 + } 1.914 + 1.915 + assert(reduced_size <= desired_eden_size, "Inconsistent result"); 1.916 + return reduced_size; 1.917 +} 1.918 + 1.919 +// Scale down "change" by the factor 1.920 +// part / total 1.921 +// Don't align the results. 1.922 + 1.923 +size_t PSAdaptiveSizePolicy::scale_down(size_t change, 1.924 + double part, 1.925 + double total) { 1.926 + assert(part <= total, "Inconsistent input"); 1.927 + size_t reduced_change = change; 1.928 + if (total > 0) { 1.929 + double fraction = part / total; 1.930 + reduced_change = (size_t) (fraction * (double) change); 1.931 + } 1.932 + assert(reduced_change <= change, "Inconsistent result"); 1.933 + return reduced_change; 1.934 +} 1.935 + 1.936 +size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden, 1.937 + uint percent_change) { 1.938 + size_t eden_heap_delta; 1.939 + eden_heap_delta = cur_eden / 100 * percent_change; 1.940 + return eden_heap_delta; 1.941 +} 1.942 + 1.943 +size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden) { 1.944 + return eden_increment(cur_eden, YoungGenerationSizeIncrement); 1.945 +} 1.946 + 1.947 +size_t PSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) { 1.948 + size_t result = eden_increment(cur_eden, YoungGenerationSizeIncrement); 1.949 + return align_size_up(result, _intra_generation_alignment); 1.950 +} 1.951 + 1.952 +size_t PSAdaptiveSizePolicy::eden_increment_aligned_down(size_t cur_eden) { 1.953 + size_t result = eden_increment(cur_eden); 1.954 + return align_size_down(result, _intra_generation_alignment); 1.955 +} 1.956 + 1.957 +size_t PSAdaptiveSizePolicy::eden_increment_with_supplement_aligned_up( 1.958 + size_t cur_eden) { 1.959 + size_t result = eden_increment(cur_eden, 1.960 + YoungGenerationSizeIncrement + _young_gen_size_increment_supplement); 1.961 + return align_size_up(result, _intra_generation_alignment); 1.962 +} 1.963 + 1.964 +size_t PSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) { 1.965 + size_t eden_heap_delta = eden_decrement(cur_eden); 1.966 + return align_size_down(eden_heap_delta, _intra_generation_alignment); 1.967 +} 1.968 + 1.969 +size_t PSAdaptiveSizePolicy::eden_decrement(size_t cur_eden) { 1.970 + size_t eden_heap_delta = eden_increment(cur_eden) / 1.971 + AdaptiveSizeDecrementScaleFactor; 1.972 + return eden_heap_delta; 1.973 +} 1.974 + 1.975 +size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo, 1.976 + uint percent_change) { 1.977 + size_t promo_heap_delta; 1.978 + promo_heap_delta = cur_promo / 100 * percent_change; 1.979 + return promo_heap_delta; 1.980 +} 1.981 + 1.982 +size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo) { 1.983 + return promo_increment(cur_promo, TenuredGenerationSizeIncrement); 1.984 +} 1.985 + 1.986 +size_t PSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) { 1.987 + size_t result = promo_increment(cur_promo, TenuredGenerationSizeIncrement); 1.988 + return align_size_up(result, _intra_generation_alignment); 1.989 +} 1.990 + 1.991 +size_t PSAdaptiveSizePolicy::promo_increment_aligned_down(size_t cur_promo) { 1.992 + size_t result = promo_increment(cur_promo, TenuredGenerationSizeIncrement); 1.993 + return align_size_down(result, _intra_generation_alignment); 1.994 +} 1.995 + 1.996 +size_t PSAdaptiveSizePolicy::promo_increment_with_supplement_aligned_up( 1.997 + size_t cur_promo) { 1.998 + size_t result = promo_increment(cur_promo, 1.999 + TenuredGenerationSizeIncrement + _old_gen_size_increment_supplement); 1.1000 + return align_size_up(result, _intra_generation_alignment); 1.1001 +} 1.1002 + 1.1003 +size_t PSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) { 1.1004 + size_t promo_heap_delta = promo_decrement(cur_promo); 1.1005 + return align_size_down(promo_heap_delta, _intra_generation_alignment); 1.1006 +} 1.1007 + 1.1008 +size_t PSAdaptiveSizePolicy::promo_decrement(size_t cur_promo) { 1.1009 + size_t promo_heap_delta = promo_increment(cur_promo); 1.1010 + promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor; 1.1011 + return promo_heap_delta; 1.1012 +} 1.1013 + 1.1014 +int PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold( 1.1015 + bool is_survivor_overflow, 1.1016 + int tenuring_threshold, 1.1017 + size_t survivor_limit) { 1.1018 + assert(survivor_limit >= _intra_generation_alignment, 1.1019 + "survivor_limit too small"); 1.1020 + assert((size_t)align_size_down(survivor_limit, _intra_generation_alignment) 1.1021 + == survivor_limit, "survivor_limit not aligned"); 1.1022 + 1.1023 + // This method is called even if the tenuring threshold and survivor 1.1024 + // spaces are not adjusted so that the averages are sampled above. 1.1025 + if (!UsePSAdaptiveSurvivorSizePolicy || 1.1026 + !young_gen_policy_is_ready()) { 1.1027 + return tenuring_threshold; 1.1028 + } 1.1029 + 1.1030 + // We'll decide whether to increase or decrease the tenuring 1.1031 + // threshold based partly on the newly computed survivor size 1.1032 + // (if we hit the maximum limit allowed, we'll always choose to 1.1033 + // decrement the threshold). 1.1034 + bool incr_tenuring_threshold = false; 1.1035 + bool decr_tenuring_threshold = false; 1.1036 + 1.1037 + set_decrement_tenuring_threshold_for_gc_cost(false); 1.1038 + set_increment_tenuring_threshold_for_gc_cost(false); 1.1039 + set_decrement_tenuring_threshold_for_survivor_limit(false); 1.1040 + 1.1041 + if (!is_survivor_overflow) { 1.1042 + // Keep running averages on how much survived 1.1043 + 1.1044 + // We use the tenuring threshold to equalize the cost of major 1.1045 + // and minor collections. 1.1046 + // ThresholdTolerance is used to indicate how sensitive the 1.1047 + // tenuring threshold is to differences in cost betweent the 1.1048 + // collection types. 1.1049 + 1.1050 + // Get the times of interest. This involves a little work, so 1.1051 + // we cache the values here. 1.1052 + const double major_cost = major_gc_cost(); 1.1053 + const double minor_cost = minor_gc_cost(); 1.1054 + 1.1055 + if (minor_cost > major_cost * _threshold_tolerance_percent) { 1.1056 + // Minor times are getting too long; lower the threshold so 1.1057 + // less survives and more is promoted. 1.1058 + decr_tenuring_threshold = true; 1.1059 + set_decrement_tenuring_threshold_for_gc_cost(true); 1.1060 + } else if (major_cost > minor_cost * _threshold_tolerance_percent) { 1.1061 + // Major times are too long, so we want less promotion. 1.1062 + incr_tenuring_threshold = true; 1.1063 + set_increment_tenuring_threshold_for_gc_cost(true); 1.1064 + } 1.1065 + 1.1066 + } else { 1.1067 + // Survivor space overflow occurred, so promoted and survived are 1.1068 + // not accurate. We'll make our best guess by combining survived 1.1069 + // and promoted and count them as survivors. 1.1070 + // 1.1071 + // We'll lower the tenuring threshold to see if we can correct 1.1072 + // things. Also, set the survivor size conservatively. We're 1.1073 + // trying to avoid many overflows from occurring if defnew size 1.1074 + // is just too small. 1.1075 + 1.1076 + decr_tenuring_threshold = true; 1.1077 + } 1.1078 + 1.1079 + // The padded average also maintains a deviation from the average; 1.1080 + // we use this to see how good of an estimate we have of what survived. 1.1081 + // We're trying to pad the survivor size as little as possible without 1.1082 + // overflowing the survivor spaces. 1.1083 + size_t target_size = align_size_up((size_t)_avg_survived->padded_average(), 1.1084 + _intra_generation_alignment); 1.1085 + target_size = MAX2(target_size, _intra_generation_alignment); 1.1086 + 1.1087 + if (target_size > survivor_limit) { 1.1088 + // Target size is bigger than we can handle. Let's also reduce 1.1089 + // the tenuring threshold. 1.1090 + target_size = survivor_limit; 1.1091 + decr_tenuring_threshold = true; 1.1092 + set_decrement_tenuring_threshold_for_survivor_limit(true); 1.1093 + } 1.1094 + 1.1095 + // Finally, increment or decrement the tenuring threshold, as decided above. 1.1096 + // We test for decrementing first, as we might have hit the target size 1.1097 + // limit. 1.1098 + if (decr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) { 1.1099 + if (tenuring_threshold > 1) { 1.1100 + tenuring_threshold--; 1.1101 + } 1.1102 + } else if (incr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) { 1.1103 + if (tenuring_threshold < MaxTenuringThreshold) { 1.1104 + tenuring_threshold++; 1.1105 + } 1.1106 + } 1.1107 + 1.1108 + // We keep a running average of the amount promoted which is used 1.1109 + // to decide when we should collect the old generation (when 1.1110 + // the amount of old gen free space is less than what we expect to 1.1111 + // promote). 1.1112 + 1.1113 + if (PrintAdaptiveSizePolicy) { 1.1114 + // A little more detail if Verbose is on 1.1115 + if (Verbose) { 1.1116 + gclog_or_tty->print( " avg_survived: %f" 1.1117 + " avg_deviation: %f", 1.1118 + _avg_survived->average(), 1.1119 + _avg_survived->deviation()); 1.1120 + } 1.1121 + 1.1122 + gclog_or_tty->print( " avg_survived_padded_avg: %f", 1.1123 + _avg_survived->padded_average()); 1.1124 + 1.1125 + if (Verbose) { 1.1126 + gclog_or_tty->print( " avg_promoted_avg: %f" 1.1127 + " avg_promoted_dev: %f", 1.1128 + avg_promoted()->average(), 1.1129 + avg_promoted()->deviation()); 1.1130 + } 1.1131 + 1.1132 + gclog_or_tty->print( " avg_promoted_padded_avg: %f" 1.1133 + " avg_pretenured_padded_avg: %f" 1.1134 + " tenuring_thresh: %d" 1.1135 + " target_size: " SIZE_FORMAT, 1.1136 + avg_promoted()->padded_average(), 1.1137 + _avg_pretenured->padded_average(), 1.1138 + tenuring_threshold, target_size); 1.1139 + tty->cr(); 1.1140 + } 1.1141 + 1.1142 + set_survivor_size(target_size); 1.1143 + 1.1144 + return tenuring_threshold; 1.1145 +} 1.1146 + 1.1147 +void PSAdaptiveSizePolicy::update_averages(bool is_survivor_overflow, 1.1148 + size_t survived, 1.1149 + size_t promoted) { 1.1150 + // Update averages 1.1151 + if (!is_survivor_overflow) { 1.1152 + // Keep running averages on how much survived 1.1153 + _avg_survived->sample(survived); 1.1154 + } else { 1.1155 + size_t survived_guess = survived + promoted; 1.1156 + _avg_survived->sample(survived_guess); 1.1157 + } 1.1158 + avg_promoted()->sample(promoted + _avg_pretenured->padded_average()); 1.1159 + 1.1160 + if (PrintAdaptiveSizePolicy) { 1.1161 + gclog_or_tty->print( 1.1162 + "AdaptiveSizePolicy::compute_survivor_space_size_and_thresh:" 1.1163 + " survived: " SIZE_FORMAT 1.1164 + " promoted: " SIZE_FORMAT 1.1165 + " overflow: %s", 1.1166 + survived, promoted, is_survivor_overflow ? "true" : "false"); 1.1167 + } 1.1168 +} 1.1169 + 1.1170 +bool PSAdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st) 1.1171 + const { 1.1172 + 1.1173 + if (!UseAdaptiveSizePolicy) return false; 1.1174 + 1.1175 + return AdaptiveSizePolicy::print_adaptive_size_policy_on( 1.1176 + st, 1.1177 + PSScavenge::tenuring_threshold()); 1.1178 +}