src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/gc_implementation/parallelScavenge

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

Print this page
rev 5803 : 8028391: Make the Min/MaxHeapFreeRatio flags manageable
Summary: Made the flags Min- and MaxHeapFreeRatio manageable, and implemented support for these flags in ParallalGC.
Reviewed-by: sla, mgerdin, brutisso


   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"

  26 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
  27 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
  28 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
  29 #include "gc_implementation/shared/gcPolicyCounters.hpp"
  30 #include "gc_interface/gcCause.hpp"
  31 #include "memory/collectorPolicy.hpp"
  32 #include "runtime/timer.hpp"
  33 #include "utilities/top.hpp"
  34 
  35 #include <math.h>
  36 
  37 PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
  38                                            size_t init_promo_size,
  39                                            size_t init_survivor_size,
  40                                            size_t space_alignment,
  41                                            double gc_pause_goal_sec,
  42                                            double gc_minor_pause_goal_sec,
  43                                            uint gc_cost_ratio) :
  44      AdaptiveSizePolicy(init_eden_size,
  45                         init_promo_size,


  59   _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
  60   _avg_major_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
  61 
  62   _avg_base_footprint = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
  63   _major_pause_old_estimator =
  64     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  65   _major_pause_young_estimator =
  66     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  67   _major_collection_estimator =
  68     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  69 
  70   _young_gen_size_increment_supplement = YoungGenerationSizeSupplement;
  71   _old_gen_size_increment_supplement = TenuredGenerationSizeSupplement;
  72 
  73   // Start the timers
  74   _major_timer.start();
  75 
  76   _old_gen_policy_is_ready = false;
  77 }
  78 
































  79 void PSAdaptiveSizePolicy::major_collection_begin() {
  80   // Update the interval time
  81   _major_timer.stop();
  82   // Save most recent collection time
  83   _latest_major_mutator_interval_seconds = _major_timer.seconds();
  84   _major_timer.reset();
  85   _major_timer.start();
  86 }
  87 
  88 void PSAdaptiveSizePolicy::update_minor_pause_old_estimator(
  89     double minor_pause_in_ms) {
  90   double promo_size_in_mbytes = ((double)_promo_size)/((double)M);
  91   _minor_pause_old_estimator->update(promo_size_in_mbytes,
  92     minor_pause_in_ms);
  93 }
  94 
  95 void PSAdaptiveSizePolicy::major_collection_end(size_t amount_live,
  96   GCCause::Cause gc_cause) {
  97   // Update the pause time.
  98   _major_timer.stop();


1275 
1276   if (PrintAdaptiveSizePolicy) {
1277     gclog_or_tty->print_cr(
1278                   "AdaptiveSizePolicy::update_averages:"
1279                   "  survived: "  SIZE_FORMAT
1280                   "  promoted: "  SIZE_FORMAT
1281                   "  overflow: %s",
1282                   survived, promoted, is_survivor_overflow ? "true" : "false");
1283   }
1284 }
1285 
1286 bool PSAdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st)
1287   const {
1288 
1289   if (!UseAdaptiveSizePolicy) return false;
1290 
1291   return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1292                           st,
1293                           PSScavenge::tenuring_threshold());
1294 }

















   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  27 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
  28 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
  29 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
  30 #include "gc_implementation/shared/gcPolicyCounters.hpp"
  31 #include "gc_interface/gcCause.hpp"
  32 #include "memory/collectorPolicy.hpp"
  33 #include "runtime/timer.hpp"
  34 #include "utilities/top.hpp"
  35 
  36 #include <math.h>
  37 
  38 PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
  39                                            size_t init_promo_size,
  40                                            size_t init_survivor_size,
  41                                            size_t space_alignment,
  42                                            double gc_pause_goal_sec,
  43                                            double gc_minor_pause_goal_sec,
  44                                            uint gc_cost_ratio) :
  45      AdaptiveSizePolicy(init_eden_size,
  46                         init_promo_size,


  60   _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
  61   _avg_major_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
  62 
  63   _avg_base_footprint = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
  64   _major_pause_old_estimator =
  65     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  66   _major_pause_young_estimator =
  67     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  68   _major_collection_estimator =
  69     new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
  70 
  71   _young_gen_size_increment_supplement = YoungGenerationSizeSupplement;
  72   _old_gen_size_increment_supplement = TenuredGenerationSizeSupplement;
  73 
  74   // Start the timers
  75   _major_timer.start();
  76 
  77   _old_gen_policy_is_ready = false;
  78 }
  79 
  80 size_t PSAdaptiveSizePolicy::calculate_free_based_on_live(size_t live, uintx ratio_as_percentage) {
  81   // We want to calculate how much free memory there can be based on the
  82   // amount of live data currently in the old gen. Using the formula:
  83   // ratio * (free + live) = free
  84   // Some equation solving later we get:
  85   // free = (live * ratio) / (1 - ratio)
  86 
  87   const double ratio = ratio_as_percentage / 100.0;
  88   const double ratio_inverse = 1.0 - ratio;
  89   const double tmp = live * ratio;
  90   size_t free = (size_t)(tmp / ratio_inverse);
  91 
  92   return free;
  93 }
  94 
  95 size_t PSAdaptiveSizePolicy::calculated_old_free_size_in_bytes() const {
  96   size_t free_size = (size_t)(_promo_size + avg_promoted()->padded_average());
  97   size_t live = ParallelScavengeHeap::heap()->old_gen()->used_in_bytes();
  98 
  99   if (MinHeapFreeRatio != 0) {
 100     size_t min_free = calculate_free_based_on_live(live, MinHeapFreeRatio);
 101     free_size = MAX2(free_size, min_free);
 102   }
 103 
 104   if (MaxHeapFreeRatio != 100) {
 105     size_t max_free = calculate_free_based_on_live(live, MaxHeapFreeRatio);
 106     free_size = MIN2(max_free, free_size);
 107   }
 108 
 109   return free_size;
 110 }
 111 
 112 void PSAdaptiveSizePolicy::major_collection_begin() {
 113   // Update the interval time
 114   _major_timer.stop();
 115   // Save most recent collection time
 116   _latest_major_mutator_interval_seconds = _major_timer.seconds();
 117   _major_timer.reset();
 118   _major_timer.start();
 119 }
 120 
 121 void PSAdaptiveSizePolicy::update_minor_pause_old_estimator(
 122     double minor_pause_in_ms) {
 123   double promo_size_in_mbytes = ((double)_promo_size)/((double)M);
 124   _minor_pause_old_estimator->update(promo_size_in_mbytes,
 125     minor_pause_in_ms);
 126 }
 127 
 128 void PSAdaptiveSizePolicy::major_collection_end(size_t amount_live,
 129   GCCause::Cause gc_cause) {
 130   // Update the pause time.
 131   _major_timer.stop();


1308 
1309   if (PrintAdaptiveSizePolicy) {
1310     gclog_or_tty->print_cr(
1311                   "AdaptiveSizePolicy::update_averages:"
1312                   "  survived: "  SIZE_FORMAT
1313                   "  promoted: "  SIZE_FORMAT
1314                   "  overflow: %s",
1315                   survived, promoted, is_survivor_overflow ? "true" : "false");
1316   }
1317 }
1318 
1319 bool PSAdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st)
1320   const {
1321 
1322   if (!UseAdaptiveSizePolicy) return false;
1323 
1324   return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1325                           st,
1326                           PSScavenge::tenuring_threshold());
1327 }
1328 
1329 #ifndef PRODUCT
1330 
1331 void TestOldFreeSpaceCalculation_test() {
1332   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 20) == 25, "Calculation of free memory failed");
1333   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 50) == 100, "Calculation of free memory failed");
1334   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 60) == 150, "Calculation of free memory failed");
1335   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 75) == 300, "Calculation of free memory failed");
1336   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 20) == 100, "Calculation of free memory failed");
1337   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 50) == 400, "Calculation of free memory failed");
1338   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 60) == 600, "Calculation of free memory failed");
1339   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 75) == 1200, "Calculation of free memory failed");
1340 }
1341 
1342 #endif /* !PRODUCT */
src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File