0N/A/*
1472N/A * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP
1879N/A
1879N/A#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
1879N/A#include "gc_implementation/shared/gcStats.hpp"
1879N/A#include "gc_implementation/shared/gcUtil.hpp"
1879N/A#include "gc_interface/gcCause.hpp"
1879N/A
0N/A// This class keeps statistical information and computes the
0N/A// optimal free space for both the young and old generation
0N/A// based on current application characteristics (based on gc cost
0N/A// and application footprint).
0N/A//
0N/A// It also computes an optimal tenuring threshold between the young
0N/A// and old generations, so as to equalize the cost of collections
0N/A// of those generations, as well as optimial survivor space sizes
0N/A// for the young generation.
0N/A//
0N/A// While this class is specifically intended for a generational system
0N/A// consisting of a young gen (containing an Eden and two semi-spaces)
0N/A// and a tenured gen, as well as a perm gen for reflective data, it
0N/A// makes NO references to specific generations.
0N/A//
0N/A// 05/02/2003 Update
0N/A// The 1.5 policy makes use of data gathered for the costs of GC on
0N/A// specific generations. That data does reference specific
0N/A// generation. Also diagnostics specific to generations have
0N/A// been added.
0N/A
0N/A// Forward decls
0N/Aclass elapsedTimer;
1387N/Aclass GenerationSizer;
0N/A
0N/Aclass PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
0N/A friend class PSGCAdaptivePolicyCounters;
0N/A private:
0N/A // These values are used to record decisions made during the
0N/A // policy. For example, if the young generation was decreased
0N/A // to decrease the GC cost of minor collections the value
0N/A // decrease_young_gen_for_throughput_true is used.
0N/A
0N/A // Last calculated sizes, in bytes, and aligned
0N/A // NEEDS_CLEANUP should use sizes.hpp, but it works in ints, not size_t's
0N/A
0N/A // Time statistics
0N/A AdaptivePaddedAverage* _avg_major_pause;
0N/A
0N/A // Footprint statistics
0N/A AdaptiveWeightedAverage* _avg_base_footprint;
0N/A
0N/A // Statistical data gathered for GC
0N/A GCStats _gc_stats;
0N/A
0N/A size_t _survivor_size_limit; // Limit in bytes of survivor size
0N/A const double _collection_cost_margin_fraction;
0N/A
0N/A // Variable for estimating the major and minor pause times.
0N/A // These variables represent linear least-squares fits of
0N/A // the data.
0N/A // major pause time vs. old gen size
0N/A LinearLeastSquareFit* _major_pause_old_estimator;
0N/A // major pause time vs. young gen size
0N/A LinearLeastSquareFit* _major_pause_young_estimator;
0N/A
0N/A
0N/A // These record the most recent collection times. They
0N/A // are available as an alternative to using the averages
0N/A // for making ergonomic decisions.
0N/A double _latest_major_mutator_interval_seconds;
0N/A
0N/A const size_t _intra_generation_alignment; // alignment for eden, survivors
0N/A
0N/A const double _gc_minor_pause_goal_sec; // goal for maximum minor gc pause
0N/A
0N/A // The amount of live data in the heap at the last full GC, used
0N/A // as a baseline to help us determine when we need to perform the
0N/A // next full GC.
0N/A size_t _live_at_last_full_gc;
0N/A
0N/A // decrease/increase the old generation for minor pause time
0N/A int _change_old_gen_for_min_pauses;
0N/A
0N/A // increase/decrease the young generation for major pause time
0N/A int _change_young_gen_for_maj_pauses;
0N/A
0N/A
0N/A // Flag indicating that the adaptive policy is ready to use
0N/A bool _old_gen_policy_is_ready;
0N/A
0N/A // Changing the generation sizing depends on the data that is
0N/A // gathered about the effects of changes on the pause times and
0N/A // throughput. These variable count the number of data points
0N/A // gathered. The policy may use these counters as a threshhold
0N/A // for reliable data.
0N/A julong _young_gen_change_for_major_pause_count;
0N/A
0N/A // To facilitate faster growth at start up, supplement the normal
0N/A // growth percentage for the young gen eden and the
0N/A // old gen space for promotion with these value which decay
0N/A // with increasing collections.
0N/A uint _young_gen_size_increment_supplement;
0N/A uint _old_gen_size_increment_supplement;
0N/A
0N/A // The number of bytes absorbed from eden into the old gen by moving the
0N/A // boundary over live data.
0N/A size_t _bytes_absorbed_from_eden;
0N/A
0N/A private:
0N/A
0N/A // Accessors
0N/A AdaptivePaddedAverage* avg_major_pause() const { return _avg_major_pause; }
0N/A double gc_minor_pause_goal_sec() const { return _gc_minor_pause_goal_sec; }
0N/A
0N/A // Change the young generation size to achieve a minor GC pause time goal
0N/A void adjust_for_minor_pause_time(bool is_full_gc,
0N/A size_t* desired_promo_size_ptr,
0N/A size_t* desired_eden_size_ptr);
0N/A // Change the generation sizes to achieve a GC pause time goal
0N/A // Returned sizes are not necessarily aligned.
0N/A void adjust_for_pause_time(bool is_full_gc,
0N/A size_t* desired_promo_size_ptr,
0N/A size_t* desired_eden_size_ptr);
0N/A // Change the generation sizes to achieve an application throughput goal
0N/A // Returned sizes are not necessarily aligned.
0N/A void adjust_for_throughput(bool is_full_gc,
0N/A size_t* desired_promo_size_ptr,
0N/A size_t* desired_eden_size_ptr);
0N/A // Change the generation sizes to achieve minimum footprint
0N/A // Returned sizes are not aligned.
0N/A size_t adjust_promo_for_footprint(size_t desired_promo_size,
0N/A size_t desired_total);
0N/A size_t adjust_eden_for_footprint(size_t desired_promo_size,
0N/A size_t desired_total);
0N/A
0N/A // Size in bytes for an increment or decrement of eden.
0N/A virtual size_t eden_increment(size_t cur_eden, uint percent_change);
0N/A virtual size_t eden_decrement(size_t cur_eden);
0N/A size_t eden_decrement_aligned_down(size_t cur_eden);
0N/A size_t eden_increment_with_supplement_aligned_up(size_t cur_eden);
0N/A
0N/A // Size in bytes for an increment or decrement of the promotion area
0N/A virtual size_t promo_increment(size_t cur_promo, uint percent_change);
0N/A virtual size_t promo_decrement(size_t cur_promo);
0N/A size_t promo_decrement_aligned_down(size_t cur_promo);
0N/A size_t promo_increment_with_supplement_aligned_up(size_t cur_promo);
0N/A
0N/A // Decay the supplemental growth additive.
0N/A void decay_supplemental_growth(bool is_full_gc);
0N/A
0N/A // Returns a change that has been scaled down. Result
0N/A // is not aligned. (If useful, move to some shared
0N/A // location.)
0N/A size_t scale_down(size_t change, double part, double total);
0N/A
0N/A protected:
0N/A // Time accessors
0N/A
0N/A // Footprint accessors
0N/A size_t live_space() const {
0N/A return (size_t)(avg_base_footprint()->average() +
0N/A avg_young_live()->average() +
0N/A avg_old_live()->average());
0N/A }
0N/A size_t free_space() const {
0N/A return _eden_size + _promo_size;
0N/A }
0N/A
0N/A void set_promo_size(size_t new_size) {
0N/A _promo_size = new_size;
0N/A }
0N/A void set_survivor_size(size_t new_size) {
0N/A _survivor_size = new_size;
0N/A }
0N/A
0N/A // Update estimators
0N/A void update_minor_pause_old_estimator(double minor_pause_in_ms);
0N/A
0N/A virtual GCPolicyKind kind() const { return _gc_ps_adaptive_size_policy; }
0N/A
0N/A public:
0N/A // Use by ASPSYoungGen and ASPSOldGen to limit boundary moving.
0N/A size_t eden_increment_aligned_up(size_t cur_eden);
0N/A size_t eden_increment_aligned_down(size_t cur_eden);
0N/A size_t promo_increment_aligned_up(size_t cur_promo);
0N/A size_t promo_increment_aligned_down(size_t cur_promo);
0N/A
0N/A virtual size_t eden_increment(size_t cur_eden);
0N/A virtual size_t promo_increment(size_t cur_promo);
0N/A
0N/A // Accessors for use by performance counters
0N/A AdaptivePaddedNoZeroDevAverage* avg_promoted() const {
0N/A return _gc_stats.avg_promoted();
0N/A }
0N/A AdaptiveWeightedAverage* avg_base_footprint() const {
0N/A return _avg_base_footprint;
0N/A }
0N/A
0N/A // Input arguments are initial free space sizes for young and old
0N/A // generations, the initial survivor space size, the
0N/A // alignment values and the pause & throughput goals.
0N/A //
0N/A // NEEDS_CLEANUP this is a singleton object
0N/A PSAdaptiveSizePolicy(size_t init_eden_size,
0N/A size_t init_promo_size,
0N/A size_t init_survivor_size,
0N/A size_t intra_generation_alignment,
0N/A double gc_pause_goal_sec,
0N/A double gc_minor_pause_goal_sec,
0N/A uint gc_time_ratio);
0N/A
0N/A // Methods indicating events of interest to the adaptive size policy,
0N/A // called by GC algorithms. It is the responsibility of users of this
0N/A // policy to call these methods at the correct times!
0N/A void major_collection_begin();
0N/A void major_collection_end(size_t amount_live, GCCause::Cause gc_cause);
0N/A
0N/A //
0N/A void tenured_allocation(size_t size) {
0N/A _avg_pretenured->sample(size);
0N/A }
0N/A
0N/A // Accessors
0N/A // NEEDS_CLEANUP should use sizes.hpp
0N/A
0N/A size_t calculated_old_free_size_in_bytes() const {
0N/A return (size_t)(_promo_size + avg_promoted()->padded_average());
0N/A }
0N/A
0N/A size_t average_old_live_in_bytes() const {
0N/A return (size_t) avg_old_live()->average();
0N/A }
0N/A
0N/A size_t average_promoted_in_bytes() const {
0N/A return (size_t)avg_promoted()->average();
0N/A }
0N/A
0N/A size_t padded_average_promoted_in_bytes() const {
0N/A return (size_t)avg_promoted()->padded_average();
0N/A }
0N/A
0N/A int change_young_gen_for_maj_pauses() {
0N/A return _change_young_gen_for_maj_pauses;
0N/A }
0N/A void set_change_young_gen_for_maj_pauses(int v) {
0N/A _change_young_gen_for_maj_pauses = v;
0N/A }
0N/A
0N/A int change_old_gen_for_min_pauses() {
0N/A return _change_old_gen_for_min_pauses;
0N/A }
0N/A void set_change_old_gen_for_min_pauses(int v) {
0N/A _change_old_gen_for_min_pauses = v;
0N/A }
0N/A
0N/A // Return true if the old generation size was changed
0N/A // to try to reach a pause time goal.
0N/A bool old_gen_changed_for_pauses() {
0N/A bool result = _change_old_gen_for_maj_pauses != 0 ||
0N/A _change_old_gen_for_min_pauses != 0;
0N/A return result;
0N/A }
0N/A
0N/A // Return true if the young generation size was changed
0N/A // to try to reach a pause time goal.
0N/A bool young_gen_changed_for_pauses() {
0N/A bool result = _change_young_gen_for_min_pauses != 0 ||
0N/A _change_young_gen_for_maj_pauses != 0;
0N/A return result;
0N/A }
0N/A // end flags for pause goal
0N/A
0N/A // Return true if the old generation size was changed
0N/A // to try to reach a throughput goal.
0N/A bool old_gen_changed_for_throughput() {
0N/A bool result = _change_old_gen_for_throughput != 0;
0N/A return result;
0N/A }
0N/A
0N/A // Return true if the young generation size was changed
0N/A // to try to reach a throughput goal.
0N/A bool young_gen_changed_for_throughput() {
0N/A bool result = _change_young_gen_for_throughput != 0;
0N/A return result;
0N/A }
0N/A
0N/A int decrease_for_footprint() { return _decrease_for_footprint; }
0N/A
0N/A
0N/A // Accessors for estimators. The slope of the linear fit is
0N/A // currently all that is used for making decisions.
0N/A
0N/A LinearLeastSquareFit* major_pause_old_estimator() {
0N/A return _major_pause_old_estimator;
0N/A }
0N/A
0N/A LinearLeastSquareFit* major_pause_young_estimator() {
0N/A return _major_pause_young_estimator;
0N/A }
0N/A
0N/A
0N/A virtual void clear_generation_free_space_flags();
0N/A
0N/A float major_pause_old_slope() { return _major_pause_old_estimator->slope(); }
0N/A float major_pause_young_slope() {
0N/A return _major_pause_young_estimator->slope();
0N/A }
0N/A float major_collection_slope() { return _major_collection_estimator->slope();}
0N/A
0N/A bool old_gen_policy_is_ready() { return _old_gen_policy_is_ready; }
0N/A
0N/A // Given the amount of live data in the heap, should we
0N/A // perform a Full GC?
0N/A bool should_full_GC(size_t live_in_old_gen);
0N/A
0N/A // Calculates optimial free space sizes for both the old and young
0N/A // generations. Stores results in _eden_size and _promo_size.
0N/A // Takes current used space in all generations as input, as well
0N/A // as an indication if a full gc has just been performed, for use
0N/A // in deciding if an OOM error should be thrown.
0N/A void compute_generation_free_space(size_t young_live,
0N/A size_t eden_live,
0N/A size_t old_live,
0N/A size_t perm_live,
0N/A size_t cur_eden, // current eden in bytes
0N/A size_t max_old_gen_size,
0N/A size_t max_eden_size,
0N/A bool is_full_gc,
1387N/A GCCause::Cause gc_cause,
1387N/A CollectorPolicy* collector_policy);
0N/A
0N/A // Calculates new survivor space size; returns a new tenuring threshold
0N/A // value. Stores new survivor size in _survivor_size.
0N/A int compute_survivor_space_size_and_threshold(bool is_survivor_overflow,
0N/A int tenuring_threshold,
0N/A size_t survivor_limit);
0N/A
0N/A // Return the maximum size of a survivor space if the young generation were of
0N/A // size gen_size.
0N/A size_t max_survivor_size(size_t gen_size) {
0N/A // Never allow the target survivor size to grow more than MinSurvivorRatio
0N/A // of the young generation size. We cannot grow into a two semi-space
0N/A // system, with Eden zero sized. Even if the survivor space grows, from()
0N/A // might grow by moving the bottom boundary "down" -- so from space will
0N/A // remain almost full anyway (top() will be near end(), but there will be a
0N/A // large filler object at the bottom).
0N/A const size_t sz = gen_size / MinSurvivorRatio;
0N/A const size_t alignment = _intra_generation_alignment;
0N/A return sz > alignment ? align_size_down(sz, alignment) : alignment;
0N/A }
0N/A
0N/A size_t live_at_last_full_gc() {
0N/A return _live_at_last_full_gc;
0N/A }
0N/A
0N/A size_t bytes_absorbed_from_eden() const { return _bytes_absorbed_from_eden; }
0N/A void reset_bytes_absorbed_from_eden() { _bytes_absorbed_from_eden = 0; }
0N/A
0N/A void set_bytes_absorbed_from_eden(size_t val) {
0N/A _bytes_absorbed_from_eden = val;
0N/A }
0N/A
0N/A // Update averages that are always used (even
0N/A // if adaptive sizing is turned off).
0N/A void update_averages(bool is_survivor_overflow,
0N/A size_t survived,
0N/A size_t promoted);
0N/A
0N/A // Printing support
0N/A virtual bool print_adaptive_size_policy_on(outputStream* st) const;
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP