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




  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 intra_generation_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,
  46                         init_survivor_size,
  47                         gc_pause_goal_sec,
  48                         gc_cost_ratio),
  49      _collection_cost_margin_fraction(AdaptiveSizePolicyCollectionCostMargin / 100.0),
  50      _intra_generation_alignment(intra_generation_alignment),
  51      _live_at_last_full_gc(init_promo_size),
  52      _gc_minor_pause_goal_sec(gc_minor_pause_goal_sec),
  53      _latest_major_mutator_interval_seconds(0),
  54      _young_gen_change_for_major_pause_count(0)
  55 {
  56   // Sizing policy statistics
  57   _avg_major_pause    =
  58     new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
  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;


 335             "PSAdaptiveSizePolicy::compute_eden_space_size limits:"
 336             " desired_eden_size: " SIZE_FORMAT
 337             " old_eden_size: " SIZE_FORMAT
 338             " eden_limit: " SIZE_FORMAT
 339             " cur_eden: " SIZE_FORMAT
 340             " max_eden_size: " SIZE_FORMAT
 341             " avg_young_live: " SIZE_FORMAT,
 342             desired_eden_size, _eden_size, eden_limit, cur_eden,
 343             max_eden_size, (size_t)avg_young_live()->average());
 344     }
 345     if (gc_cost() > gc_cost_limit) {
 346       gclog_or_tty->print_cr(
 347             "PSAdaptiveSizePolicy::compute_eden_space_size: gc time limit"
 348             " gc_cost: %f "
 349             " GCTimeLimit: %d",
 350             gc_cost(), GCTimeLimit);
 351     }
 352   }
 353 
 354   // Align everything and make a final limit check
 355   const size_t alignment = _intra_generation_alignment;
 356   desired_eden_size  = align_size_up(desired_eden_size, alignment);
 357   desired_eden_size  = MAX2(desired_eden_size, alignment);
 358 
 359   eden_limit  = align_size_down(eden_limit, alignment);
 360 
 361   // And one last limit check, now that we've aligned things.
 362   if (desired_eden_size > eden_limit) {
 363     // If the policy says to get a larger eden but
 364     // is hitting the limit, don't decrease eden.
 365     // This can lead to a general drifting down of the
 366     // eden size.  Let the tenuring calculation push more
 367     // into the old gen.
 368     desired_eden_size = MAX2(eden_limit, cur_eden);
 369   }
 370 
 371   if (PrintAdaptiveSizePolicy) {
 372     // Timing stats
 373     gclog_or_tty->print(
 374                "PSAdaptiveSizePolicy::compute_eden_space_size: costs"
 375                " minor_time: %f"
 376                " major_cost: %f"
 377                " mutator_cost: %f"
 378                " throughput_goal: %f",
 379                minor_gc_cost(), major_gc_cost(), mutator_cost(),


 543       gclog_or_tty->print_cr(
 544             "PSAdaptiveSizePolicy::compute_old_gen_free_space limits:"
 545             " desired_promo_size: " SIZE_FORMAT
 546             " promo_limit: " SIZE_FORMAT
 547             " free_in_old_gen: " SIZE_FORMAT
 548             " max_old_gen_size: " SIZE_FORMAT
 549             " avg_old_live: " SIZE_FORMAT,
 550             desired_promo_size, promo_limit, free_in_old_gen,
 551             max_old_gen_size, (size_t) avg_old_live()->average());
 552     }
 553     if (gc_cost() > gc_cost_limit) {
 554       gclog_or_tty->print_cr(
 555             "PSAdaptiveSizePolicy::compute_old_gen_free_space: gc time limit"
 556             " gc_cost: %f "
 557             " GCTimeLimit: %d",
 558             gc_cost(), GCTimeLimit);
 559     }
 560   }
 561 
 562   // Align everything and make a final limit check
 563   const size_t alignment = _intra_generation_alignment;
 564   desired_promo_size = align_size_up(desired_promo_size, alignment);
 565   desired_promo_size = MAX2(desired_promo_size, alignment);
 566 
 567   promo_limit = align_size_down(promo_limit, alignment);
 568 
 569   // And one last limit check, now that we've aligned things.
 570   desired_promo_size = MIN2(desired_promo_size, promo_limit);
 571 
 572   if (PrintAdaptiveSizePolicy) {
 573     // Timing stats
 574     gclog_or_tty->print(
 575                "PSAdaptiveSizePolicy::compute_old_gen_free_space: costs"
 576                " minor_time: %f"
 577                " major_cost: %f"
 578                " mutator_cost: %f"
 579                " throughput_goal: %f",
 580                minor_gc_cost(), major_gc_cost(), mutator_cost(),
 581                _throughput_goal);
 582 
 583     // We give more details if Verbose is set
 584     if (Verbose) {
 585       gclog_or_tty->print( " minor_pause: %f"
 586                   " major_pause: %f"
 587                   " minor_interval: %f"


 632         _old_gen_size_increment_supplement >> 1;
 633     }
 634   } else {
 635     if ((_avg_minor_pause->count() >= AdaptiveSizePolicyReadyThreshold) &&
 636         (_avg_minor_pause->count() % YoungGenerationSizeSupplementDecay) == 0) {
 637       _young_gen_size_increment_supplement =
 638         _young_gen_size_increment_supplement >> 1;
 639     }
 640   }
 641 }
 642 
 643 void PSAdaptiveSizePolicy::adjust_promo_for_minor_pause_time(bool is_full_gc,
 644     size_t* desired_promo_size_ptr, size_t* desired_eden_size_ptr) {
 645 
 646   if (PSAdjustTenuredGenForMinorPause) {
 647     if (is_full_gc) {
 648       set_decide_at_full_gc(decide_at_full_gc_true);
 649     }
 650     // If the desired eden size is as small as it will get,
 651     // try to adjust the old gen size.
 652     if (*desired_eden_size_ptr <= _intra_generation_alignment) {
 653       // Vary the old gen size to reduce the young gen pause.  This
 654       // may not be a good idea.  This is just a test.
 655       if (minor_pause_old_estimator()->decrement_will_decrease()) {
 656         set_change_old_gen_for_min_pauses(decrease_old_gen_for_min_pauses_true);
 657         *desired_promo_size_ptr =
 658           _promo_size - promo_decrement_aligned_down(*desired_promo_size_ptr);
 659       } else {
 660         set_change_old_gen_for_min_pauses(increase_old_gen_for_min_pauses_true);
 661         size_t promo_heap_delta =
 662           promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr);
 663         if ((*desired_promo_size_ptr + promo_heap_delta) >
 664             *desired_promo_size_ptr) {
 665           *desired_promo_size_ptr =
 666             _promo_size + promo_heap_delta;
 667         }
 668       }
 669     }
 670   }
 671 }
 672 


 737 
 738 void PSAdaptiveSizePolicy::adjust_eden_for_pause_time(bool is_full_gc,
 739                                              size_t* desired_promo_size_ptr,
 740                                              size_t* desired_eden_size_ptr) {
 741 
 742   size_t eden_heap_delta = 0;
 743   // Add some checks for a threshold for a change.  For example,
 744   // a change less than the required alignment is probably not worth
 745   // attempting.
 746   if (_avg_minor_pause->padded_average() > _avg_major_pause->padded_average()) {
 747     adjust_eden_for_minor_pause_time(is_full_gc,
 748                                 desired_eden_size_ptr);
 749     // major pause adjustments
 750   } else if (is_full_gc) {
 751     // Adjust for the major pause time only at full gc's because the
 752     // affects of a change can only be seen at full gc's.
 753     if (PSAdjustYoungGenForMajorPause) {
 754       // If the promo size is at the minimum (i.e., the old gen
 755       // size will not actually decrease), consider changing the
 756       // young gen size.
 757       if (*desired_promo_size_ptr < _intra_generation_alignment) {
 758         // If increasing the young generation will decrease the old gen
 759         // pause, do it.
 760         // During startup there is noise in the statistics for deciding
 761         // on whether to increase or decrease the young gen size.  For
 762         // some number of iterations, just try to increase the young
 763         // gen size if the major pause is too long to try and establish
 764         // good statistics for later decisions.
 765         if (major_pause_young_estimator()->increment_will_decrease() ||
 766           (_young_gen_change_for_major_pause_count
 767             <= AdaptiveSizePolicyInitializingSteps)) {
 768           set_change_young_gen_for_maj_pauses(
 769           increase_young_gen_for_maj_pauses_true);
 770           eden_heap_delta = eden_increment_aligned_up(*desired_eden_size_ptr);
 771           *desired_eden_size_ptr = _eden_size + eden_heap_delta;
 772           _young_gen_change_for_major_pause_count++;
 773         } else {
 774           // Record that decreasing the young gen size would decrease
 775           // the major pause
 776           set_change_young_gen_for_maj_pauses(
 777             decrease_young_gen_for_maj_pauses_true);


1048     double fraction =  part / total;
1049     reduced_change = (size_t) (fraction * (double) change);
1050   }
1051   assert(reduced_change <= change, "Inconsistent result");
1052   return reduced_change;
1053 }
1054 
1055 size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden,
1056                                             uint percent_change) {
1057   size_t eden_heap_delta;
1058   eden_heap_delta = cur_eden / 100 * percent_change;
1059   return eden_heap_delta;
1060 }
1061 
1062 size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden) {
1063   return eden_increment(cur_eden, YoungGenerationSizeIncrement);
1064 }
1065 
1066 size_t PSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) {
1067   size_t result = eden_increment(cur_eden, YoungGenerationSizeIncrement);
1068   return align_size_up(result, _intra_generation_alignment);
1069 }
1070 
1071 size_t PSAdaptiveSizePolicy::eden_increment_aligned_down(size_t cur_eden) {
1072   size_t result = eden_increment(cur_eden);
1073   return align_size_down(result, _intra_generation_alignment);
1074 }
1075 
1076 size_t PSAdaptiveSizePolicy::eden_increment_with_supplement_aligned_up(
1077   size_t cur_eden) {
1078   size_t result = eden_increment(cur_eden,
1079     YoungGenerationSizeIncrement + _young_gen_size_increment_supplement);
1080   return align_size_up(result, _intra_generation_alignment);
1081 }
1082 
1083 size_t PSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) {
1084   size_t eden_heap_delta = eden_decrement(cur_eden);
1085   return align_size_down(eden_heap_delta, _intra_generation_alignment);
1086 }
1087 
1088 size_t PSAdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
1089   size_t eden_heap_delta = eden_increment(cur_eden) /
1090     AdaptiveSizeDecrementScaleFactor;
1091   return eden_heap_delta;
1092 }
1093 
1094 size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo,
1095                                              uint percent_change) {
1096   size_t promo_heap_delta;
1097   promo_heap_delta = cur_promo / 100 * percent_change;
1098   return promo_heap_delta;
1099 }
1100 
1101 size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo) {
1102   return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1103 }
1104 
1105 size_t PSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) {
1106   size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1107   return align_size_up(result, _intra_generation_alignment);
1108 }
1109 
1110 size_t PSAdaptiveSizePolicy::promo_increment_aligned_down(size_t cur_promo) {
1111   size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1112   return align_size_down(result, _intra_generation_alignment);
1113 }
1114 
1115 size_t PSAdaptiveSizePolicy::promo_increment_with_supplement_aligned_up(
1116   size_t cur_promo) {
1117   size_t result =  promo_increment(cur_promo,
1118     TenuredGenerationSizeIncrement + _old_gen_size_increment_supplement);
1119   return align_size_up(result, _intra_generation_alignment);
1120 }
1121 
1122 size_t PSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) {
1123   size_t promo_heap_delta = promo_decrement(cur_promo);
1124   return align_size_down(promo_heap_delta, _intra_generation_alignment);
1125 }
1126 
1127 size_t PSAdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
1128   size_t promo_heap_delta = promo_increment(cur_promo);
1129   promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
1130   return promo_heap_delta;
1131 }
1132 
1133 uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
1134                                              bool is_survivor_overflow,
1135                                              uint tenuring_threshold,
1136                                              size_t survivor_limit) {
1137   assert(survivor_limit >= _intra_generation_alignment,
1138          "survivor_limit too small");
1139   assert((size_t)align_size_down(survivor_limit, _intra_generation_alignment)
1140          == survivor_limit, "survivor_limit not aligned");
1141 
1142   // This method is called even if the tenuring threshold and survivor
1143   // spaces are not adjusted so that the averages are sampled above.
1144   if (!UsePSAdaptiveSurvivorSizePolicy ||
1145       !young_gen_policy_is_ready()) {
1146     return tenuring_threshold;
1147   }
1148 
1149   // We'll decide whether to increase or decrease the tenuring
1150   // threshold based partly on the newly computed survivor size
1151   // (if we hit the maximum limit allowed, we'll always choose to
1152   // decrement the threshold).
1153   bool incr_tenuring_threshold = false;
1154   bool decr_tenuring_threshold = false;
1155 
1156   set_decrement_tenuring_threshold_for_gc_cost(false);
1157   set_increment_tenuring_threshold_for_gc_cost(false);
1158   set_decrement_tenuring_threshold_for_survivor_limit(false);
1159 


1183     }
1184 
1185   } else {
1186     // Survivor space overflow occurred, so promoted and survived are
1187     // not accurate. We'll make our best guess by combining survived
1188     // and promoted and count them as survivors.
1189     //
1190     // We'll lower the tenuring threshold to see if we can correct
1191     // things. Also, set the survivor size conservatively. We're
1192     // trying to avoid many overflows from occurring if defnew size
1193     // is just too small.
1194 
1195     decr_tenuring_threshold = true;
1196   }
1197 
1198   // The padded average also maintains a deviation from the average;
1199   // we use this to see how good of an estimate we have of what survived.
1200   // We're trying to pad the survivor size as little as possible without
1201   // overflowing the survivor spaces.
1202   size_t target_size = align_size_up((size_t)_avg_survived->padded_average(),
1203                                      _intra_generation_alignment);
1204   target_size = MAX2(target_size, _intra_generation_alignment);
1205 
1206   if (target_size > survivor_limit) {
1207     // Target size is bigger than we can handle. Let's also reduce
1208     // the tenuring threshold.
1209     target_size = survivor_limit;
1210     decr_tenuring_threshold = true;
1211     set_decrement_tenuring_threshold_for_survivor_limit(true);
1212   }
1213 
1214   // Finally, increment or decrement the tenuring threshold, as decided above.
1215   // We test for decrementing first, as we might have hit the target size
1216   // limit.
1217   if (decr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
1218     if (tenuring_threshold > 1) {
1219       tenuring_threshold--;
1220     }
1221   } else if (incr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
1222     if (tenuring_threshold < MaxTenuringThreshold) {
1223       tenuring_threshold++;
1224     }




  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,
  46                         init_survivor_size,
  47                         gc_pause_goal_sec,
  48                         gc_cost_ratio),
  49      _collection_cost_margin_fraction(AdaptiveSizePolicyCollectionCostMargin / 100.0),
  50      _space_alignment(space_alignment),
  51      _live_at_last_full_gc(init_promo_size),
  52      _gc_minor_pause_goal_sec(gc_minor_pause_goal_sec),
  53      _latest_major_mutator_interval_seconds(0),
  54      _young_gen_change_for_major_pause_count(0)
  55 {
  56   // Sizing policy statistics
  57   _avg_major_pause    =
  58     new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
  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;


 335             "PSAdaptiveSizePolicy::compute_eden_space_size limits:"
 336             " desired_eden_size: " SIZE_FORMAT
 337             " old_eden_size: " SIZE_FORMAT
 338             " eden_limit: " SIZE_FORMAT
 339             " cur_eden: " SIZE_FORMAT
 340             " max_eden_size: " SIZE_FORMAT
 341             " avg_young_live: " SIZE_FORMAT,
 342             desired_eden_size, _eden_size, eden_limit, cur_eden,
 343             max_eden_size, (size_t)avg_young_live()->average());
 344     }
 345     if (gc_cost() > gc_cost_limit) {
 346       gclog_or_tty->print_cr(
 347             "PSAdaptiveSizePolicy::compute_eden_space_size: gc time limit"
 348             " gc_cost: %f "
 349             " GCTimeLimit: %d",
 350             gc_cost(), GCTimeLimit);
 351     }
 352   }
 353 
 354   // Align everything and make a final limit check
 355   desired_eden_size  = align_size_up(desired_eden_size, _space_alignment);
 356   desired_eden_size  = MAX2(desired_eden_size, _space_alignment);

 357 
 358   eden_limit  = align_size_down(eden_limit, _space_alignment);
 359 
 360   // And one last limit check, now that we've aligned things.
 361   if (desired_eden_size > eden_limit) {
 362     // If the policy says to get a larger eden but
 363     // is hitting the limit, don't decrease eden.
 364     // This can lead to a general drifting down of the
 365     // eden size.  Let the tenuring calculation push more
 366     // into the old gen.
 367     desired_eden_size = MAX2(eden_limit, cur_eden);
 368   }
 369 
 370   if (PrintAdaptiveSizePolicy) {
 371     // Timing stats
 372     gclog_or_tty->print(
 373                "PSAdaptiveSizePolicy::compute_eden_space_size: costs"
 374                " minor_time: %f"
 375                " major_cost: %f"
 376                " mutator_cost: %f"
 377                " throughput_goal: %f",
 378                minor_gc_cost(), major_gc_cost(), mutator_cost(),


 542       gclog_or_tty->print_cr(
 543             "PSAdaptiveSizePolicy::compute_old_gen_free_space limits:"
 544             " desired_promo_size: " SIZE_FORMAT
 545             " promo_limit: " SIZE_FORMAT
 546             " free_in_old_gen: " SIZE_FORMAT
 547             " max_old_gen_size: " SIZE_FORMAT
 548             " avg_old_live: " SIZE_FORMAT,
 549             desired_promo_size, promo_limit, free_in_old_gen,
 550             max_old_gen_size, (size_t) avg_old_live()->average());
 551     }
 552     if (gc_cost() > gc_cost_limit) {
 553       gclog_or_tty->print_cr(
 554             "PSAdaptiveSizePolicy::compute_old_gen_free_space: gc time limit"
 555             " gc_cost: %f "
 556             " GCTimeLimit: %d",
 557             gc_cost(), GCTimeLimit);
 558     }
 559   }
 560 
 561   // Align everything and make a final limit check
 562   desired_promo_size = align_size_up(desired_promo_size, _space_alignment);
 563   desired_promo_size = MAX2(desired_promo_size, _space_alignment);

 564 
 565   promo_limit = align_size_down(promo_limit, _space_alignment);
 566 
 567   // And one last limit check, now that we've aligned things.
 568   desired_promo_size = MIN2(desired_promo_size, promo_limit);
 569 
 570   if (PrintAdaptiveSizePolicy) {
 571     // Timing stats
 572     gclog_or_tty->print(
 573                "PSAdaptiveSizePolicy::compute_old_gen_free_space: costs"
 574                " minor_time: %f"
 575                " major_cost: %f"
 576                " mutator_cost: %f"
 577                " throughput_goal: %f",
 578                minor_gc_cost(), major_gc_cost(), mutator_cost(),
 579                _throughput_goal);
 580 
 581     // We give more details if Verbose is set
 582     if (Verbose) {
 583       gclog_or_tty->print( " minor_pause: %f"
 584                   " major_pause: %f"
 585                   " minor_interval: %f"


 630         _old_gen_size_increment_supplement >> 1;
 631     }
 632   } else {
 633     if ((_avg_minor_pause->count() >= AdaptiveSizePolicyReadyThreshold) &&
 634         (_avg_minor_pause->count() % YoungGenerationSizeSupplementDecay) == 0) {
 635       _young_gen_size_increment_supplement =
 636         _young_gen_size_increment_supplement >> 1;
 637     }
 638   }
 639 }
 640 
 641 void PSAdaptiveSizePolicy::adjust_promo_for_minor_pause_time(bool is_full_gc,
 642     size_t* desired_promo_size_ptr, size_t* desired_eden_size_ptr) {
 643 
 644   if (PSAdjustTenuredGenForMinorPause) {
 645     if (is_full_gc) {
 646       set_decide_at_full_gc(decide_at_full_gc_true);
 647     }
 648     // If the desired eden size is as small as it will get,
 649     // try to adjust the old gen size.
 650     if (*desired_eden_size_ptr <= _space_alignment) {
 651       // Vary the old gen size to reduce the young gen pause.  This
 652       // may not be a good idea.  This is just a test.
 653       if (minor_pause_old_estimator()->decrement_will_decrease()) {
 654         set_change_old_gen_for_min_pauses(decrease_old_gen_for_min_pauses_true);
 655         *desired_promo_size_ptr =
 656           _promo_size - promo_decrement_aligned_down(*desired_promo_size_ptr);
 657       } else {
 658         set_change_old_gen_for_min_pauses(increase_old_gen_for_min_pauses_true);
 659         size_t promo_heap_delta =
 660           promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr);
 661         if ((*desired_promo_size_ptr + promo_heap_delta) >
 662             *desired_promo_size_ptr) {
 663           *desired_promo_size_ptr =
 664             _promo_size + promo_heap_delta;
 665         }
 666       }
 667     }
 668   }
 669 }
 670 


 735 
 736 void PSAdaptiveSizePolicy::adjust_eden_for_pause_time(bool is_full_gc,
 737                                              size_t* desired_promo_size_ptr,
 738                                              size_t* desired_eden_size_ptr) {
 739 
 740   size_t eden_heap_delta = 0;
 741   // Add some checks for a threshold for a change.  For example,
 742   // a change less than the required alignment is probably not worth
 743   // attempting.
 744   if (_avg_minor_pause->padded_average() > _avg_major_pause->padded_average()) {
 745     adjust_eden_for_minor_pause_time(is_full_gc,
 746                                 desired_eden_size_ptr);
 747     // major pause adjustments
 748   } else if (is_full_gc) {
 749     // Adjust for the major pause time only at full gc's because the
 750     // affects of a change can only be seen at full gc's.
 751     if (PSAdjustYoungGenForMajorPause) {
 752       // If the promo size is at the minimum (i.e., the old gen
 753       // size will not actually decrease), consider changing the
 754       // young gen size.
 755       if (*desired_promo_size_ptr < _space_alignment) {
 756         // If increasing the young generation will decrease the old gen
 757         // pause, do it.
 758         // During startup there is noise in the statistics for deciding
 759         // on whether to increase or decrease the young gen size.  For
 760         // some number of iterations, just try to increase the young
 761         // gen size if the major pause is too long to try and establish
 762         // good statistics for later decisions.
 763         if (major_pause_young_estimator()->increment_will_decrease() ||
 764           (_young_gen_change_for_major_pause_count
 765             <= AdaptiveSizePolicyInitializingSteps)) {
 766           set_change_young_gen_for_maj_pauses(
 767           increase_young_gen_for_maj_pauses_true);
 768           eden_heap_delta = eden_increment_aligned_up(*desired_eden_size_ptr);
 769           *desired_eden_size_ptr = _eden_size + eden_heap_delta;
 770           _young_gen_change_for_major_pause_count++;
 771         } else {
 772           // Record that decreasing the young gen size would decrease
 773           // the major pause
 774           set_change_young_gen_for_maj_pauses(
 775             decrease_young_gen_for_maj_pauses_true);


1046     double fraction =  part / total;
1047     reduced_change = (size_t) (fraction * (double) change);
1048   }
1049   assert(reduced_change <= change, "Inconsistent result");
1050   return reduced_change;
1051 }
1052 
1053 size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden,
1054                                             uint percent_change) {
1055   size_t eden_heap_delta;
1056   eden_heap_delta = cur_eden / 100 * percent_change;
1057   return eden_heap_delta;
1058 }
1059 
1060 size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden) {
1061   return eden_increment(cur_eden, YoungGenerationSizeIncrement);
1062 }
1063 
1064 size_t PSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) {
1065   size_t result = eden_increment(cur_eden, YoungGenerationSizeIncrement);
1066   return align_size_up(result, _space_alignment);
1067 }
1068 
1069 size_t PSAdaptiveSizePolicy::eden_increment_aligned_down(size_t cur_eden) {
1070   size_t result = eden_increment(cur_eden);
1071   return align_size_down(result, _space_alignment);
1072 }
1073 
1074 size_t PSAdaptiveSizePolicy::eden_increment_with_supplement_aligned_up(
1075   size_t cur_eden) {
1076   size_t result = eden_increment(cur_eden,
1077     YoungGenerationSizeIncrement + _young_gen_size_increment_supplement);
1078   return align_size_up(result, _space_alignment);
1079 }
1080 
1081 size_t PSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) {
1082   size_t eden_heap_delta = eden_decrement(cur_eden);
1083   return align_size_down(eden_heap_delta, _space_alignment);
1084 }
1085 
1086 size_t PSAdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
1087   size_t eden_heap_delta = eden_increment(cur_eden) /
1088     AdaptiveSizeDecrementScaleFactor;
1089   return eden_heap_delta;
1090 }
1091 
1092 size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo,
1093                                              uint percent_change) {
1094   size_t promo_heap_delta;
1095   promo_heap_delta = cur_promo / 100 * percent_change;
1096   return promo_heap_delta;
1097 }
1098 
1099 size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo) {
1100   return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1101 }
1102 
1103 size_t PSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) {
1104   size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1105   return align_size_up(result, _space_alignment);
1106 }
1107 
1108 size_t PSAdaptiveSizePolicy::promo_increment_aligned_down(size_t cur_promo) {
1109   size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
1110   return align_size_down(result, _space_alignment);
1111 }
1112 
1113 size_t PSAdaptiveSizePolicy::promo_increment_with_supplement_aligned_up(
1114   size_t cur_promo) {
1115   size_t result =  promo_increment(cur_promo,
1116     TenuredGenerationSizeIncrement + _old_gen_size_increment_supplement);
1117   return align_size_up(result, _space_alignment);
1118 }
1119 
1120 size_t PSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) {
1121   size_t promo_heap_delta = promo_decrement(cur_promo);
1122   return align_size_down(promo_heap_delta, _space_alignment);
1123 }
1124 
1125 size_t PSAdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
1126   size_t promo_heap_delta = promo_increment(cur_promo);
1127   promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
1128   return promo_heap_delta;
1129 }
1130 
1131 uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
1132                                              bool is_survivor_overflow,
1133                                              uint tenuring_threshold,
1134                                              size_t survivor_limit) {
1135   assert(survivor_limit >= _space_alignment,
1136          "survivor_limit too small");
1137   assert((size_t)align_size_down(survivor_limit, _space_alignment)
1138          == survivor_limit, "survivor_limit not aligned");
1139 
1140   // This method is called even if the tenuring threshold and survivor
1141   // spaces are not adjusted so that the averages are sampled above.
1142   if (!UsePSAdaptiveSurvivorSizePolicy ||
1143       !young_gen_policy_is_ready()) {
1144     return tenuring_threshold;
1145   }
1146 
1147   // We'll decide whether to increase or decrease the tenuring
1148   // threshold based partly on the newly computed survivor size
1149   // (if we hit the maximum limit allowed, we'll always choose to
1150   // decrement the threshold).
1151   bool incr_tenuring_threshold = false;
1152   bool decr_tenuring_threshold = false;
1153 
1154   set_decrement_tenuring_threshold_for_gc_cost(false);
1155   set_increment_tenuring_threshold_for_gc_cost(false);
1156   set_decrement_tenuring_threshold_for_survivor_limit(false);
1157 


1181     }
1182 
1183   } else {
1184     // Survivor space overflow occurred, so promoted and survived are
1185     // not accurate. We'll make our best guess by combining survived
1186     // and promoted and count them as survivors.
1187     //
1188     // We'll lower the tenuring threshold to see if we can correct
1189     // things. Also, set the survivor size conservatively. We're
1190     // trying to avoid many overflows from occurring if defnew size
1191     // is just too small.
1192 
1193     decr_tenuring_threshold = true;
1194   }
1195 
1196   // The padded average also maintains a deviation from the average;
1197   // we use this to see how good of an estimate we have of what survived.
1198   // We're trying to pad the survivor size as little as possible without
1199   // overflowing the survivor spaces.
1200   size_t target_size = align_size_up((size_t)_avg_survived->padded_average(),
1201                                      _space_alignment);
1202   target_size = MAX2(target_size, _space_alignment);
1203 
1204   if (target_size > survivor_limit) {
1205     // Target size is bigger than we can handle. Let's also reduce
1206     // the tenuring threshold.
1207     target_size = survivor_limit;
1208     decr_tenuring_threshold = true;
1209     set_decrement_tenuring_threshold_for_survivor_limit(true);
1210   }
1211 
1212   // Finally, increment or decrement the tenuring threshold, as decided above.
1213   // We test for decrementing first, as we might have hit the target size
1214   // limit.
1215   if (decr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
1216     if (tenuring_threshold > 1) {
1217       tenuring_threshold--;
1218     }
1219   } else if (incr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
1220     if (tenuring_threshold < MaxTenuringThreshold) {
1221       tenuring_threshold++;
1222     }


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