duke@435: /* tamao@5192: * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSADAPTIVESIZEPOLICY_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSADAPTIVESIZEPOLICY_HPP stefank@2314: stefank@2314: #include "gc_implementation/shared/adaptiveSizePolicy.hpp" stefank@2314: #include "runtime/timer.hpp" stefank@2314: duke@435: // This class keeps statistical information and computes the duke@435: // size of the heap for the concurrent mark sweep collector. duke@435: // duke@435: // Cost for garbage collector include cost for duke@435: // minor collection duke@435: // concurrent collection duke@435: // stop-the-world component duke@435: // concurrent component duke@435: // major compacting collection duke@435: // uses decaying cost duke@435: duke@435: // Forward decls duke@435: class elapsedTimer; duke@435: duke@435: class CMSAdaptiveSizePolicy : public AdaptiveSizePolicy { duke@435: friend class CMSGCAdaptivePolicyCounters; duke@435: friend class CMSCollector; duke@435: private: duke@435: duke@435: // Total number of processors available duke@435: int _processor_count; duke@435: // Number of processors used by the concurrent phases of GC duke@435: // This number is assumed to be the same for all concurrent duke@435: // phases. duke@435: int _concurrent_processor_count; duke@435: duke@435: // Time that the mutators run exclusive of a particular duke@435: // phase. For example, the time the mutators run excluding duke@435: // the time during which the cms collector runs concurrently duke@435: // with the mutators. duke@435: // Between end of most recent cms reset and start of initial mark duke@435: // This may be redundant duke@435: double _latest_cms_reset_end_to_initial_mark_start_secs; duke@435: // Between end of the most recent initial mark and start of remark duke@435: double _latest_cms_initial_mark_end_to_remark_start_secs; duke@435: // Between end of most recent collection and start of duke@435: // a concurrent collection duke@435: double _latest_cms_collection_end_to_collection_start_secs; duke@435: // Times of the concurrent phases of the most recent duke@435: // concurrent collection duke@435: double _latest_cms_concurrent_marking_time_secs; duke@435: double _latest_cms_concurrent_precleaning_time_secs; duke@435: double _latest_cms_concurrent_sweeping_time_secs; duke@435: // Between end of most recent STW MSC and start of next STW MSC duke@435: double _latest_cms_msc_end_to_msc_start_time_secs; duke@435: // Between end of most recent MS and start of next MS duke@435: // This does not include any time spent during a concurrent duke@435: // collection. duke@435: double _latest_cms_ms_end_to_ms_start; duke@435: // Between start and end of the initial mark of the most recent duke@435: // concurrent collection. duke@435: double _latest_cms_initial_mark_start_to_end_time_secs; duke@435: // Between start and end of the remark phase of the most recent duke@435: // concurrent collection duke@435: double _latest_cms_remark_start_to_end_time_secs; duke@435: // Between start and end of the most recent MS STW marking phase duke@435: double _latest_cms_ms_marking_start_to_end_time_secs; duke@435: duke@435: // Pause time timers duke@435: static elapsedTimer _STW_timer; duke@435: // Concurrent collection timer. Used for total of all concurrent phases duke@435: // during 1 collection cycle. duke@435: static elapsedTimer _concurrent_timer; duke@435: duke@435: // When the size of the generation is changed, the size duke@435: // of the change will rounded up or down (depending on the duke@435: // type of change) by this value. duke@435: size_t _generation_alignment; duke@435: duke@435: // If this variable is true, the size of the young generation duke@435: // may be changed in order to reduce the pause(s) of the duke@435: // collection of the tenured generation in order to meet the duke@435: // pause time goal. It is common to change the size of the duke@435: // tenured generation in order to meet the pause time goal duke@435: // for the tenured generation. With the CMS collector for duke@435: // the tenured generation, the size of the young generation duke@435: // can have an significant affect on the pause times for collecting the duke@435: // tenured generation. duke@435: // This is a duplicate of a variable in PSAdaptiveSizePolicy. It duke@435: // is duplicated because it is not clear that it is general enough duke@435: // to go into AdaptiveSizePolicy. duke@435: int _change_young_gen_for_maj_pauses; duke@435: duke@435: // Variable that is set to true after a collection. duke@435: bool _first_after_collection; duke@435: duke@435: // Fraction of collections that are of each type duke@435: double concurrent_fraction() const; duke@435: double STW_msc_fraction() const; duke@435: double STW_ms_fraction() const; duke@435: duke@435: // This call cannot be put into the epilogue as long as some duke@435: // of the counters can be set during concurrent phases. duke@435: virtual void clear_generation_free_space_flags(); duke@435: duke@435: void set_first_after_collection() { _first_after_collection = true; } duke@435: duke@435: protected: duke@435: // Average of the sum of the concurrent times for duke@435: // one collection in seconds. duke@435: AdaptiveWeightedAverage* _avg_concurrent_time; duke@435: // Average time between concurrent collections in seconds. duke@435: AdaptiveWeightedAverage* _avg_concurrent_interval; duke@435: // Average cost of the concurrent part of a collection duke@435: // in seconds. duke@435: AdaptiveWeightedAverage* _avg_concurrent_gc_cost; duke@435: duke@435: // Average of the initial pause of a concurrent collection in seconds. duke@435: AdaptivePaddedAverage* _avg_initial_pause; duke@435: // Average of the remark pause of a concurrent collection in seconds. duke@435: AdaptivePaddedAverage* _avg_remark_pause; duke@435: duke@435: // Average of the stop-the-world (STW) (initial mark + remark) duke@435: // times in seconds for concurrent collections. duke@435: AdaptiveWeightedAverage* _avg_cms_STW_time; duke@435: // Average of the STW collection cost for concurrent collections. duke@435: AdaptiveWeightedAverage* _avg_cms_STW_gc_cost; duke@435: duke@435: // Average of the bytes free at the start of the sweep. duke@435: AdaptiveWeightedAverage* _avg_cms_free_at_sweep; duke@435: // Average of the bytes free at the end of the collection. duke@435: AdaptiveWeightedAverage* _avg_cms_free; duke@435: // Average of the bytes promoted between cms collections. duke@435: AdaptiveWeightedAverage* _avg_cms_promo; duke@435: duke@435: // stop-the-world (STW) mark-sweep-compact duke@435: // Average of the pause time in seconds for STW mark-sweep-compact duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_msc_pause; duke@435: // Average of the interval in seconds between STW mark-sweep-compact duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_msc_interval; duke@435: // Average of the collection costs for STW mark-sweep-compact duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_msc_gc_cost; duke@435: duke@435: // Averages for mark-sweep collections. duke@435: // The collection may have started as a background collection duke@435: // that completes in a stop-the-world (STW) collection. duke@435: // Average of the pause time in seconds for mark-sweep duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_ms_pause; duke@435: // Average of the interval in seconds between mark-sweep duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_ms_interval; duke@435: // Average of the collection costs for mark-sweep duke@435: // collections. duke@435: AdaptiveWeightedAverage* _avg_ms_gc_cost; duke@435: duke@435: // These variables contain a linear fit of duke@435: // a generation size as the independent variable duke@435: // and a pause time as the dependent variable. duke@435: // For example _remark_pause_old_estimator duke@435: // is a fit of the old generation size as the duke@435: // independent variable and the remark pause duke@435: // as the dependent variable. duke@435: // remark pause time vs. cms gen size duke@435: LinearLeastSquareFit* _remark_pause_old_estimator; duke@435: // initial pause time vs. cms gen size duke@435: LinearLeastSquareFit* _initial_pause_old_estimator; duke@435: // remark pause time vs. young gen size duke@435: LinearLeastSquareFit* _remark_pause_young_estimator; duke@435: // initial pause time vs. young gen size duke@435: LinearLeastSquareFit* _initial_pause_young_estimator; duke@435: duke@435: // Accessors duke@435: int processor_count() const { return _processor_count; } duke@435: int concurrent_processor_count() const { return _concurrent_processor_count; } duke@435: duke@435: AdaptiveWeightedAverage* avg_concurrent_time() const { duke@435: return _avg_concurrent_time; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_concurrent_interval() const { duke@435: return _avg_concurrent_interval; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_concurrent_gc_cost() const { duke@435: return _avg_concurrent_gc_cost; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_cms_STW_time() const { duke@435: return _avg_cms_STW_time; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_cms_STW_gc_cost() const { duke@435: return _avg_cms_STW_gc_cost; duke@435: } duke@435: duke@435: AdaptivePaddedAverage* avg_initial_pause() const { duke@435: return _avg_initial_pause; duke@435: } duke@435: duke@435: AdaptivePaddedAverage* avg_remark_pause() const { duke@435: return _avg_remark_pause; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_cms_free() const { duke@435: return _avg_cms_free; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_cms_free_at_sweep() const { duke@435: return _avg_cms_free_at_sweep; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_msc_pause() const { duke@435: return _avg_msc_pause; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_msc_interval() const { duke@435: return _avg_msc_interval; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_msc_gc_cost() const { duke@435: return _avg_msc_gc_cost; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_ms_pause() const { duke@435: return _avg_ms_pause; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_ms_interval() const { duke@435: return _avg_ms_interval; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_ms_gc_cost() const { duke@435: return _avg_ms_gc_cost; duke@435: } duke@435: duke@435: LinearLeastSquareFit* remark_pause_old_estimator() { duke@435: return _remark_pause_old_estimator; duke@435: } duke@435: LinearLeastSquareFit* initial_pause_old_estimator() { duke@435: return _initial_pause_old_estimator; duke@435: } duke@435: LinearLeastSquareFit* remark_pause_young_estimator() { duke@435: return _remark_pause_young_estimator; duke@435: } duke@435: LinearLeastSquareFit* initial_pause_young_estimator() { duke@435: return _initial_pause_young_estimator; duke@435: } duke@435: duke@435: // These *slope() methods return the slope duke@435: // m for the linear fit of an independent duke@435: // variable vs. a dependent variable. For duke@435: // example duke@435: // remark_pause = m * old_generation_size + c duke@435: // These may be used to determine if an duke@435: // adjustment should be made to achieve a goal. duke@435: // For example, if remark_pause_old_slope() is duke@435: // positive, a reduction of the old generation duke@435: // size has on average resulted in the reduction duke@435: // of the remark pause. duke@435: float remark_pause_old_slope() { duke@435: return _remark_pause_old_estimator->slope(); duke@435: } duke@435: duke@435: float initial_pause_old_slope() { duke@435: return _initial_pause_old_estimator->slope(); duke@435: } duke@435: duke@435: float remark_pause_young_slope() { duke@435: return _remark_pause_young_estimator->slope(); duke@435: } duke@435: duke@435: float initial_pause_young_slope() { duke@435: return _initial_pause_young_estimator->slope(); duke@435: } duke@435: duke@435: // Update estimators duke@435: void update_minor_pause_old_estimator(double minor_pause_in_ms); duke@435: duke@435: // Fraction of processors used by the concurrent phases. duke@435: double concurrent_processor_fraction(); duke@435: duke@435: // Returns the total times for the concurrent part of the duke@435: // latest collection in seconds. duke@435: double concurrent_collection_time(); duke@435: duke@435: // Return the total times for the concurrent part of the duke@435: // latest collection in seconds where the times of the various duke@435: // concurrent phases are scaled by the processor fraction used duke@435: // during the phase. duke@435: double scaled_concurrent_collection_time(); duke@435: duke@435: // Dimensionless concurrent GC cost for all the concurrent phases. duke@435: double concurrent_collection_cost(double interval_in_seconds); duke@435: duke@435: // Dimensionless GC cost duke@435: double collection_cost(double pause_in_seconds, double interval_in_seconds); duke@435: duke@435: virtual GCPolicyKind kind() const { return _gc_cms_adaptive_size_policy; } duke@435: duke@435: virtual double time_since_major_gc() const; duke@435: duke@435: // This returns the maximum average for the concurrent, ms, and duke@435: // msc collections. This is meant to be used for the calculation duke@435: // of the decayed major gc cost and is not in general the duke@435: // average of all the different types of major collections. duke@435: virtual double major_gc_interval_average_for_decay() const; duke@435: duke@435: public: duke@435: CMSAdaptiveSizePolicy(size_t init_eden_size, duke@435: size_t init_promo_size, duke@435: size_t init_survivor_size, duke@435: double max_gc_minor_pause_sec, duke@435: double max_gc_pause_sec, duke@435: uint gc_cost_ratio); duke@435: duke@435: // The timers for the stop-the-world phases measure a total duke@435: // stop-the-world time. The timer is started and stopped duke@435: // for each phase but is only reset after the final checkpoint. duke@435: void checkpoint_roots_initial_begin(); duke@435: void checkpoint_roots_initial_end(GCCause::Cause gc_cause); duke@435: void checkpoint_roots_final_begin(); duke@435: void checkpoint_roots_final_end(GCCause::Cause gc_cause); duke@435: duke@435: // Methods for gathering information about the duke@435: // concurrent marking phase of the collection. duke@435: // Records the mutator times and duke@435: // resets the concurrent timer. duke@435: void concurrent_marking_begin(); duke@435: // Resets concurrent phase timer in the begin methods and duke@435: // saves the time for a phase in the end methods. duke@435: void concurrent_marking_end(); duke@435: void concurrent_sweeping_begin(); duke@435: void concurrent_sweeping_end(); duke@435: // Similar to the above (e.g., concurrent_marking_end()) and duke@435: // is used for both the precleaning an abortable precleaing duke@435: // phases. duke@435: void concurrent_precleaning_begin(); duke@435: void concurrent_precleaning_end(); duke@435: // Stops the concurrent phases time. Gathers duke@435: // information and resets the timer. duke@435: void concurrent_phases_end(GCCause::Cause gc_cause, duke@435: size_t cur_eden, duke@435: size_t cur_promo); duke@435: duke@435: // Methods for gather information about STW Mark-Sweep-Compact duke@435: void msc_collection_begin(); duke@435: void msc_collection_end(GCCause::Cause gc_cause); duke@435: duke@435: // Methods for gather information about Mark-Sweep done duke@435: // in the foreground. duke@435: void ms_collection_begin(); duke@435: void ms_collection_end(GCCause::Cause gc_cause); duke@435: duke@435: // Cost for a mark-sweep tenured gen collection done in the foreground duke@435: double ms_gc_cost() const { duke@435: return MAX2(0.0F, _avg_ms_gc_cost->average()); duke@435: } duke@435: duke@435: // Cost of collecting the tenured generation. Includes duke@435: // concurrent collection and STW collection costs duke@435: double cms_gc_cost() const; duke@435: duke@435: // Cost of STW mark-sweep-compact tenured gen collection. duke@435: double msc_gc_cost() const { duke@435: return MAX2(0.0F, _avg_msc_gc_cost->average()); duke@435: } duke@435: duke@435: // duke@435: double compacting_gc_cost() const { duke@435: double result = MIN2(1.0, minor_gc_cost() + msc_gc_cost()); duke@435: assert(result >= 0.0, "Both minor and major costs are non-negative"); duke@435: return result; duke@435: } duke@435: duke@435: // Restarts the concurrent phases timer. duke@435: void concurrent_phases_resume(); duke@435: twisti@1040: // Time beginning and end of the marking phase for duke@435: // a synchronous MS collection. A MS collection duke@435: // that finishes in the foreground can have started duke@435: // in the background. These methods capture the duke@435: // completion of the marking (after the initial duke@435: // marking) that is done in the foreground. duke@435: void ms_collection_marking_begin(); duke@435: void ms_collection_marking_end(GCCause::Cause gc_cause); duke@435: duke@435: static elapsedTimer* concurrent_timer_ptr() { duke@435: return &_concurrent_timer; duke@435: } duke@435: duke@435: AdaptiveWeightedAverage* avg_cms_promo() const { duke@435: return _avg_cms_promo; duke@435: } duke@435: duke@435: int change_young_gen_for_maj_pauses() { duke@435: return _change_young_gen_for_maj_pauses; duke@435: } duke@435: void set_change_young_gen_for_maj_pauses(int v) { duke@435: _change_young_gen_for_maj_pauses = v; duke@435: } duke@435: duke@435: void clear_internal_time_intervals(); duke@435: duke@435: duke@435: // Either calculated_promo_size_in_bytes() or promo_size() duke@435: // should be deleted. duke@435: size_t promo_size() { return _promo_size; } duke@435: void set_promo_size(size_t v) { _promo_size = v; } duke@435: duke@435: // Cost of GC for all types of collections. duke@435: virtual double gc_cost() const; duke@435: duke@435: size_t generation_alignment() { return _generation_alignment; } duke@435: tamao@5192: virtual void compute_eden_space_size(size_t cur_eden, tamao@5192: size_t max_eden_size); duke@435: // Calculates new survivor space size; returns a new tenuring threshold duke@435: // value. Stores new survivor size in _survivor_size. jwilhelm@4129: virtual uint compute_survivor_space_size_and_threshold( duke@435: bool is_survivor_overflow, jwilhelm@4129: uint tenuring_threshold, duke@435: size_t survivor_limit); duke@435: duke@435: virtual void compute_tenured_generation_free_space(size_t cur_tenured_free, duke@435: size_t max_tenured_available, duke@435: size_t cur_eden); duke@435: duke@435: size_t eden_decrement_aligned_down(size_t cur_eden); duke@435: size_t eden_increment_aligned_up(size_t cur_eden); duke@435: duke@435: size_t adjust_eden_for_pause_time(size_t cur_eden); duke@435: size_t adjust_eden_for_throughput(size_t cur_eden); duke@435: size_t adjust_eden_for_footprint(size_t cur_eden); duke@435: duke@435: size_t promo_decrement_aligned_down(size_t cur_promo); duke@435: size_t promo_increment_aligned_up(size_t cur_promo); duke@435: duke@435: size_t adjust_promo_for_pause_time(size_t cur_promo); duke@435: size_t adjust_promo_for_throughput(size_t cur_promo); duke@435: size_t adjust_promo_for_footprint(size_t cur_promo, size_t cur_eden); duke@435: duke@435: // Scale down the input size by the ratio of the cost to collect the duke@435: // generation to the total GC cost. duke@435: size_t scale_by_gen_gc_cost(size_t base_change, double gen_gc_cost); duke@435: duke@435: // Return the value and clear it. duke@435: bool get_and_clear_first_after_collection(); duke@435: duke@435: // Printing support duke@435: virtual bool print_adaptive_size_policy_on(outputStream* st) const; duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSADAPTIVESIZEPOLICY_HPP