src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp

Sat, 19 Jul 2008 17:38:22 -0400

author
coleenp
date
Sat, 19 Jul 2008 17:38:22 -0400
changeset 672
1fdb98a17101
parent 435
a61af66fc99e
child 1822
0bfd3fb24150
permissions
-rw-r--r--

6716785: implicit null checks not triggering with CompressedOops
Summary: allocate alignment-sized page(s) below java heap so that memory accesses at heap_base+1page give signal and cause an implicit null check
Reviewed-by: kvn, jmasa, phh, jcoomes

     1 /*
     2  * Copyright 2002-2007 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 // optimal free space for both the young and old generation
    27 // based on current application characteristics (based on gc cost
    28 // and application footprint).
    29 //
    30 // It also computes an optimal tenuring threshold between the young
    31 // and old generations, so as to equalize the cost of collections
    32 // of those generations, as well as optimial survivor space sizes
    33 // for the young generation.
    34 //
    35 // While this class is specifically intended for a generational system
    36 // consisting of a young gen (containing an Eden and two semi-spaces)
    37 // and a tenured gen, as well as a perm gen for reflective data, it
    38 // makes NO references to specific generations.
    39 //
    40 // 05/02/2003 Update
    41 // The 1.5 policy makes use of data gathered for the costs of GC on
    42 // specific generations.  That data does reference specific
    43 // generation.  Also diagnostics specific to generations have
    44 // been added.
    46 // Forward decls
    47 class elapsedTimer;
    49 class PSAdaptiveSizePolicy : public AdaptiveSizePolicy {
    50  friend class PSGCAdaptivePolicyCounters;
    51  private:
    52   // These values are used to record decisions made during the
    53   // policy.  For example, if the young generation was decreased
    54   // to decrease the GC cost of minor collections the value
    55   // decrease_young_gen_for_throughput_true is used.
    57   // Last calculated sizes, in bytes, and aligned
    58   // NEEDS_CLEANUP should use sizes.hpp,  but it works in ints, not size_t's
    60   // Time statistics
    61   AdaptivePaddedAverage* _avg_major_pause;
    63   // Footprint statistics
    64   AdaptiveWeightedAverage* _avg_base_footprint;
    66   // Statistical data gathered for GC
    67   GCStats _gc_stats;
    69   size_t _survivor_size_limit;   // Limit in bytes of survivor size
    70   const double _collection_cost_margin_fraction;
    72   // Variable for estimating the major and minor pause times.
    73   // These variables represent linear least-squares fits of
    74   // the data.
    75   //   major pause time vs. old gen size
    76   LinearLeastSquareFit* _major_pause_old_estimator;
    77   //   major pause time vs. young gen size
    78   LinearLeastSquareFit* _major_pause_young_estimator;
    81   // These record the most recent collection times.  They
    82   // are available as an alternative to using the averages
    83   // for making ergonomic decisions.
    84   double _latest_major_mutator_interval_seconds;
    86   const size_t _intra_generation_alignment; // alignment for eden, survivors
    88   const double _gc_minor_pause_goal_sec;    // goal for maximum minor gc pause
    90   // The amount of live data in the heap at the last full GC, used
    91   // as a baseline to help us determine when we need to perform the
    92   // next full GC.
    93   size_t _live_at_last_full_gc;
    95   // decrease/increase the old generation for minor pause time
    96   int _change_old_gen_for_min_pauses;
    98   // increase/decrease the young generation for major pause time
    99   int _change_young_gen_for_maj_pauses;
   102   // Flag indicating that the adaptive policy is ready to use
   103   bool _old_gen_policy_is_ready;
   105   // Changing the generation sizing depends on the data that is
   106   // gathered about the effects of changes on the pause times and
   107   // throughput.  These variable count the number of data points
   108   // gathered.  The policy may use these counters as a threshhold
   109   // for reliable data.
   110   julong _young_gen_change_for_major_pause_count;
   112   // To facilitate faster growth at start up, supplement the normal
   113   // growth percentage for the young gen eden and the
   114   // old gen space for promotion with these value which decay
   115   // with increasing collections.
   116   uint _young_gen_size_increment_supplement;
   117   uint _old_gen_size_increment_supplement;
   119   // The number of bytes absorbed from eden into the old gen by moving the
   120   // boundary over live data.
   121   size_t _bytes_absorbed_from_eden;
   123  private:
   125   // Accessors
   126   AdaptivePaddedAverage* avg_major_pause() const { return _avg_major_pause; }
   127   double gc_minor_pause_goal_sec() const { return _gc_minor_pause_goal_sec; }
   129   // Change the young generation size to achieve a minor GC pause time goal
   130   void adjust_for_minor_pause_time(bool is_full_gc,
   131                                    size_t* desired_promo_size_ptr,
   132                                    size_t* desired_eden_size_ptr);
   133   // Change the generation sizes to achieve a GC pause time goal
   134   // Returned sizes are not necessarily aligned.
   135   void adjust_for_pause_time(bool is_full_gc,
   136                          size_t* desired_promo_size_ptr,
   137                          size_t* desired_eden_size_ptr);
   138   // Change the generation sizes to achieve an application throughput goal
   139   // Returned sizes are not necessarily aligned.
   140   void adjust_for_throughput(bool is_full_gc,
   141                              size_t* desired_promo_size_ptr,
   142                              size_t* desired_eden_size_ptr);
   143   // Change the generation sizes to achieve minimum footprint
   144   // Returned sizes are not aligned.
   145   size_t adjust_promo_for_footprint(size_t desired_promo_size,
   146                                     size_t desired_total);
   147   size_t adjust_eden_for_footprint(size_t desired_promo_size,
   148                                    size_t desired_total);
   150   // Size in bytes for an increment or decrement of eden.
   151   virtual size_t eden_increment(size_t cur_eden, uint percent_change);
   152   virtual size_t eden_decrement(size_t cur_eden);
   153   size_t eden_decrement_aligned_down(size_t cur_eden);
   154   size_t eden_increment_with_supplement_aligned_up(size_t cur_eden);
   156   // Size in bytes for an increment or decrement of the promotion area
   157   virtual size_t promo_increment(size_t cur_promo, uint percent_change);
   158   virtual size_t promo_decrement(size_t cur_promo);
   159   size_t promo_decrement_aligned_down(size_t cur_promo);
   160   size_t promo_increment_with_supplement_aligned_up(size_t cur_promo);
   162   // Decay the supplemental growth additive.
   163   void decay_supplemental_growth(bool is_full_gc);
   165   // Returns a change that has been scaled down.  Result
   166   // is not aligned.  (If useful, move to some shared
   167   // location.)
   168   size_t scale_down(size_t change, double part, double total);
   170  protected:
   171   // Time accessors
   173   // Footprint accessors
   174   size_t live_space() const {
   175     return (size_t)(avg_base_footprint()->average() +
   176                     avg_young_live()->average() +
   177                     avg_old_live()->average());
   178   }
   179   size_t free_space() const {
   180     return _eden_size + _promo_size;
   181   }
   183   void set_promo_size(size_t new_size) {
   184     _promo_size = new_size;
   185   }
   186   void set_survivor_size(size_t new_size) {
   187     _survivor_size = new_size;
   188   }
   190   // Update estimators
   191   void update_minor_pause_old_estimator(double minor_pause_in_ms);
   193   virtual GCPolicyKind kind() const { return _gc_ps_adaptive_size_policy; }
   195  public:
   196   // Use by ASPSYoungGen and ASPSOldGen to limit boundary moving.
   197   size_t eden_increment_aligned_up(size_t cur_eden);
   198   size_t eden_increment_aligned_down(size_t cur_eden);
   199   size_t promo_increment_aligned_up(size_t cur_promo);
   200   size_t promo_increment_aligned_down(size_t cur_promo);
   202   virtual size_t eden_increment(size_t cur_eden);
   203   virtual size_t promo_increment(size_t cur_promo);
   205   // Accessors for use by performance counters
   206   AdaptivePaddedNoZeroDevAverage*  avg_promoted() const {
   207     return _gc_stats.avg_promoted();
   208   }
   209   AdaptiveWeightedAverage* avg_base_footprint() const {
   210     return _avg_base_footprint;
   211   }
   213   // Input arguments are initial free space sizes for young and old
   214   // generations, the initial survivor space size, the
   215   // alignment values and the pause & throughput goals.
   216   //
   217   // NEEDS_CLEANUP this is a singleton object
   218   PSAdaptiveSizePolicy(size_t init_eden_size,
   219                        size_t init_promo_size,
   220                        size_t init_survivor_size,
   221                        size_t intra_generation_alignment,
   222                        double gc_pause_goal_sec,
   223                        double gc_minor_pause_goal_sec,
   224                        uint gc_time_ratio);
   226   // Methods indicating events of interest to the adaptive size policy,
   227   // called by GC algorithms. It is the responsibility of users of this
   228   // policy to call these methods at the correct times!
   229   void major_collection_begin();
   230   void major_collection_end(size_t amount_live, GCCause::Cause gc_cause);
   232   //
   233   void tenured_allocation(size_t size) {
   234     _avg_pretenured->sample(size);
   235   }
   237   // Accessors
   238   // NEEDS_CLEANUP   should use sizes.hpp
   240   size_t calculated_old_free_size_in_bytes() const {
   241     return (size_t)(_promo_size + avg_promoted()->padded_average());
   242   }
   244   size_t average_old_live_in_bytes() const {
   245     return (size_t) avg_old_live()->average();
   246   }
   248   size_t average_promoted_in_bytes() const {
   249     return (size_t)avg_promoted()->average();
   250   }
   252   size_t padded_average_promoted_in_bytes() const {
   253     return (size_t)avg_promoted()->padded_average();
   254   }
   256   int change_young_gen_for_maj_pauses() {
   257     return _change_young_gen_for_maj_pauses;
   258   }
   259   void set_change_young_gen_for_maj_pauses(int v) {
   260     _change_young_gen_for_maj_pauses = v;
   261   }
   263   int change_old_gen_for_min_pauses() {
   264     return _change_old_gen_for_min_pauses;
   265   }
   266   void set_change_old_gen_for_min_pauses(int v) {
   267     _change_old_gen_for_min_pauses = v;
   268   }
   270   // Return true if the old generation size was changed
   271   // to try to reach a pause time goal.
   272   bool old_gen_changed_for_pauses() {
   273     bool result = _change_old_gen_for_maj_pauses != 0 ||
   274                   _change_old_gen_for_min_pauses != 0;
   275     return result;
   276   }
   278   // Return true if the young generation size was changed
   279   // to try to reach a pause time goal.
   280   bool young_gen_changed_for_pauses() {
   281     bool result = _change_young_gen_for_min_pauses != 0 ||
   282                   _change_young_gen_for_maj_pauses != 0;
   283     return result;
   284   }
   285   // end flags for pause goal
   287   // Return true if the old generation size was changed
   288   // to try to reach a throughput goal.
   289   bool old_gen_changed_for_throughput() {
   290     bool result = _change_old_gen_for_throughput != 0;
   291     return result;
   292   }
   294   // Return true if the young generation size was changed
   295   // to try to reach a throughput goal.
   296   bool young_gen_changed_for_throughput() {
   297     bool result = _change_young_gen_for_throughput != 0;
   298     return result;
   299   }
   301   int decrease_for_footprint() { return _decrease_for_footprint; }
   304   // Accessors for estimators.  The slope of the linear fit is
   305   // currently all that is used for making decisions.
   307   LinearLeastSquareFit* major_pause_old_estimator() {
   308     return _major_pause_old_estimator;
   309   }
   311   LinearLeastSquareFit* major_pause_young_estimator() {
   312     return _major_pause_young_estimator;
   313   }
   316   virtual void clear_generation_free_space_flags();
   318   float major_pause_old_slope() { return _major_pause_old_estimator->slope(); }
   319   float major_pause_young_slope() {
   320     return _major_pause_young_estimator->slope();
   321   }
   322   float major_collection_slope() { return _major_collection_estimator->slope();}
   324   bool old_gen_policy_is_ready() { return _old_gen_policy_is_ready; }
   326   // Given the amount of live data in the heap, should we
   327   // perform a Full GC?
   328   bool should_full_GC(size_t live_in_old_gen);
   330   // Calculates optimial free space sizes for both the old and young
   331   // generations.  Stores results in _eden_size and _promo_size.
   332   // Takes current used space in all generations as input, as well
   333   // as an indication if a full gc has just been performed, for use
   334   // in deciding if an OOM error should be thrown.
   335   void compute_generation_free_space(size_t young_live,
   336                                      size_t eden_live,
   337                                      size_t old_live,
   338                                      size_t perm_live,
   339                                      size_t cur_eden,  // current eden in bytes
   340                                      size_t max_old_gen_size,
   341                                      size_t max_eden_size,
   342                                      bool   is_full_gc,
   343                                      GCCause::Cause gc_cause);
   345   // Calculates new survivor space size;  returns a new tenuring threshold
   346   // value. Stores new survivor size in _survivor_size.
   347   int compute_survivor_space_size_and_threshold(bool   is_survivor_overflow,
   348                                                 int    tenuring_threshold,
   349                                                 size_t survivor_limit);
   351   // Return the maximum size of a survivor space if the young generation were of
   352   // size gen_size.
   353   size_t max_survivor_size(size_t gen_size) {
   354     // Never allow the target survivor size to grow more than MinSurvivorRatio
   355     // of the young generation size.  We cannot grow into a two semi-space
   356     // system, with Eden zero sized.  Even if the survivor space grows, from()
   357     // might grow by moving the bottom boundary "down" -- so from space will
   358     // remain almost full anyway (top() will be near end(), but there will be a
   359     // large filler object at the bottom).
   360     const size_t sz = gen_size / MinSurvivorRatio;
   361     const size_t alignment = _intra_generation_alignment;
   362     return sz > alignment ? align_size_down(sz, alignment) : alignment;
   363   }
   365   size_t live_at_last_full_gc() {
   366     return _live_at_last_full_gc;
   367   }
   369   size_t bytes_absorbed_from_eden() const { return _bytes_absorbed_from_eden; }
   370   void   reset_bytes_absorbed_from_eden() { _bytes_absorbed_from_eden = 0; }
   372   void set_bytes_absorbed_from_eden(size_t val) {
   373     _bytes_absorbed_from_eden = val;
   374   }
   376   // Update averages that are always used (even
   377   // if adaptive sizing is turned off).
   378   void update_averages(bool is_survivor_overflow,
   379                        size_t survived,
   380                        size_t promoted);
   382   // Printing support
   383   virtual bool print_adaptive_size_policy_on(outputStream* st) const;
   384 };

mercurial