src/share/vm/gc_implementation/shared/adaptiveSizePolicy.hpp

Fri, 25 Sep 2009 12:17:06 -0700

author
trims
date
Fri, 25 Sep 2009 12:17:06 -0700
changeset 1417
7a102acc9f17
parent 435
a61af66fc99e
child 1822
0bfd3fb24150
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // This class keeps statistical information and computes the
    26 // size of the heap.
    28 // Forward decls
    29 class elapsedTimer;
    31 class AdaptiveSizePolicy : public CHeapObj {
    32  friend class GCAdaptivePolicyCounters;
    33  friend class PSGCAdaptivePolicyCounters;
    34  friend class CMSGCAdaptivePolicyCounters;
    35  protected:
    37   enum GCPolicyKind {
    38     _gc_adaptive_size_policy,
    39     _gc_ps_adaptive_size_policy,
    40     _gc_cms_adaptive_size_policy
    41   };
    42   virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
    44   enum SizePolicyTrueValues {
    45     decrease_old_gen_for_throughput_true = -7,
    46     decrease_young_gen_for_througput_true = -6,
    48     increase_old_gen_for_min_pauses_true = -5,
    49     decrease_old_gen_for_min_pauses_true = -4,
    50     decrease_young_gen_for_maj_pauses_true = -3,
    51     increase_young_gen_for_min_pauses_true = -2,
    52     increase_old_gen_for_maj_pauses_true = -1,
    54     decrease_young_gen_for_min_pauses_true = 1,
    55     decrease_old_gen_for_maj_pauses_true = 2,
    56     increase_young_gen_for_maj_pauses_true = 3,
    58     increase_old_gen_for_throughput_true = 4,
    59     increase_young_gen_for_througput_true = 5,
    61     decrease_young_gen_for_footprint_true = 6,
    62     decrease_old_gen_for_footprint_true = 7,
    63     decide_at_full_gc_true = 8
    64   };
    66   // Goal for the fraction of the total time during which application
    67   // threads run.
    68   const double _throughput_goal;
    70   // Last calculated sizes, in bytes, and aligned
    71   size_t _eden_size;        // calculated eden free space in bytes
    72   size_t _promo_size;       // calculated cms gen free space in bytes
    74   size_t _survivor_size;    // calculated survivor size in bytes
    76   // This is a hint for the heap:  we've detected that gc times
    77   // are taking longer than GCTimeLimit allows.
    78   bool _gc_time_limit_exceeded;
    79   // Use for diagnostics only.  If UseGCTimeLimit is false,
    80   // this variable is still set.
    81   bool _print_gc_time_limit_would_be_exceeded;
    82   // Count of consecutive GC that have exceeded the
    83   // GC time limit criterion.
    84   uint _gc_time_limit_count;
    86   // Minor collection timers used to determine both
    87   // pause and interval times for collections.
    88   static elapsedTimer _minor_timer;
    90   // Major collection timers, used to determine both
    91   // pause and interval times for collections
    92   static elapsedTimer _major_timer;
    94   // Time statistics
    95   AdaptivePaddedAverage*   _avg_minor_pause;
    96   AdaptiveWeightedAverage* _avg_minor_interval;
    97   AdaptiveWeightedAverage* _avg_minor_gc_cost;
    99   AdaptiveWeightedAverage* _avg_major_interval;
   100   AdaptiveWeightedAverage* _avg_major_gc_cost;
   102   // Footprint statistics
   103   AdaptiveWeightedAverage* _avg_young_live;
   104   AdaptiveWeightedAverage* _avg_eden_live;
   105   AdaptiveWeightedAverage* _avg_old_live;
   107   // Statistics for survivor space calculation for young generation
   108   AdaptivePaddedAverage*   _avg_survived;
   110   // Objects that have been directly allocated in the old generation.
   111   AdaptivePaddedNoZeroDevAverage*   _avg_pretenured;
   113   // Variable for estimating the major and minor pause times.
   114   // These variables represent linear least-squares fits of
   115   // the data.
   116   //   minor pause time vs. old gen size
   117   LinearLeastSquareFit* _minor_pause_old_estimator;
   118   //   minor pause time vs. young gen size
   119   LinearLeastSquareFit* _minor_pause_young_estimator;
   121   // Variables for estimating the major and minor collection costs
   122   //   minor collection time vs. young gen size
   123   LinearLeastSquareFit* _minor_collection_estimator;
   124   //   major collection time vs. cms gen size
   125   LinearLeastSquareFit* _major_collection_estimator;
   127   // These record the most recent collection times.  They
   128   // are available as an alternative to using the averages
   129   // for making ergonomic decisions.
   130   double _latest_minor_mutator_interval_seconds;
   132   // Allowed difference between major and minor gc times, used
   133   // for computing tenuring_threshold.
   134   const double _threshold_tolerance_percent;
   136   const double _gc_pause_goal_sec; // goal for maximum gc pause
   138   // Flag indicating that the adaptive policy is ready to use
   139   bool _young_gen_policy_is_ready;
   141   // decrease/increase the young generation for minor pause time
   142   int _change_young_gen_for_min_pauses;
   144   // decrease/increase the old generation for major pause time
   145   int _change_old_gen_for_maj_pauses;
   147   //   change old geneneration for throughput
   148   int _change_old_gen_for_throughput;
   150   //   change young generation for throughput
   151   int _change_young_gen_for_throughput;
   153   // Flag indicating that the policy would
   154   //   increase the tenuring threshold because of the total major gc cost
   155   //   is greater than the total minor gc cost
   156   bool _increment_tenuring_threshold_for_gc_cost;
   157   //   decrease the tenuring threshold because of the the total minor gc
   158   //   cost is greater than the total major gc cost
   159   bool _decrement_tenuring_threshold_for_gc_cost;
   160   //   decrease due to survivor size limit
   161   bool _decrement_tenuring_threshold_for_survivor_limit;
   163   //   decrease generation sizes for footprint
   164   int _decrease_for_footprint;
   166   // Set if the ergonomic decisions were made at a full GC.
   167   int _decide_at_full_gc;
   169   // Changing the generation sizing depends on the data that is
   170   // gathered about the effects of changes on the pause times and
   171   // throughput.  These variable count the number of data points
   172   // gathered.  The policy may use these counters as a threshhold
   173   // for reliable data.
   174   julong _young_gen_change_for_minor_throughput;
   175   julong _old_gen_change_for_major_throughput;
   177   // Accessors
   179   double gc_pause_goal_sec() const { return _gc_pause_goal_sec; }
   180   // The value returned is unitless:  it's the proportion of time
   181   // spent in a particular collection type.
   182   // An interval time will be 0.0 if a collection type hasn't occurred yet.
   183   // The 1.4.2 implementation put a floor on the values of major_gc_cost
   184   // and minor_gc_cost.  This was useful because of the way major_gc_cost
   185   // and minor_gc_cost was used in calculating the sizes of the generations.
   186   // Do not use a floor in this implementation because any finite value
   187   // will put a limit on the throughput that can be achieved and any
   188   // throughput goal above that limit will drive the generations sizes
   189   // to extremes.
   190   double major_gc_cost() const {
   191     return MAX2(0.0F, _avg_major_gc_cost->average());
   192   }
   194   // The value returned is unitless:  it's the proportion of time
   195   // spent in a particular collection type.
   196   // An interval time will be 0.0 if a collection type hasn't occurred yet.
   197   // The 1.4.2 implementation put a floor on the values of major_gc_cost
   198   // and minor_gc_cost.  This was useful because of the way major_gc_cost
   199   // and minor_gc_cost was used in calculating the sizes of the generations.
   200   // Do not use a floor in this implementation because any finite value
   201   // will put a limit on the throughput that can be achieved and any
   202   // throughput goal above that limit will drive the generations sizes
   203   // to extremes.
   205   double minor_gc_cost() const {
   206     return MAX2(0.0F, _avg_minor_gc_cost->average());
   207   }
   209   // Because we're dealing with averages, gc_cost() can be
   210   // larger than 1.0 if just the sum of the minor cost the
   211   // the major cost is used.  Worse than that is the
   212   // fact that the minor cost and the major cost each
   213   // tend toward 1.0 in the extreme of high gc costs.
   214   // Limit the value of gc_cost to 1.0 so that the mutator
   215   // cost stays non-negative.
   216   virtual double gc_cost() const {
   217     double result = MIN2(1.0, minor_gc_cost() + major_gc_cost());
   218     assert(result >= 0.0, "Both minor and major costs are non-negative");
   219     return result;
   220   }
   222   // Elapsed time since the last major collection.
   223   virtual double time_since_major_gc() const;
   225   // Average interval between major collections to be used
   226   // in calculating the decaying major gc cost.  An overestimate
   227   // of this time would be a conservative estimate because
   228   // this time is used to decide if the major GC cost
   229   // should be decayed (i.e., if the time since the last
   230   // major gc is long compared to the time returned here,
   231   // then the major GC cost will be decayed).  See the
   232   // implementations for the specifics.
   233   virtual double major_gc_interval_average_for_decay() const {
   234     return _avg_major_interval->average();
   235   }
   237   // Return the cost of the GC where the major gc cost
   238   // has been decayed based on the time since the last
   239   // major collection.
   240   double decaying_gc_cost() const;
   242   // Decay the major gc cost.  Use this only for decisions on
   243   // whether to adjust, not to determine by how much to adjust.
   244   // This approximation is crude and may not be good enough for the
   245   // latter.
   246   double decaying_major_gc_cost() const;
   248   // Return the mutator cost using the decayed
   249   // GC cost.
   250   double adjusted_mutator_cost() const {
   251     double result = 1.0 - decaying_gc_cost();
   252     assert(result >= 0.0, "adjusted mutator cost calculation is incorrect");
   253     return result;
   254   }
   256   virtual double mutator_cost() const {
   257     double result = 1.0 - gc_cost();
   258     assert(result >= 0.0, "mutator cost calculation is incorrect");
   259     return result;
   260   }
   263   bool young_gen_policy_is_ready() { return _young_gen_policy_is_ready; }
   265   void update_minor_pause_young_estimator(double minor_pause_in_ms);
   266   virtual void update_minor_pause_old_estimator(double minor_pause_in_ms) {
   267     // This is not meaningful for all policies but needs to be present
   268     // to use minor_collection_end() in its current form.
   269   }
   271   virtual size_t eden_increment(size_t cur_eden);
   272   virtual size_t eden_increment(size_t cur_eden, uint percent_change);
   273   virtual size_t eden_decrement(size_t cur_eden);
   274   virtual size_t promo_increment(size_t cur_eden);
   275   virtual size_t promo_increment(size_t cur_eden, uint percent_change);
   276   virtual size_t promo_decrement(size_t cur_eden);
   278   virtual void clear_generation_free_space_flags();
   280   int change_old_gen_for_throughput() const {
   281     return _change_old_gen_for_throughput;
   282   }
   283   void set_change_old_gen_for_throughput(int v) {
   284     _change_old_gen_for_throughput = v;
   285   }
   286   int change_young_gen_for_throughput() const {
   287     return _change_young_gen_for_throughput;
   288   }
   289   void set_change_young_gen_for_throughput(int v) {
   290     _change_young_gen_for_throughput = v;
   291   }
   293   int change_old_gen_for_maj_pauses() const {
   294     return _change_old_gen_for_maj_pauses;
   295   }
   296   void set_change_old_gen_for_maj_pauses(int v) {
   297     _change_old_gen_for_maj_pauses = v;
   298   }
   300   bool decrement_tenuring_threshold_for_gc_cost() const {
   301     return _decrement_tenuring_threshold_for_gc_cost;
   302   }
   303   void set_decrement_tenuring_threshold_for_gc_cost(bool v) {
   304     _decrement_tenuring_threshold_for_gc_cost = v;
   305   }
   306   bool increment_tenuring_threshold_for_gc_cost() const {
   307     return _increment_tenuring_threshold_for_gc_cost;
   308   }
   309   void set_increment_tenuring_threshold_for_gc_cost(bool v) {
   310     _increment_tenuring_threshold_for_gc_cost = v;
   311   }
   312   bool decrement_tenuring_threshold_for_survivor_limit() const {
   313     return _decrement_tenuring_threshold_for_survivor_limit;
   314   }
   315   void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
   316     _decrement_tenuring_threshold_for_survivor_limit = v;
   317   }
   318   // Return true if the policy suggested a change.
   319   bool tenuring_threshold_change() const;
   321  public:
   322   AdaptiveSizePolicy(size_t init_eden_size,
   323                      size_t init_promo_size,
   324                      size_t init_survivor_size,
   325                      double gc_pause_goal_sec,
   326                      uint gc_cost_ratio);
   328   bool is_gc_cms_adaptive_size_policy() {
   329     return kind() == _gc_cms_adaptive_size_policy;
   330   }
   331   bool is_gc_ps_adaptive_size_policy() {
   332     return kind() == _gc_ps_adaptive_size_policy;
   333   }
   335   AdaptivePaddedAverage*   avg_minor_pause() const { return _avg_minor_pause; }
   336   AdaptiveWeightedAverage* avg_minor_interval() const {
   337     return _avg_minor_interval;
   338   }
   339   AdaptiveWeightedAverage* avg_minor_gc_cost() const {
   340     return _avg_minor_gc_cost;
   341   }
   343   AdaptiveWeightedAverage* avg_major_gc_cost() const {
   344     return _avg_major_gc_cost;
   345   }
   347   AdaptiveWeightedAverage* avg_young_live() const { return _avg_young_live; }
   348   AdaptiveWeightedAverage* avg_eden_live() const { return _avg_eden_live; }
   349   AdaptiveWeightedAverage* avg_old_live() const { return _avg_old_live; }
   351   AdaptivePaddedAverage*  avg_survived() const { return _avg_survived; }
   352   AdaptivePaddedNoZeroDevAverage*  avg_pretenured() { return _avg_pretenured; }
   354   // Methods indicating events of interest to the adaptive size policy,
   355   // called by GC algorithms. It is the responsibility of users of this
   356   // policy to call these methods at the correct times!
   357   virtual void minor_collection_begin();
   358   virtual void minor_collection_end(GCCause::Cause gc_cause);
   359   virtual LinearLeastSquareFit* minor_pause_old_estimator() const {
   360     return _minor_pause_old_estimator;
   361   }
   363   LinearLeastSquareFit* minor_pause_young_estimator() {
   364     return _minor_pause_young_estimator;
   365   }
   366   LinearLeastSquareFit* minor_collection_estimator() {
   367     return _minor_collection_estimator;
   368   }
   370   LinearLeastSquareFit* major_collection_estimator() {
   371     return _major_collection_estimator;
   372   }
   374   float minor_pause_young_slope() {
   375     return _minor_pause_young_estimator->slope();
   376   }
   378   float minor_collection_slope() { return _minor_collection_estimator->slope();}
   379   float major_collection_slope() { return _major_collection_estimator->slope();}
   381   float minor_pause_old_slope() {
   382     return _minor_pause_old_estimator->slope();
   383   }
   385   void set_eden_size(size_t new_size) {
   386     _eden_size = new_size;
   387   }
   388   void set_survivor_size(size_t new_size) {
   389     _survivor_size = new_size;
   390   }
   392   size_t calculated_eden_size_in_bytes() const {
   393     return _eden_size;
   394   }
   396   size_t calculated_promo_size_in_bytes() const {
   397     return _promo_size;
   398   }
   400   size_t calculated_survivor_size_in_bytes() const {
   401     return _survivor_size;
   402   }
   404   // This is a hint for the heap:  we've detected that gc times
   405   // are taking longer than GCTimeLimit allows.
   406   // Most heaps will choose to throw an OutOfMemoryError when
   407   // this occurs but it is up to the heap to request this information
   408   // of the policy
   409   bool gc_time_limit_exceeded() {
   410     return _gc_time_limit_exceeded;
   411   }
   412   void set_gc_time_limit_exceeded(bool v) {
   413     _gc_time_limit_exceeded = v;
   414   }
   415   bool print_gc_time_limit_would_be_exceeded() {
   416     return _print_gc_time_limit_would_be_exceeded;
   417   }
   418   void set_print_gc_time_limit_would_be_exceeded(bool v) {
   419     _print_gc_time_limit_would_be_exceeded = v;
   420   }
   422   uint gc_time_limit_count() { return _gc_time_limit_count; }
   423   void reset_gc_time_limit_count() { _gc_time_limit_count = 0; }
   424   void inc_gc_time_limit_count() { _gc_time_limit_count++; }
   425   // accessors for flags recording the decisions to resize the
   426   // generations to meet the pause goal.
   428   int change_young_gen_for_min_pauses() const {
   429     return _change_young_gen_for_min_pauses;
   430   }
   431   void set_change_young_gen_for_min_pauses(int v) {
   432     _change_young_gen_for_min_pauses = v;
   433   }
   434   void set_decrease_for_footprint(int v) { _decrease_for_footprint = v; }
   435   int decrease_for_footprint() const { return _decrease_for_footprint; }
   436   int decide_at_full_gc() { return _decide_at_full_gc; }
   437   void set_decide_at_full_gc(int v) { _decide_at_full_gc = v; }
   439   // Printing support
   440   virtual bool print_adaptive_size_policy_on(outputStream* st) const;
   441   bool print_adaptive_size_policy_on(outputStream* st, int
   442                                   tenuring_threshold) const;
   443 };
   445 // Class that can be used to print information about the
   446 // adaptive size policy at intervals specified by
   447 // AdaptiveSizePolicyOutputInterval.  Only print information
   448 // if an adaptive size policy is in use.
   449 class AdaptiveSizePolicyOutput : StackObj {
   450   AdaptiveSizePolicy* _size_policy;
   451   bool _do_print;
   452   bool print_test(uint count) {
   453     // A count of zero is a special value that indicates that the
   454     // interval test should be ignored.  An interval is of zero is
   455     // a special value that indicates that the interval test should
   456     // always fail (never do the print based on the interval test).
   457     return PrintGCDetails &&
   458            UseAdaptiveSizePolicy &&
   459            (UseParallelGC || UseConcMarkSweepGC) &&
   460            (AdaptiveSizePolicyOutputInterval > 0) &&
   461            ((count == 0) ||
   462              ((count % AdaptiveSizePolicyOutputInterval) == 0));
   463   }
   464  public:
   465   // The special value of a zero count can be used to ignore
   466   // the count test.
   467   AdaptiveSizePolicyOutput(uint count) {
   468     if (UseAdaptiveSizePolicy && (AdaptiveSizePolicyOutputInterval > 0)) {
   469       CollectedHeap* heap = Universe::heap();
   470       _size_policy = heap->size_policy();
   471       _do_print = print_test(count);
   472     } else {
   473       _size_policy = NULL;
   474       _do_print = false;
   475     }
   476   }
   477   AdaptiveSizePolicyOutput(AdaptiveSizePolicy* size_policy,
   478                            uint count) :
   479     _size_policy(size_policy) {
   480     if (UseAdaptiveSizePolicy && (AdaptiveSizePolicyOutputInterval > 0)) {
   481       _do_print = print_test(count);
   482     } else {
   483       _do_print = false;
   484     }
   485   }
   486   ~AdaptiveSizePolicyOutput() {
   487     if (_do_print) {
   488       assert(UseAdaptiveSizePolicy, "Should not be in use");
   489       _size_policy->print_adaptive_size_policy_on(gclog_or_tty);
   490     }
   491   }
   492 };

mercurial