/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "gc_implementation/shared/gcStats.hpp"
#include "memory/defNewGeneration.hpp"
#include "memory/genCollectedHeap.hpp"
#include "runtime/thread.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "os_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "os_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "os_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "os_bsd.inline.hpp"
#endif
// Defined if the granularity of the time measurements is potentially too large.
#define CLOCK_GRANULARITY_TOO_LARGE
double max_gc_minor_pause_sec,
double max_gc_pause_sec,
(uint) _processor_count);
} else {
}
// Mark-sweep-compact
// Mark-sweep
// Variables that estimate pause times as a function of generation
// size.
// Alignment comes from that used in ReservedSpace.
// Start the concurrent timer here so that the first
// concurrent_phases_begin() measures a finite mutator
// time. A finite mutator time is used to determine
// if a concurrent collection has been started. If this
// proves to be a problem, use some explicit flag to
// signal that a concurrent collection has been started.
_STW_timer.start();
}
// For now assume no other daemon threads are taking alway
// cpu's from the application.
return ((double) _concurrent_processor_count / (double) _processor_count);
}
double interval_in_seconds) {
// When the precleaning and sweeping phases use multiple
// threads, change one_processor_fraction to
// concurrent_processor_fraction().
double concurrent_cost =
if (PrintAdaptiveSizePolicy && Verbose) {
"\nCMSAdaptiveSizePolicy::scaled_concurrent_collection_cost(%f) "
"_latest_cms_concurrent_marking_cost %f "
"_latest_cms_concurrent_precleaning_cost %f "
"_latest_cms_concurrent_sweeping_cost %f "
"concurrent_processor_fraction %f "
"concurrent_cost %f ",
}
return concurrent_cost;
}
}
// When the precleaning and sweeping phases use multiple
// threads, change one_processor_fraction to
// concurrent_processor_fraction().
if (PrintAdaptiveSizePolicy && Verbose) {
"\nCMSAdaptiveSizePolicy::scaled_concurrent_collection_time "
"_latest_cms_concurrent_marking_time_secs %f "
"_latest_cms_concurrent_precleaning_time_secs %f "
"_latest_cms_concurrent_sweeping_time_secs %f "
"concurrent_processor_fraction %f "
"latest_cms_sum_concurrent_phases_time_secs %f ",
}
}
double minor_pause_in_ms) {
// Get the equivalent of the free space
// that is available for promotions in the CMS generation
// and use that to update _minor_pause_old_estimator
// Don't implement this until it is needed. A warning is
// printed if _minor_pause_old_estimator is used.
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
// Update the interval time
if (PrintAdaptiveSizePolicy && Verbose) {
"mutator time %f", _latest_cms_collection_end_to_collection_start_secs);
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
if (PrintAdaptiveSizePolicy && Verbose) {
":concurrent marking time (s) %f",
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
"CMSAdaptiveSizePolicy::concurrent_precleaning_begin()");
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
// May be set again by a second call during the same collection.
if (PrintAdaptiveSizePolicy && Verbose) {
":concurrent precleaning time (s) %f",
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
"CMSAdaptiveSizePolicy::concurrent_sweeping_begin()");
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
if (PrintAdaptiveSizePolicy && Verbose) {
":concurrent sweeping time (s) %f",
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
// Update the concurrent timer
// Cost of collection (unit-less)
// Total interval for collection. May not be valid. Tests
// below determine whether to use this.
//
if (PrintAdaptiveSizePolicy && Verbose) {
"_latest_cms_reset_end_to_initial_mark_start_secs %f \n"
"_latest_cms_initial_mark_start_to_end_time_secs %f \n"
"_latest_cms_remark_start_to_end_time_secs %f \n"
"_latest_cms_concurrent_marking_time_secs %f \n"
"_latest_cms_concurrent_precleaning_time_secs %f \n"
"_latest_cms_concurrent_sweeping_time_secs %f \n"
"latest_cms_sum_concurrent_phases_time_secs %f \n"
"_latest_cms_collection_end_to_collection_start_secs %f \n"
"concurrent_processor_fraction %f",
}
double interval_in_seconds =
"Bad interval between cms collections");
// Sample for performance counter
// STW costs (initial and remark pauses)
// Cost of collection (unit-less)
"Bad initial mark pause");
"Bad remark pause");
double STW_time_in_seconds =
if (interval_in_seconds > 0.0) {
// cost for the STW phases of the concurrent collection.
}
if (PrintAdaptiveSizePolicy && Verbose) {
"STW gc cost: %f average: %f", STW_collection_cost,
avg_cms_STW_gc_cost()->average());
(double) STW_time_in_seconds * MILLIUNITS,
(double) interval_in_seconds * MILLIUNITS);
}
if (latest_cms_sum_concurrent_phases_time_secs > 0.0) {
// Average this ms cost into all the other types gc costs
if (PrintAdaptiveSizePolicy && Verbose) {
"concurrent gc cost: %f average: %f",
" processor fraction: %f",
}
}
// Gather information for estimating future behavior
// This estimate uses the average eden size. It could also
// have used the latest eden size. Which is better?
}
// The concurrent phases keeps track of it's own mutator interval
// with this timer. This allows the stop-the-world phase to
// be included in the mutator time so that the stop-the-world time
// is not double counted. Reset and start it.
// The mutator time between STW phases does not include the
// concurrent collection time.
_STW_timer.reset();
_STW_timer.start();
}
// Update the interval time
_STW_timer.stop();
// Reset for the initial mark
_STW_timer.reset();
_STW_timer.start();
}
_STW_timer.stop();
if (PrintAdaptiveSizePolicy && Verbose) {
"cmsAdaptiveSizePolicy::checkpoint_roots_initial_end: "
"initial pause: %f ", _latest_cms_initial_mark_start_to_end_time_secs);
}
}
_STW_timer.reset();
_STW_timer.start();
}
_STW_timer.stop();
// Start accumumlating time for the remark in the STW timer.
_STW_timer.reset();
_STW_timer.start();
}
_STW_timer.stop();
// Total initial mark pause + remark pause.
// Sample total for initial mark + remark
if (PrintAdaptiveSizePolicy && Verbose) {
"remark pause: %f", _latest_cms_remark_start_to_end_time_secs);
}
}
// Don't start the STW times here because the concurrent
// sweep and reset has not happened.
// Keep the old comment above in case I don't understand
// what is going on but now
// Start the STW timer because it is used by ms_collection_begin()
// and ms_collection_end() to get the sweep time if a MS is being
// done in the foreground.
_STW_timer.reset();
_STW_timer.start();
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
_STW_timer.stop();
if (PrintAdaptiveSizePolicy && Verbose) {
"mutator time %f",
}
_STW_timer.reset();
_STW_timer.start();
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
_STW_timer.stop();
if ((_latest_cms_msc_end_to_msc_start_time_secs > 0.0) &&
(msc_pause_in_seconds > 0.0)) {
if (_latest_cms_collection_end_to_collection_start_secs == 0.0) {
// This assertion may fail because of time stamp gradularity.
// Comment it out and investiage it at a later time. The large
// time stamp granularity occurs on some older linux systems.
#ifndef CLOCK_GRANULARITY_TOO_LARGE
(_latest_cms_concurrent_precleaning_time_secs == 0.0) &&
"There should not be any concurrent time");
#endif
// A concurrent collection did not start. Mutator time
// between collections comes from the STW MSC timer.
} else {
// The concurrent collection did start so count the mutator
// time to the start of the concurrent collection. In this
// case the _latest_cms_msc_end_to_msc_start_time_secs measures
// the time between the initial mark or remark and the
// start of the MSC. That has no real meaning.
}
double interval_in_seconds =
if (PrintAdaptiveSizePolicy && Verbose) {
" mutator_time_in_seconds %f \n"
" _latest_cms_initial_mark_start_to_end_time_secs %f\n"
" _latest_cms_remark_start_to_end_time_secs %f\n"
" latest_cms_sum_concurrent_phases_time_secs %f\n"
" msc_pause_in_seconds %f\n",
}
// The concurrent cost is wasted cost but it should be
// included.
// Initial mark and remark, also wasted.
double STW_collection_cost =
if (PrintAdaptiveSizePolicy && Verbose) {
"_latest_cms_collection_end_to_collection_start_secs %f\n"
"_latest_cms_msc_end_to_msc_start_time_secs %f\n"
"_latest_cms_initial_mark_start_to_end_time_secs %f\n"
"_latest_cms_remark_start_to_end_time_secs %f\n"
"latest_cms_sum_concurrent_phases_time_secs %f\n",
"latest_cms_sum_concurrent_phases_time_secs %f\n"
"STW_time_in_seconds %f\n"
"msc_pause_in_seconds %f\n",
}
// Average this ms cost into all the other types gc costs
// Sample for performance counter
if (PrintAdaptiveSizePolicy && Verbose) {
"MSC gc cost: %f average: %f", cost,
_avg_msc_gc_cost->average());
}
}
}
// Can this call be put into the epilogue?
// The concurrent phases keeps track of it's own mutator interval
// with this timer. This allows the stop-the-world phase to
// be included in the mutator time so that the stop-the-world time
// is not double counted. Reset and start it.
_STW_timer.reset();
_STW_timer.start();
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
_STW_timer.stop();
if (PrintAdaptiveSizePolicy && Verbose) {
"mutator time %f",
}
_STW_timer.reset();
_STW_timer.start();
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
_STW_timer.stop();
// The MS collection is a foreground collection that does all
// the parts of a mostly concurrent collection.
//
// For this collection include the cost of the
// initial mark
// remark
// all concurrent time (scaled down by the
// concurrent_processor_fraction). Some
// may be zero if the baton was passed before
// it was reached.
// concurrent marking
// sweeping
// resetting
// STW after baton was passed (STW_in_foreground_in_seconds)
if (PrintAdaptiveSizePolicy && Verbose) {
"STW_in_foreground_in_seconds %f "
"_latest_cms_initial_mark_start_to_end_time_secs %f "
"_latest_cms_remark_start_to_end_time_secs %f "
"latest_cms_sum_concurrent_phases_time_secs %f "
"_latest_cms_ms_marking_start_to_end_time_secs %f "
"_latest_cms_ms_end_to_ms_start %f",
}
#ifndef CLOCK_GRANULARITY_TOO_LARGE
"marking done twice?");
#endif
// Use the STW costs from the initial mark and remark plus
// the cost of the concurrent phase to calculate a
// collection cost.
if ((_latest_cms_ms_end_to_ms_start > 0.0) &&
(ms_time_in_seconds > 0.0)) {
double interval_in_seconds =
if (PrintAdaptiveSizePolicy && Verbose) {
"latest_cms_sum_concurrent_phases_time_secs %f "
"interval_in_seconds %f",
}
// Average this ms cost into all the other types gc costs
// Sample for performance counter
}
if (PrintAdaptiveSizePolicy && Verbose) {
}
}
// Consider putting this code (here to end) into a
// method for convenience.
// The concurrent phases keeps track of it's own mutator interval
// with this timer. This allows the stop-the-world phase to
// be included in the mutator time so that the stop-the-world time
// is not double counted. Reset and start it.
_STW_timer.reset();
_STW_timer.start();
}
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
gclog_or_tty->stamp();
}
}
_STW_timer.stop();
_STW_timer.start();
}
}
return avg_major_gc_cost()->average();
}
_STW_timer.stop();
// Start accumumlating time for the marking in the STW timer.
_STW_timer.reset();
_STW_timer.start();
}
_STW_timer.stop();
if (PrintAdaptiveSizePolicy && Verbose) {
"msc_collection_marking_end: mutator time %f",
}
}
_STW_timer.reset();
_STW_timer.start();
}
return result;
}
// Cost of collection (unit-less)
double interval_in_seconds) {
// Cost of collection (unit-less)
if ((interval_in_seconds > 0.0) &&
(pause_in_seconds > 0.0)) {
cost =
}
return cost;
}
// reduce eden size
if (PrintAdaptiveSizePolicy && Verbose) {
"CMSAdaptiveSizePolicy::adjust_eden_for_pause_time "
"adjusting eden for pause time. "
" starting eden size " SIZE_FORMAT
" reduced eden size " SIZE_FORMAT
" eden delta " SIZE_FORMAT,
}
return desired_eden;
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
"CMSAdaptiveSizePolicy::adjust_eden_for_throughput "
"adjusting eden for throughput. "
" starting eden size " SIZE_FORMAT
" increased eden size " SIZE_FORMAT
" eden delta " SIZE_FORMAT,
}
return desired_eden;
}
if (PrintAdaptiveSizePolicy && Verbose) {
"CMSAdaptiveSizePolicy::adjust_eden_for_footprint "
"adjusting eden for footprint. "
" starting eden size " SIZE_FORMAT
" reduced eden size " SIZE_FORMAT
" eden delta " SIZE_FORMAT,
}
return desired_eden_size;
}
// The eden and promo versions should be combined if possible.
// They are the same except that the sizes of the decrement
// and increment are different for eden and promo.
}
}
}
}
{
// Printout input
if (PrintGC && PrintAdaptiveSizePolicy) {
"CMSAdaptiveSizePolicy::compute_young_generation_free_space: "
"cur_eden " SIZE_FORMAT,
cur_eden);
}
// Used for diagnostics
if (minor_pause_young_estimator()->decrement_will_decrease()) {
// If the minor pause is too long, shrink the young gen.
}
// The remark or initial pauses are not meeting the goal. Should
// the generation be shrunk?
if (get_and_clear_first_after_collection() &&
// If the remark or initial pause is too long and this is the
// first young gen collection after a cms collection, shrink
// the young gen.
}
// If not the first young gen collection after a cms collection,
// don't do anything. In this case an adjustment has already
// been made and the results of the adjustment has not yet been
// measured.
} else if ((minor_gc_cost() >= 0.0) &&
(adjusted_mutator_cost() < _throughput_goal)) {
} else {
}
if (PrintGC && PrintAdaptiveSizePolicy) {
"CMSAdaptiveSizePolicy::compute_young_generation_free_space limits:"
" desired_eden_size: " SIZE_FORMAT
" old_eden_size: " SIZE_FORMAT,
}
}
// Move this test up to caller like the adjust_eden_for_pause_time()
// call.
if ((AdaptiveSizePausePolicy == 0) &&
} else if ((AdaptiveSizePausePolicy > 0) &&
}
"CMSAdaptiveSizePolicy::adjust_promo_for_pause_time "
"adjusting promo for pause time. "
" starting promo size " SIZE_FORMAT
" reduced promo size " SIZE_FORMAT
" promo delta " SIZE_FORMAT,
}
return desired_promo;
}
// Try to share this with PS.
double gen_gc_cost) {
// Calculate the change to use for the tenured gen.
// Can the increment to the generation be scaled?
if (PrintAdaptiveSizePolicy && Verbose) {
}
} else if (gen_gc_cost >= 0.0) {
// Scaling is not going to work. If the major gc time is the
// larger than the other GC costs, give it a full increment.
}
} else {
// Don't expect to get here but it's ok if it does
// in the product build since the delta will be 0
// and nothing will change.
assert(false, "Unexpected value for gc costs");
}
return scaled_change;
}
}
if (PrintAdaptiveSizePolicy && Verbose) {
"CMSAdaptiveSizePolicy::adjust_promo_for_throughput "
"adjusting promo for throughput. "
" starting promo size " SIZE_FORMAT
" increased promo size " SIZE_FORMAT
" promo delta " SIZE_FORMAT,
}
return desired_promo;
}
if (PrintAdaptiveSizePolicy && Verbose) {
"CMSAdaptiveSizePolicy::adjust_promo_for_footprint "
"adjusting promo for footprint. "
" starting promo size " SIZE_FORMAT
" reduced promo size " SIZE_FORMAT
" promo delta " SIZE_FORMAT,
}
return desired_promo_size;
}
// any connection to the read free space
// Printout input
if (PrintGC && PrintAdaptiveSizePolicy) {
"CMSAdaptiveSizePolicy::compute_tenured_generation_free_space: "
"cur_tenured_free " SIZE_FORMAT
" max_tenured_available " SIZE_FORMAT,
}
// Used for diagnostics
// Nothing to do since the minor collections are too large and
// this method only deals with the cms generation.
} else if ((cms_gc_cost() >= 0.0) &&
(adjusted_mutator_cost() < _throughput_goal)) {
} else {
cur_eden);
}
if (PrintGC && PrintAdaptiveSizePolicy) {
"CMSAdaptiveSizePolicy::compute_tenured_generation_free_space limits:"
" desired_promo_size: " SIZE_FORMAT
" old_promo_size: " SIZE_FORMAT,
}
}
bool is_survivor_overflow,
int tenuring_threshold,
"survivor_limit too small");
== survivor_limit, "survivor_limit not aligned");
// Change UsePSAdaptiveSurvivorSizePolicy -> UseAdaptiveSurvivorSizePolicy?
if (!UsePSAdaptiveSurvivorSizePolicy ||
return tenuring_threshold;
}
// We'll decide whether to increase or decrease the tenuring
// threshold based partly on the newly computed survivor size
// (if we hit the maximum limit allowed, we'll always choose to
// decrement the threshold).
bool incr_tenuring_threshold = false;
bool decr_tenuring_threshold = false;
if (!is_survivor_overflow) {
// Keep running averages on how much survived
// We use the tenuring threshold to equalize the cost of major
// and minor collections.
// ThresholdTolerance is used to indicate how sensitive the
// tenuring threshold is to differences in cost betweent the
// collection types.
// Get the times of interest. This involves a little work, so
// we cache the values here.
// Minor times are getting too long; lower the threshold so
// less survives and more is promoted.
decr_tenuring_threshold = true;
// Major times are too long, so we want less promotion.
incr_tenuring_threshold = true;
}
} else {
// Survivor space overflow occurred, so promoted and survived are
// not accurate. We'll make our best guess by combining survived
// and promoted and count them as survivors.
//
// We'll lower the tenuring threshold to see if we can correct
// things. Also, set the survivor size conservatively. We're
// trying to avoid many overflows from occurring if defnew size
// is just too small.
decr_tenuring_threshold = true;
}
// The padded average also maintains a deviation from the average;
// we use this to see how good of an estimate we have of what survived.
// We're trying to pad the survivor size as little as possible without
// overflowing the survivor spaces.
if (target_size > survivor_limit) {
// Target size is bigger than we can handle. Let's also reduce
// the tenuring threshold.
decr_tenuring_threshold = true;
}
// Finally, increment or decrement the tenuring threshold, as decided above.
// We test for decrementing first, as we might have hit the target size
// limit.
if (tenuring_threshold > 1) {
}
if (tenuring_threshold < MaxTenuringThreshold) {
}
}
// We keep a running average of the amount promoted which is used
// to decide when we should collect the old generation (when
// the amount of old gen free space is less than what we expect to
// promote).
if (PrintAdaptiveSizePolicy) {
// A little more detail if Verbose is on
if (Verbose) {
" avg_deviation: %f",
_avg_survived->average(),
_avg_survived->deviation());
}
if (Verbose) {
" avg_promoted_dev: %f",
}
" avg_pretenured_padded_avg: %f"
" tenuring_thresh: %d"
" target_size: " SIZE_FORMAT
" survivor_limit: " SIZE_FORMAT,
gclog_or_tty->cr();
}
return tenuring_threshold;
}
_first_after_collection = false;
return result;
}
outputStream* st) const {
if (!UseAdaptiveSizePolicy) return false;
return
st,
}