/*
* 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"
#include "gc_implementation/shared/gcStats.hpp"
#include "gc_implementation/shared/gcUtil.hpp"
#include "gc_interface/gcCause.hpp"
// This class keeps statistical information and computes the
// optimal free space for both the young and old generation
// based on current application characteristics (based on gc cost
// and application footprint).
//
// It also computes an optimal tenuring threshold between the young
// and old generations, so as to equalize the cost of collections
// of those generations, as well as optimial survivor space sizes
// for the young generation.
//
// While this class is specifically intended for a generational system
// consisting of a young gen (containing an Eden and two semi-spaces)
// and a tenured gen, as well as a perm gen for reflective data, it
// makes NO references to specific generations.
//
// 05/02/2003 Update
// The 1.5 policy makes use of data gathered for the costs of GC on
// specific generations. That data does reference specific
// generation. Also diagnostics specific to generations have
// been added.
// Forward decls
class elapsedTimer;
class GenerationSizer;
friend class PSGCAdaptivePolicyCounters;
private:
// These values are used to record decisions made during the
// policy. For example, if the young generation was decreased
// to decrease the GC cost of minor collections the value
// decrease_young_gen_for_throughput_true is used.
// Last calculated sizes, in bytes, and aligned
// NEEDS_CLEANUP should use sizes.hpp, but it works in ints, not size_t's
// Time statistics
// Footprint statistics
// Statistical data gathered for GC
const double _collection_cost_margin_fraction;
// Variable for estimating the major and minor pause times.
// These variables represent linear least-squares fits of
// the data.
// major pause time vs. old gen size
// major pause time vs. young gen size
// These record the most recent collection times. They
// are available as an alternative to using the averages
// for making ergonomic decisions.
// The amount of live data in the heap at the last full GC, used
// as a baseline to help us determine when we need to perform the
// next full GC.
// Flag indicating that the adaptive policy is ready to use
bool _old_gen_policy_is_ready;
// Changing the generation sizing depends on the data that is
// gathered about the effects of changes on the pause times and
// throughput. These variable count the number of data points
// gathered. The policy may use these counters as a threshhold
// for reliable data.
// To facilitate faster growth at start up, supplement the normal
// growth percentage for the young gen eden and the
// old gen space for promotion with these value which decay
// with increasing collections.
// The number of bytes absorbed from eden into the old gen by moving the
// boundary over live data.
private:
// Accessors
// Change the young generation size to achieve a minor GC pause time goal
void adjust_for_minor_pause_time(bool is_full_gc,
// Change the generation sizes to achieve a GC pause time goal
// Returned sizes are not necessarily aligned.
void adjust_for_pause_time(bool is_full_gc,
// Change the generation sizes to achieve an application throughput goal
// Returned sizes are not necessarily aligned.
void adjust_for_throughput(bool is_full_gc,
// Change the generation sizes to achieve minimum footprint
// Returned sizes are not aligned.
// Size in bytes for an increment or decrement of eden.
// Size in bytes for an increment or decrement of the promotion area
// Decay the supplemental growth additive.
void decay_supplemental_growth(bool is_full_gc);
// Returns a change that has been scaled down. Result
// is not aligned. (If useful, move to some shared
// location.)
protected:
// Time accessors
// Footprint accessors
avg_young_live()->average() +
avg_old_live()->average());
}
return _eden_size + _promo_size;
}
}
}
// Update estimators
void update_minor_pause_old_estimator(double minor_pause_in_ms);
public:
// Use by ASPSYoungGen and ASPSOldGen to limit boundary moving.
// Accessors for use by performance counters
return _gc_stats.avg_promoted();
}
return _avg_base_footprint;
}
// Input arguments are initial free space sizes for young and old
// generations, the initial survivor space size, the
// alignment values and the pause & throughput goals.
//
// NEEDS_CLEANUP this is a singleton object
double gc_pause_goal_sec,
double gc_minor_pause_goal_sec,
// Methods indicating events of interest to the adaptive size policy,
// called by GC algorithms. It is the responsibility of users of this
// policy to call these methods at the correct times!
void major_collection_begin();
//
}
// Accessors
// NEEDS_CLEANUP should use sizes.hpp
}
}
}
}
int change_young_gen_for_maj_pauses() {
return _change_young_gen_for_maj_pauses;
}
void set_change_young_gen_for_maj_pauses(int v) {
}
int change_old_gen_for_min_pauses() {
return _change_old_gen_for_min_pauses;
}
void set_change_old_gen_for_min_pauses(int v) {
}
// Return true if the old generation size was changed
// to try to reach a pause time goal.
bool old_gen_changed_for_pauses() {
return result;
}
// Return true if the young generation size was changed
// to try to reach a pause time goal.
bool young_gen_changed_for_pauses() {
return result;
}
// end flags for pause goal
// Return true if the old generation size was changed
// to try to reach a throughput goal.
bool old_gen_changed_for_throughput() {
return result;
}
// Return true if the young generation size was changed
// to try to reach a throughput goal.
bool young_gen_changed_for_throughput() {
return result;
}
// Accessors for estimators. The slope of the linear fit is
// currently all that is used for making decisions.
return _major_pause_old_estimator;
}
return _major_pause_young_estimator;
}
virtual void clear_generation_free_space_flags();
float major_pause_young_slope() {
return _major_pause_young_estimator->slope();
}
// Given the amount of live data in the heap, should we
// perform a Full GC?
// Calculates optimial free space sizes for both the old and young
// generations. Stores results in _eden_size and _promo_size.
// Takes current used space in all generations as input, as well
// as an indication if a full gc has just been performed, for use
// in deciding if an OOM error should be thrown.
bool is_full_gc,
// Calculates new survivor space size; returns a new tenuring threshold
// value. Stores new survivor size in _survivor_size.
int tenuring_threshold,
// Return the maximum size of a survivor space if the young generation were of
// size gen_size.
// Never allow the target survivor size to grow more than MinSurvivorRatio
// of the young generation size. We cannot grow into a two semi-space
// system, with Eden zero sized. Even if the survivor space grows, from()
// might grow by moving the bottom boundary "down" -- so from space will
// remain almost full anyway (top() will be near end(), but there will be a
// large filler object at the bottom).
}
return _live_at_last_full_gc;
}
}
// Update averages that are always used (even
// if adaptive sizing is turned off).
void update_averages(bool is_survivor_overflow,
// Printing support
};
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP