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




   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/generationSizer.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 intra_generation_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,


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
































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


1090 
1091   if (PrintAdaptiveSizePolicy) {
1092     gclog_or_tty->print(
1093                   "AdaptiveSizePolicy::compute_survivor_space_size_and_thresh:"
1094                   "  survived: "  SIZE_FORMAT
1095                   "  promoted: "  SIZE_FORMAT
1096                   "  overflow: %s",
1097                   survived, promoted, is_survivor_overflow ? "true" : "false");
1098   }
1099 }
1100 
1101 bool PSAdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st)
1102   const {
1103 
1104   if (!UseAdaptiveSizePolicy) return false;
1105 
1106   return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1107                           st,
1108                           PSScavenge::tenuring_threshold());
1109 }

















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


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


1123 
1124   if (PrintAdaptiveSizePolicy) {
1125     gclog_or_tty->print(
1126                   "AdaptiveSizePolicy::compute_survivor_space_size_and_thresh:"
1127                   "  survived: "  SIZE_FORMAT
1128                   "  promoted: "  SIZE_FORMAT
1129                   "  overflow: %s",
1130                   survived, promoted, is_survivor_overflow ? "true" : "false");
1131   }
1132 }
1133 
1134 bool PSAdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st)
1135   const {
1136 
1137   if (!UseAdaptiveSizePolicy) return false;
1138 
1139   return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1140                           st,
1141                           PSScavenge::tenuring_threshold());
1142 }
1143 
1144 #ifndef PRODUCT
1145 
1146 void TestOldFreeSpaceCalculation_test() {
1147   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 20) == 25, "Calculation of free memory failed");
1148   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 50) == 100, "Calculation of free memory failed");
1149   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 60) == 150, "Calculation of free memory failed");
1150   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 75) == 300, "Calculation of free memory failed");
1151   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 20) == 100, "Calculation of free memory failed");
1152   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 50) == 400, "Calculation of free memory failed");
1153   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 60) == 600, "Calculation of free memory failed");
1154   assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 75) == 1200, "Calculation of free memory failed");
1155 }
1156 
1157 #endif /* !PRODUCT */
src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File