/*
* 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 "gc_implementation/shared/adaptiveSizePolicy.hpp"
// This class keeps statistical information and computes the
// size of the heap for the concurrent mark sweep collector.
//
// Cost for garbage collector include cost for
// minor collection
// concurrent collection
// stop-the-world component
// concurrent component
// major compacting collection
// uses decaying cost
// Forward decls
class elapsedTimer;
friend class CMSGCAdaptivePolicyCounters;
friend class CMSCollector;
private:
// Total number of processors available
int _processor_count;
// Number of processors used by the concurrent phases of GC
// This number is assumed to be the same for all concurrent
// phases.
// Time that the mutators run exclusive of a particular
// phase. For example, the time the mutators run excluding
// the time during which the cms collector runs concurrently
// with the mutators.
// Between end of most recent cms reset and start of initial mark
// This may be redundant
// Between end of the most recent initial mark and start of remark
// Between end of most recent collection and start of
// a concurrent collection
// Times of the concurrent phases of the most recent
// concurrent collection
// Between end of most recent STW MSC and start of next STW MSC
// Between end of most recent MS and start of next MS
// This does not include any time spent during a concurrent
// collection.
double _latest_cms_ms_end_to_ms_start;
// Between start and end of the initial mark of the most recent
// concurrent collection.
// Between start and end of the remark phase of the most recent
// concurrent collection
// Between start and end of the most recent MS STW marking phase
// Pause time timers
// Concurrent collection timer. Used for total of all concurrent phases
// during 1 collection cycle.
// When the size of the generation is changed, the size
// of the change will rounded up or down (depending on the
// type of change) by this value.
// If this variable is true, the size of the young generation
// may be changed in order to reduce the pause(s) of the
// collection of the tenured generation in order to meet the
// pause time goal. It is common to change the size of the
// tenured generation in order to meet the pause time goal
// for the tenured generation. With the CMS collector for
// the tenured generation, the size of the young generation
// can have an significant affect on the pause times for collecting the
// tenured generation.
// This is a duplicate of a variable in PSAdaptiveSizePolicy. It
// is duplicated because it is not clear that it is general enough
// to go into AdaptiveSizePolicy.
// Variable that is set to true after a collection.
bool _first_after_collection;
// Fraction of collections that are of each type
double concurrent_fraction() const;
double STW_msc_fraction() const;
double STW_ms_fraction() const;
// This call cannot be put into the epilogue as long as some
// of the counters can be set during concurrent phases.
virtual void clear_generation_free_space_flags();
protected:
// Average of the sum of the concurrent times for
// one collection in seconds.
// Average time between concurrent collections in seconds.
// Average cost of the concurrent part of a collection
// in seconds.
// Average of the initial pause of a concurrent collection in seconds.
// Average of the remark pause of a concurrent collection in seconds.
// Average of the stop-the-world (STW) (initial mark + remark)
// times in seconds for concurrent collections.
// Average of the STW collection cost for concurrent collections.
// Average of the bytes free at the start of the sweep.
// Average of the bytes free at the end of the collection.
// Average of the bytes promoted between cms collections.
// stop-the-world (STW) mark-sweep-compact
// Average of the pause time in seconds for STW mark-sweep-compact
// collections.
// Average of the interval in seconds between STW mark-sweep-compact
// collections.
// Average of the collection costs for STW mark-sweep-compact
// collections.
// Averages for mark-sweep collections.
// The collection may have started as a background collection
// that completes in a stop-the-world (STW) collection.
// Average of the pause time in seconds for mark-sweep
// collections.
// Average of the interval in seconds between mark-sweep
// collections.
// Average of the collection costs for mark-sweep
// collections.
// These variables contain a linear fit of
// a generation size as the independent variable
// and a pause time as the dependent variable.
// For example _remark_pause_old_estimator
// is a fit of the old generation size as the
// independent variable and the remark pause
// as the dependent variable.
// remark pause time vs. cms gen size
// initial pause time vs. cms gen size
// remark pause time vs. young gen size
// initial pause time vs. young gen size
// Accessors
return _avg_concurrent_time;
}
return _avg_concurrent_interval;
}
return _avg_concurrent_gc_cost;
}
return _avg_cms_STW_time;
}
return _avg_cms_STW_gc_cost;
}
return _avg_initial_pause;
}
return _avg_remark_pause;
}
return _avg_cms_free;
}
return _avg_cms_free_at_sweep;
}
return _avg_msc_pause;
}
return _avg_msc_interval;
}
return _avg_msc_gc_cost;
}
return _avg_ms_pause;
}
return _avg_ms_interval;
}
return _avg_ms_gc_cost;
}
return _remark_pause_old_estimator;
}
return _initial_pause_old_estimator;
}
return _remark_pause_young_estimator;
}
return _initial_pause_young_estimator;
}
// These *slope() methods return the slope
// m for the linear fit of an independent
// variable vs. a dependent variable. For
// example
// remark_pause = m * old_generation_size + c
// These may be used to determine if an
// adjustment should be made to achieve a goal.
// For example, if remark_pause_old_slope() is
// positive, a reduction of the old generation
// size has on average resulted in the reduction
// of the remark pause.
float remark_pause_old_slope() {
return _remark_pause_old_estimator->slope();
}
float initial_pause_old_slope() {
return _initial_pause_old_estimator->slope();
}
float remark_pause_young_slope() {
return _remark_pause_young_estimator->slope();
}
float initial_pause_young_slope() {
return _initial_pause_young_estimator->slope();
}
// Update estimators
void update_minor_pause_old_estimator(double minor_pause_in_ms);
// Fraction of processors used by the concurrent phases.
double concurrent_processor_fraction();
// Returns the total times for the concurrent part of the
// latest collection in seconds.
double concurrent_collection_time();
// Return the total times for the concurrent part of the
// latest collection in seconds where the times of the various
// concurrent phases are scaled by the processor fraction used
// during the phase.
double scaled_concurrent_collection_time();
// Dimensionless concurrent GC cost for all the concurrent phases.
double concurrent_collection_cost(double interval_in_seconds);
// Dimensionless GC cost
virtual double time_since_major_gc() const;
// This returns the maximum average for the concurrent, ms, and
// msc collections. This is meant to be used for the calculation
// of the decayed major gc cost and is not in general the
// average of all the different types of major collections.
virtual double major_gc_interval_average_for_decay() const;
public:
double max_gc_minor_pause_sec,
double max_gc_pause_sec,
// The timers for the stop-the-world phases measure a total
// stop-the-world time. The timer is started and stopped
// for each phase but is only reset after the final checkpoint.
void checkpoint_roots_initial_begin();
void checkpoint_roots_final_begin();
// Methods for gathering information about the
// concurrent marking phase of the collection.
// Records the mutator times and
// resets the concurrent timer.
void concurrent_marking_begin();
// Resets concurrent phase timer in the begin methods and
// saves the time for a phase in the end methods.
void concurrent_marking_end();
void concurrent_sweeping_begin();
void concurrent_sweeping_end();
// Similar to the above (e.g., concurrent_marking_end()) and
// is used for both the precleaning an abortable precleaing
// phases.
void concurrent_precleaning_begin();
void concurrent_precleaning_end();
// Stops the concurrent phases time. Gathers
// information and resets the timer.
// Methods for gather information about STW Mark-Sweep-Compact
void msc_collection_begin();
// Methods for gather information about Mark-Sweep done
// in the foreground.
void ms_collection_begin();
// Cost for a mark-sweep tenured gen collection done in the foreground
double ms_gc_cost() const {
}
// Cost of collecting the tenured generation. Includes
// concurrent collection and STW collection costs
double cms_gc_cost() const;
// Cost of STW mark-sweep-compact tenured gen collection.
double msc_gc_cost() const {
}
//
double compacting_gc_cost() const {
return result;
}
// Restarts the concurrent phases timer.
void concurrent_phases_resume();
// Time beginning and end of the marking phase for
// a synchronous MS collection. A MS collection
// that finishes in the foreground can have started
// in the background. These methods capture the
// completion of the marking (after the initial
// marking) that is done in the foreground.
void ms_collection_marking_begin();
return &_concurrent_timer;
}
return _avg_cms_promo;
}
int change_young_gen_for_maj_pauses() {
return _change_young_gen_for_maj_pauses;
}
void set_change_young_gen_for_maj_pauses(int v) {
}
void clear_internal_time_intervals();
// Either calculated_promo_size_in_bytes() or promo_size()
// should be deleted.
// Cost of GC for all types of collections.
virtual double gc_cost() const;
// Calculates new survivor space size; returns a new tenuring threshold
// value. Stores new survivor size in _survivor_size.
virtual int compute_survivor_space_size_and_threshold(
bool is_survivor_overflow,
int tenuring_threshold,
// Scale down the input size by the ratio of the cost to collect the
// generation to the total GC cost.
// Return the value and clear it.
// Printing support
};
#endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSADAPTIVESIZEPOLICY_HPP