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 |