hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp
changeset 37144 b7ae74d4d5d8
parent 37143 345ad6728be3
child 37158 b882bbfa1af0
equal deleted inserted replaced
37143:345ad6728be3 37144:b7ae74d4d5d8
    47   _analytics(new G1Analytics(&_predictor)),
    47   _analytics(new G1Analytics(&_predictor)),
    48   _pause_time_target_ms((double) MaxGCPauseMillis),
    48   _pause_time_target_ms((double) MaxGCPauseMillis),
    49   _rs_lengths_prediction(0),
    49   _rs_lengths_prediction(0),
    50   _max_survivor_regions(0),
    50   _max_survivor_regions(0),
    51   _survivors_age_table(true),
    51   _survivors_age_table(true),
    52   _gc_overhead_perc(0.0),
       
    53 
    52 
    54   _bytes_allocated_in_old_since_last_gc(0),
    53   _bytes_allocated_in_old_since_last_gc(0),
    55   _ihop_control(NULL),
    54   _ihop_control(NULL),
    56   _initial_mark_to_mixed() {
    55   _initial_mark_to_mixed() {
    57 
    56 
    73   // the region size on the heap size, but the heap size should be
    72   // the region size on the heap size, but the heap size should be
    74   // aligned with the region size. To get around this we use the
    73   // aligned with the region size. To get around this we use the
    75   // unaligned values for the heap.
    74   // unaligned values for the heap.
    76   HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize);
    75   HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize);
    77   HeapRegionRemSet::setup_remset_size();
    76   HeapRegionRemSet::setup_remset_size();
    78 
       
    79   clear_ratio_check_data();
       
    80 
    77 
    81   _phase_times = new G1GCPhaseTimes(ParallelGCThreads);
    78   _phase_times = new G1GCPhaseTimes(ParallelGCThreads);
    82 
    79 
    83   // Below, we might need to calculate the pause time target based on
    80   // Below, we might need to calculate the pause time target based on
    84   // the pause interval. When we do so we are going to give G1 maximum
    81   // the pause interval. When we do so we are going to give G1 maximum
   121   double time_slice  = (double) GCPauseIntervalMillis / 1000.0;
   118   double time_slice  = (double) GCPauseIntervalMillis / 1000.0;
   122   _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
   119   _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
   123 
   120 
   124   _tenuring_threshold = MaxTenuringThreshold;
   121   _tenuring_threshold = MaxTenuringThreshold;
   125 
   122 
   126   assert(GCTimeRatio > 0,
       
   127          "we should have set it to a default value set_g1_gc_flags() "
       
   128          "if a user set it to 0");
       
   129   _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
       
   130 
   123 
   131   guarantee(G1ReservePercent <= 50, "Range checking should not allow values over 50.");
   124   guarantee(G1ReservePercent <= 50, "Range checking should not allow values over 50.");
   132   _reserve_factor = (double) G1ReservePercent / 100.0;
   125   _reserve_factor = (double) G1ReservePercent / 100.0;
   133   // This will be set when the heap is expanded
   126   // This will be set when the heap is expanded
   134   // for the first time during initialization.
   127   // for the first time during initialization.
  1055     region_elapsed_time_ms += _analytics->predict_non_young_other_time_ms(1);
  1048     region_elapsed_time_ms += _analytics->predict_non_young_other_time_ms(1);
  1056   }
  1049   }
  1057   return region_elapsed_time_ms;
  1050   return region_elapsed_time_ms;
  1058 }
  1051 }
  1059 
  1052 
  1060 void G1CollectorPolicy::clear_ratio_check_data() {
       
  1061   _ratio_over_threshold_count = 0;
       
  1062   _ratio_over_threshold_sum = 0.0;
       
  1063   _pauses_since_start = 0;
       
  1064 }
       
  1065 
       
  1066 size_t G1CollectorPolicy::expansion_amount() {
       
  1067   double recent_gc_overhead = _analytics->recent_avg_pause_time_ratio() * 100.0;
       
  1068   double last_gc_overhead = _analytics->last_pause_time_ratio() * 100.0;
       
  1069   double threshold = _gc_overhead_perc;
       
  1070   size_t expand_bytes = 0;
       
  1071 
       
  1072   // If the heap is at less than half its maximum size, scale the threshold down,
       
  1073   // to a limit of 1. Thus the smaller the heap is, the more likely it is to expand,
       
  1074   // though the scaling code will likely keep the increase small.
       
  1075   if (_g1->capacity() <= _g1->max_capacity() / 2) {
       
  1076     threshold *= (double)_g1->capacity() / (double)(_g1->max_capacity() / 2);
       
  1077     threshold = MAX2(threshold, 1.0);
       
  1078   }
       
  1079 
       
  1080   // If the last GC time ratio is over the threshold, increment the count of
       
  1081   // times it has been exceeded, and add this ratio to the sum of exceeded
       
  1082   // ratios.
       
  1083   if (last_gc_overhead > threshold) {
       
  1084     _ratio_over_threshold_count++;
       
  1085     _ratio_over_threshold_sum += last_gc_overhead;
       
  1086   }
       
  1087 
       
  1088   // Check if we've had enough GC time ratio checks that were over the
       
  1089   // threshold to trigger an expansion. We'll also expand if we've
       
  1090   // reached the end of the history buffer and the average of all entries
       
  1091   // is still over the threshold. This indicates a smaller number of GCs were
       
  1092   // long enough to make the average exceed the threshold.
       
  1093   bool filled_history_buffer = _pauses_since_start == NumPrevPausesForHeuristics;
       
  1094   if ((_ratio_over_threshold_count == MinOverThresholdForGrowth) ||
       
  1095       (filled_history_buffer && (recent_gc_overhead > threshold))) {
       
  1096     size_t min_expand_bytes = HeapRegion::GrainBytes;
       
  1097     size_t reserved_bytes = _g1->max_capacity();
       
  1098     size_t committed_bytes = _g1->capacity();
       
  1099     size_t uncommitted_bytes = reserved_bytes - committed_bytes;
       
  1100     size_t expand_bytes_via_pct =
       
  1101       uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
       
  1102     double scale_factor = 1.0;
       
  1103 
       
  1104     // If the current size is less than 1/4 of the Initial heap size, expand
       
  1105     // by half of the delta between the current and Initial sizes. IE, grow
       
  1106     // back quickly.
       
  1107     //
       
  1108     // Otherwise, take the current size, or G1ExpandByPercentOfAvailable % of
       
  1109     // the available expansion space, whichever is smaller, as the base
       
  1110     // expansion size. Then possibly scale this size according to how much the
       
  1111     // threshold has (on average) been exceeded by. If the delta is small
       
  1112     // (less than the StartScaleDownAt value), scale the size down linearly, but
       
  1113     // not by less than MinScaleDownFactor. If the delta is large (greater than
       
  1114     // the StartScaleUpAt value), scale up, but adding no more than MaxScaleUpFactor
       
  1115     // times the base size. The scaling will be linear in the range from
       
  1116     // StartScaleUpAt to (StartScaleUpAt + ScaleUpRange). In other words,
       
  1117     // ScaleUpRange sets the rate of scaling up.
       
  1118     if (committed_bytes < InitialHeapSize / 4) {
       
  1119       expand_bytes = (InitialHeapSize - committed_bytes) / 2;
       
  1120     } else {
       
  1121       double const MinScaleDownFactor = 0.2;
       
  1122       double const MaxScaleUpFactor = 2;
       
  1123       double const StartScaleDownAt = _gc_overhead_perc;
       
  1124       double const StartScaleUpAt = _gc_overhead_perc * 1.5;
       
  1125       double const ScaleUpRange = _gc_overhead_perc * 2.0;
       
  1126 
       
  1127       double ratio_delta;
       
  1128       if (filled_history_buffer) {
       
  1129         ratio_delta = recent_gc_overhead - threshold;
       
  1130       } else {
       
  1131         ratio_delta = (_ratio_over_threshold_sum/_ratio_over_threshold_count) - threshold;
       
  1132       }
       
  1133 
       
  1134       expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
       
  1135       if (ratio_delta < StartScaleDownAt) {
       
  1136         scale_factor = ratio_delta / StartScaleDownAt;
       
  1137         scale_factor = MAX2(scale_factor, MinScaleDownFactor);
       
  1138       } else if (ratio_delta > StartScaleUpAt) {
       
  1139         scale_factor = 1 + ((ratio_delta - StartScaleUpAt) / ScaleUpRange);
       
  1140         scale_factor = MIN2(scale_factor, MaxScaleUpFactor);
       
  1141       }
       
  1142     }
       
  1143 
       
  1144     log_debug(gc, ergo, heap)("Attempt heap expansion (recent GC overhead higher than threshold after GC) "
       
  1145                               "recent GC overhead: %1.2f %% threshold: %1.2f %% uncommitted: " SIZE_FORMAT "B base expansion amount and scale: " SIZE_FORMAT "B (%1.2f%%)",
       
  1146                               recent_gc_overhead, threshold, uncommitted_bytes, expand_bytes, scale_factor * 100);
       
  1147 
       
  1148     expand_bytes = static_cast<size_t>(expand_bytes * scale_factor);
       
  1149 
       
  1150     // Ensure the expansion size is at least the minimum growth amount
       
  1151     // and at most the remaining uncommitted byte size.
       
  1152     expand_bytes = MAX2(expand_bytes, min_expand_bytes);
       
  1153     expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
       
  1154 
       
  1155     clear_ratio_check_data();
       
  1156   } else {
       
  1157     // An expansion was not triggered. If we've started counting, increment
       
  1158     // the number of checks we've made in the current window.  If we've
       
  1159     // reached the end of the window without resizing, clear the counters to
       
  1160     // start again the next time we see a ratio above the threshold.
       
  1161     if (_ratio_over_threshold_count > 0) {
       
  1162       _pauses_since_start++;
       
  1163       if (_pauses_since_start > NumPrevPausesForHeuristics) {
       
  1164         clear_ratio_check_data();
       
  1165       }
       
  1166     }
       
  1167   }
       
  1168 
       
  1169   return expand_bytes;
       
  1170 }
       
  1171 
  1053 
  1172 void G1CollectorPolicy::print_yg_surv_rate_info() const {
  1054 void G1CollectorPolicy::print_yg_surv_rate_info() const {
  1173 #ifndef PRODUCT
  1055 #ifndef PRODUCT
  1174   _short_lived_surv_rate_group->print_surv_rate_summary();
  1056   _short_lived_surv_rate_group->print_surv_rate_summary();
  1175   // add this call for any other surv rate groups
  1057   // add this call for any other surv rate groups