bool AdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st) const { // Should only be used with adaptive size policy turned on. // Otherwise, there may be variables that are undefined. if (!UseAdaptiveSizePolicy) return false; // Print goal for which action is needed. char* action = NULL; bool change_for_pause = false; if ((change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) || (change_young_gen_for_min_pauses() == decrease_young_gen_for_min_pauses_true)) { action = (char*) " *** pause time goal ***"; change_for_pause = true; } else if ((change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) || (change_young_gen_for_throughput() == increase_young_gen_for_througput_true)) { action = (char*) " *** throughput goal ***"; } else if (decrease_for_footprint()) { action = (char*) " *** reduced footprint ***"; } else { // No actions were taken. This can legitimately be the // situation if not enough data has been gathered to make // decisions. return false; } // Pauses // Currently the size of the old gen is only adjusted to // change the major pause times. char* young_gen_action = NULL; char* tenured_gen_action = NULL; char* shrink_msg = (char*) "(attempted to shrink)"; char* grow_msg = (char*) "(attempted to grow)"; char* no_change_msg = (char*) "(no change)"; if (change_young_gen_for_min_pauses() == decrease_young_gen_for_min_pauses_true) { young_gen_action = shrink_msg; } else if (change_for_pause) { young_gen_action = no_change_msg; } if (change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) { tenured_gen_action = shrink_msg; } else if (change_for_pause) { tenured_gen_action = no_change_msg; } // Throughput if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) { assert(change_young_gen_for_throughput() == increase_young_gen_for_througput_true, "Both generations should be growing"); young_gen_action = grow_msg; tenured_gen_action = grow_msg; } else if (change_young_gen_for_throughput() == increase_young_gen_for_througput_true) { // Only the young generation may grow at start up (before // enough full collections have been done to grow the old generation). young_gen_action = grow_msg; tenured_gen_action = no_change_msg; } // Minimum footprint if (decrease_for_footprint() != 0) { young_gen_action = shrink_msg; tenured_gen_action = shrink_msg; } st->print_cr(" UseAdaptiveSizePolicy actions to meet %s", action); st->print_cr(" GC overhead (%%)"); st->print_cr(" Young generation: %7.2f\t %s", 100.0 * avg_minor_gc_cost()->average(), young_gen_action); st->print_cr(" Tenured generation: %7.2f\t %s", 100.0 * avg_major_gc_cost()->average(), tenured_gen_action); return true; }
void PSAdaptiveSizePolicy::major_collection_end(size_t amount_live, GCCause::Cause gc_cause) { // Update the pause time. _major_timer.stop(); if (gc_cause != GCCause::_java_lang_system_gc || UseAdaptiveSizePolicyWithSystemGC) { double major_pause_in_seconds = _major_timer.seconds(); double major_pause_in_ms = major_pause_in_seconds * MILLIUNITS; // Sample for performance counter _avg_major_pause->sample(major_pause_in_seconds); // Cost of collection (unit-less) double collection_cost = 0.0; if ((_latest_major_mutator_interval_seconds > 0.0) && (major_pause_in_seconds > 0.0)) { double interval_in_seconds = _latest_major_mutator_interval_seconds + major_pause_in_seconds; collection_cost = major_pause_in_seconds / interval_in_seconds; avg_major_gc_cost()->sample(collection_cost); // Sample for performance counter _avg_major_interval->sample(interval_in_seconds); } // Calculate variables used to estimate pause time vs. gen sizes double eden_size_in_mbytes = ((double)_eden_size)/((double)M); double promo_size_in_mbytes = ((double)_promo_size)/((double)M); _major_pause_old_estimator->update(promo_size_in_mbytes, major_pause_in_ms); _major_pause_young_estimator->update(eden_size_in_mbytes, major_pause_in_ms); if (PrintAdaptiveSizePolicy && Verbose) { gclog_or_tty->print("psAdaptiveSizePolicy::major_collection_end: " "major gc cost: %f average: %f", collection_cost, avg_major_gc_cost()->average()); gclog_or_tty->print_cr(" major pause: %f major period %f", major_pause_in_ms, _latest_major_mutator_interval_seconds * MILLIUNITS); } // Calculate variable used to estimate collection cost vs. gen sizes assert(collection_cost >= 0.0, "Expected to be non-negative"); _major_collection_estimator->update(promo_size_in_mbytes, collection_cost); } // Update the amount live at the end of a full GC _live_at_last_full_gc = amount_live; // The policy does not have enough data until at least some major collections // have been done. if (_avg_major_pause->count() >= AdaptiveSizePolicyReadyThreshold) { _old_gen_policy_is_ready = true; } // Interval times use this timer to measure the interval that // the mutator runs. Reset after the GC pause has been measured. _major_timer.reset(); _major_timer.start(); }
void PSAdaptiveSizePolicy::compute_old_gen_free_space( size_t old_live, size_t cur_eden, size_t max_old_gen_size, bool is_full_gc) { // Update statistics // Time statistics are updated as we go, update footprint stats here if (is_full_gc) { // old_live is only accurate after a full gc avg_old_live()->sample(old_live); } // This code used to return if the policy was not ready , i.e., // policy_is_ready() returning false. The intent was that // decisions below needed major collection times and so could // not be made before two major collections. A consequence was // adjustments to the young generation were not done until after // two major collections even if the minor collections times // exceeded the requested goals. Now let the young generation // adjust for the minor collection times. Major collection times // will be zero for the first collection and will naturally be // ignored. Tenured generation adjustments are only made at the // full collections so until the second major collection has // been reached, no tenured generation adjustments will be made. // Until we know better, desired promotion size uses the last calculation size_t desired_promo_size = _promo_size; // Start eden at the current value. The desired value that is stored // in _eden_size is not bounded by constraints of the heap and can // run away. // // As expected setting desired_eden_size to the current // value of desired_eden_size as a starting point // caused desired_eden_size to grow way too large and caused // an overflow down stream. It may have improved performance in // some case but is dangerous. size_t desired_eden_size = cur_eden; // Cache some values. There's a bit of work getting these, so // we might save a little time. const double major_cost = major_gc_cost(); const double minor_cost = minor_gc_cost(); // Limits on our growth size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average()); // But don't force a promo size below the current promo size. Otherwise, // the promo size will shrink for no good reason. promo_limit = MAX2(promo_limit, _promo_size); const double gc_cost_limit = GCTimeLimit/100.0; // Which way should we go? // if pause requirement is not met // adjust size of any generation with average paus exceeding // the pause limit. Adjust one pause at a time (the larger) // and only make adjustments for the major pause at full collections. // else if throughput requirement not met // adjust the size of the generation with larger gc time. Only // adjust one generation at a time. // else // adjust down the total heap size. Adjust down the larger of the // generations. // Add some checks for a threshold for a change. For example, // a change less than the necessary alignment is probably not worth // attempting. if ((_avg_minor_pause->padded_average() > gc_pause_goal_sec()) || (_avg_major_pause->padded_average() > gc_pause_goal_sec())) { // // Check pauses // // Make changes only to affect one of the pauses (the larger) // at a time. if (is_full_gc) { set_decide_at_full_gc(decide_at_full_gc_true); adjust_promo_for_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size); } } else if (adjusted_mutator_cost() < _throughput_goal) { // This branch used to require that (mutator_cost() > 0.0 in 1.4.2. // This sometimes resulted in skipping to the minimize footprint // code. Change this to try and reduce GC time if mutator time is // negative for whatever reason. Or for future consideration, // bail out of the code if mutator time is negative. // // Throughput // assert(major_cost >= 0.0, "major cost is < 0.0"); assert(minor_cost >= 0.0, "minor cost is < 0.0"); // Try to reduce the GC times. if (is_full_gc) { set_decide_at_full_gc(decide_at_full_gc_true); adjust_promo_for_throughput(is_full_gc, &desired_promo_size); } } else { // Be conservative about reducing the footprint. // Do a minimum number of major collections first. // Have reasonable averages for major and minor collections costs. if (UseAdaptiveSizePolicyFootprintGoal && young_gen_policy_is_ready() && avg_major_gc_cost()->average() >= 0.0 && avg_minor_gc_cost()->average() >= 0.0) { if (is_full_gc) { set_decide_at_full_gc(decide_at_full_gc_true); size_t desired_sum = desired_eden_size + desired_promo_size; desired_promo_size = adjust_promo_for_footprint(desired_promo_size, desired_sum); } } } // Note we make the same tests as in the code block below; the code // seems a little easier to read with the printing in another block. if (desired_promo_size > promo_limit) { // "free_in_old_gen" was the original value for used for promo_limit size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); log_debug(gc, ergo)( "PSAdaptiveSizePolicy::compute_old_gen_free_space limits:" " desired_promo_size: " SIZE_FORMAT " promo_limit: " SIZE_FORMAT " free_in_old_gen: " SIZE_FORMAT " max_old_gen_size: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT, desired_promo_size, promo_limit, free_in_old_gen, max_old_gen_size, (size_t) avg_old_live()->average()); } if (gc_cost() > gc_cost_limit) { log_debug(gc, ergo)( "PSAdaptiveSizePolicy::compute_old_gen_free_space: gc time limit" " gc_cost: %f " " GCTimeLimit: " UINTX_FORMAT, gc_cost(), GCTimeLimit); } // Align everything and make a final limit check desired_promo_size = align_size_up(desired_promo_size, _space_alignment); desired_promo_size = MAX2(desired_promo_size, _space_alignment); promo_limit = align_size_down(promo_limit, _space_alignment); // And one last limit check, now that we've aligned things. desired_promo_size = MIN2(desired_promo_size, promo_limit); // Timing stats log_debug(gc, ergo)("PSAdaptiveSizePolicy::compute_old_gen_free_space: costs minor_time: %f major_cost: %f mutator_cost: %f throughput_goal: %f", minor_gc_cost(), major_gc_cost(), mutator_cost(), _throughput_goal); log_trace(gc, ergo)("Minor_pause: %f major_pause: %f minor_interval: %f major_interval: %f pause_goal: %f", _avg_minor_pause->padded_average(), _avg_major_pause->padded_average(), _avg_minor_interval->average(), _avg_major_interval->average(), gc_pause_goal_sec()); // Footprint stats log_debug(gc, ergo)("Live_space: " SIZE_FORMAT " free_space: " SIZE_FORMAT, live_space(), free_space()); log_trace(gc, ergo)("Base_footprint: " SIZE_FORMAT " avg_young_live: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT, (size_t)_avg_base_footprint->average(), (size_t)avg_young_live()->average(), (size_t)avg_old_live()->average()); log_debug(gc, ergo)("Old promo_size: " SIZE_FORMAT " desired_promo_size: " SIZE_FORMAT, _promo_size, desired_promo_size); set_promo_size(desired_promo_size); }
void PSAdaptiveSizePolicy::compute_generation_free_space(size_t young_live, size_t eden_live, size_t old_live, size_t perm_live, size_t cur_eden, size_t max_old_gen_size, size_t max_eden_size, bool is_full_gc, GCCause::Cause gc_cause) { // Update statistics // Time statistics are updated as we go, update footprint stats here _avg_base_footprint->sample(BaseFootPrintEstimate + perm_live); avg_young_live()->sample(young_live); avg_eden_live()->sample(eden_live); if (is_full_gc) { // old_live is only accurate after a full gc avg_old_live()->sample(old_live); } // This code used to return if the policy was not ready , i.e., // policy_is_ready() returning false. The intent was that // decisions below needed major collection times and so could // not be made before two major collections. A consequence was // adjustments to the young generation were not done until after // two major collections even if the minor collections times // exceeded the requested goals. Now let the young generation // adjust for the minor collection times. Major collection times // will be zero for the first collection and will naturally be // ignored. Tenured generation adjustments are only made at the // full collections so until the second major collection has // been reached, no tenured generation adjustments will be made. // Until we know better, desired promotion size uses the last calculation size_t desired_promo_size = _promo_size; // Start eden at the current value. The desired value that is stored // in _eden_size is not bounded by constraints of the heap and can // run away. // // As expected setting desired_eden_size to the current // value of desired_eden_size as a starting point // caused desired_eden_size to grow way too large and caused // an overflow down stream. It may have improved performance in // some case but is dangerous. size_t desired_eden_size = cur_eden; #ifdef ASSERT size_t original_promo_size = desired_promo_size; size_t original_eden_size = desired_eden_size; #endif // Cache some values. There's a bit of work getting these, so // we might save a little time. const double major_cost = major_gc_cost(); const double minor_cost = minor_gc_cost(); // Used for diagnostics clear_generation_free_space_flags(); // Limits on our growth size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average()); // This method sets the desired eden size. That plus the // desired survivor space sizes sets the desired young generation // size. This methods does not know what the desired survivor // size is but expects that other policy will attempt to make // the survivor sizes compatible with the live data in the // young generation. This limit is an estimate of the space left // in the young generation after the survivor spaces have been // subtracted out. size_t eden_limit = max_eden_size; // But don't force a promo size below the current promo size. Otherwise, // the promo size will shrink for no good reason. promo_limit = MAX2(promo_limit, _promo_size); const double gc_cost_limit = GCTimeLimit/100.0; // Which way should we go? // if pause requirement is not met // adjust size of any generation with average paus exceeding // the pause limit. Adjust one pause at a time (the larger) // and only make adjustments for the major pause at full collections. // else if throughput requirement not met // adjust the size of the generation with larger gc time. Only // adjust one generation at a time. // else // adjust down the total heap size. Adjust down the larger of the // generations. // Add some checks for a threshhold for a change. For example, // a change less than the necessary alignment is probably not worth // attempting. if ((_avg_minor_pause->padded_average() > gc_pause_goal_sec()) || (_avg_major_pause->padded_average() > gc_pause_goal_sec())) { // // Check pauses // // Make changes only to affect one of the pauses (the larger) // at a time. adjust_for_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size); } else if (_avg_minor_pause->padded_average() > gc_minor_pause_goal_sec()) { // Adjust only for the minor pause time goal adjust_for_minor_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size); } else if(adjusted_mutator_cost() < _throughput_goal) { // This branch used to require that (mutator_cost() > 0.0 in 1.4.2. // This sometimes resulted in skipping to the minimize footprint // code. Change this to try and reduce GC time if mutator time is // negative for whatever reason. Or for future consideration, // bail out of the code if mutator time is negative. // // Throughput // assert(major_cost >= 0.0, "major cost is < 0.0"); assert(minor_cost >= 0.0, "minor cost is < 0.0"); // Try to reduce the GC times. adjust_for_throughput(is_full_gc, &desired_promo_size, &desired_eden_size); } else { // Be conservative about reducing the footprint. // Do a minimum number of major collections first. // Have reasonable averages for major and minor collections costs. if (UseAdaptiveSizePolicyFootprintGoal && young_gen_policy_is_ready() && avg_major_gc_cost()->average() >= 0.0 && avg_minor_gc_cost()->average() >= 0.0) { size_t desired_sum = desired_eden_size + desired_promo_size; desired_eden_size = adjust_eden_for_footprint(desired_eden_size, desired_sum); if (is_full_gc) { set_decide_at_full_gc(decide_at_full_gc_true); desired_promo_size = adjust_promo_for_footprint(desired_promo_size, desired_sum); } } } // Note we make the same tests as in the code block below; the code // seems a little easier to read with the printing in another block. if (PrintAdaptiveSizePolicy) { if (desired_promo_size > promo_limit) { // "free_in_old_gen" was the original value for used for promo_limit size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); gclog_or_tty->print_cr( "PSAdaptiveSizePolicy::compute_generation_free_space limits:" " desired_promo_size: " SIZE_FORMAT " promo_limit: " SIZE_FORMAT " free_in_old_gen: " SIZE_FORMAT " max_old_gen_size: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT, desired_promo_size, promo_limit, free_in_old_gen, max_old_gen_size, (size_t) avg_old_live()->average()); } if (desired_eden_size > eden_limit) { gclog_or_tty->print_cr( "AdaptiveSizePolicy::compute_generation_free_space limits:" " desired_eden_size: " SIZE_FORMAT " old_eden_size: " SIZE_FORMAT " eden_limit: " SIZE_FORMAT " cur_eden: " SIZE_FORMAT " max_eden_size: " SIZE_FORMAT " avg_young_live: " SIZE_FORMAT, desired_eden_size, _eden_size, eden_limit, cur_eden, max_eden_size, (size_t)avg_young_live()->average()); } if (gc_cost() > gc_cost_limit) { gclog_or_tty->print_cr( "AdaptiveSizePolicy::compute_generation_free_space: gc time limit" " gc_cost: %f " " GCTimeLimit: %d", gc_cost(), GCTimeLimit); } } // Align everything and make a final limit check const size_t alignment = _intra_generation_alignment; desired_eden_size = align_size_up(desired_eden_size, alignment); desired_eden_size = MAX2(desired_eden_size, alignment); desired_promo_size = align_size_up(desired_promo_size, alignment); desired_promo_size = MAX2(desired_promo_size, alignment); eden_limit = align_size_down(eden_limit, alignment); promo_limit = align_size_down(promo_limit, alignment); // Is too much time being spent in GC? // Is the heap trying to grow beyond it's limits? const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average()); if (desired_promo_size > free_in_old_gen && desired_eden_size > eden_limit) { // eden_limit is the upper limit on the size of eden based on // the maximum size of the young generation and the sizes // of the survivor space. // The question being asked is whether the gc costs are high // and the space being recovered by a collection is low. // free_in_young_gen is the free space in the young generation // after a collection and promo_live is the free space in the old // generation after a collection. // // Use the minimum of the current value of the live in the // young gen or the average of the live in the young gen. // If the current value drops quickly, that should be taken // into account (i.e., don't trigger if the amount of free // space has suddenly jumped up). If the current is much // higher than the average, use the average since it represents // the longer term behavor. const size_t live_in_eden = MIN2(eden_live, (size_t) avg_eden_live()->average()); const size_t free_in_eden = eden_limit > live_in_eden ? eden_limit - live_in_eden : 0; const size_t total_free_limit = free_in_old_gen + free_in_eden; const size_t total_mem = max_old_gen_size + max_eden_size; const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0); if (PrintAdaptiveSizePolicy && (Verbose || (total_free_limit < (size_t) mem_free_limit))) { gclog_or_tty->print_cr( "PSAdaptiveSizePolicy::compute_generation_free_space limits:" " promo_limit: " SIZE_FORMAT " eden_limit: " SIZE_FORMAT " total_free_limit: " SIZE_FORMAT " max_old_gen_size: " SIZE_FORMAT " max_eden_size: " SIZE_FORMAT " mem_free_limit: " SIZE_FORMAT, promo_limit, eden_limit, total_free_limit, max_old_gen_size, max_eden_size, (size_t) mem_free_limit); } if (is_full_gc) { if (gc_cost() > gc_cost_limit && total_free_limit < (size_t) mem_free_limit) { // Collections, on average, are taking too much time, and // gc_cost() > gc_cost_limit // we have too little space available after a full gc. // total_free_limit < mem_free_limit // where // total_free_limit is the free space available in // both generations // total_mem is the total space available for allocation // in both generations (survivor spaces are not included // just as they are not included in eden_limit). // mem_free_limit is a fraction of total_mem judged to be an // acceptable amount that is still unused. // The heap can ask for the value of this variable when deciding // whether to thrown an OutOfMemory error. // Note that the gc time limit test only works for the collections // of the young gen + tenured gen and not for collections of the // permanent gen. That is because the calculation of the space // freed by the collection is the free space in the young gen + // tenured gen. // Ignore explicit GC's. Ignoring explicit GC's at this level // is the equivalent of the GC did not happen as far as the // overhead calculation is concerted (i.e., the flag is not set // and the count is not affected). Also the average will not // have been updated unless UseAdaptiveSizePolicyWithSystemGC is on. if (!GCCause::is_user_requested_gc(gc_cause) && !GCCause::is_serviceability_requested_gc(gc_cause)) { inc_gc_time_limit_count(); if (UseGCOverheadLimit && (gc_time_limit_count() > AdaptiveSizePolicyGCTimeLimitThreshold)){ // All conditions have been met for throwing an out-of-memory _gc_time_limit_exceeded = true; // Avoid consecutive OOM due to the gc time limit by resetting // the counter. reset_gc_time_limit_count(); } _print_gc_time_limit_would_be_exceeded = true; } } else { // Did not exceed overhead limits reset_gc_time_limit_count(); } } } // And one last limit check, now that we've aligned things. if (desired_eden_size > eden_limit) { // If the policy says to get a larger eden but // is hitting the limit, don't decrease eden. // This can lead to a general drifting down of the // eden size. Let the tenuring calculation push more // into the old gen. desired_eden_size = MAX2(eden_limit, cur_eden); } desired_promo_size = MIN2(desired_promo_size, promo_limit); if (PrintAdaptiveSizePolicy) { // Timing stats gclog_or_tty->print( "PSAdaptiveSizePolicy::compute_generation_free_space: costs" " minor_time: %f" " major_cost: %f" " mutator_cost: %f" " throughput_goal: %f", minor_gc_cost(), major_gc_cost(), mutator_cost(), _throughput_goal); // We give more details if Verbose is set if (Verbose) { gclog_or_tty->print( " minor_pause: %f" " major_pause: %f" " minor_interval: %f" " major_interval: %f" " pause_goal: %f", _avg_minor_pause->padded_average(), _avg_major_pause->padded_average(), _avg_minor_interval->average(), _avg_major_interval->average(), gc_pause_goal_sec()); } // Footprint stats gclog_or_tty->print( " live_space: " SIZE_FORMAT " free_space: " SIZE_FORMAT, live_space(), free_space()); // More detail if (Verbose) { gclog_or_tty->print( " base_footprint: " SIZE_FORMAT " avg_young_live: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT, (size_t)_avg_base_footprint->average(), (size_t)avg_young_live()->average(), (size_t)avg_old_live()->average()); } // And finally, our old and new sizes. gclog_or_tty->print(" old_promo_size: " SIZE_FORMAT " old_eden_size: " SIZE_FORMAT " desired_promo_size: " SIZE_FORMAT " desired_eden_size: " SIZE_FORMAT, _promo_size, _eden_size, desired_promo_size, desired_eden_size); gclog_or_tty->cr(); } decay_supplemental_growth(is_full_gc); set_promo_size(desired_promo_size); set_eden_size(desired_eden_size); };