162 // When copying, we will likely need more bytes free than is live in the region.
163 // Add some safety margin to factor in the confidence of our guess, and the
164 // natural expected waste.
165 // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
166 // of the calculation: the lower the confidence, the more headroom.
167 // (100 + TargetPLABWastePct) represents the increase in expected bytes during
168 // copying due to anticipated waste in the PLABs.
169 const double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
170 const size_t expected_bytes_to_copy = (size_t)(safety_factor * bytes_to_copy);
171
172 if (expected_bytes_to_copy > free_bytes) {
173 // end condition 3: out-of-space
174 return false;
175 }
176
177 // success!
178 return true;
179 }
180 };
181
182 void G1Policy::record_new_heap_size(uint new_number_of_regions) {
183 // re-calculate the necessary reserve
184 double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
185 // We use ceiling so that if reserve_regions_d is > 0.0 (but
186 // smaller than 1.0) we'll get 1.
187 _reserve_regions = (uint) ceil(reserve_regions_d);
188
189 _young_gen_sizer->heap_size_changed(new_number_of_regions);
190
191 _ihop_control->update_target_occupancy(new_number_of_regions * HeapRegion::GrainBytes);
192 }
193
194 uint G1Policy::calculate_young_list_desired_min_length(uint base_min_length) const {
195 uint desired_min_length = 0;
196 if (use_adaptive_young_list_length()) {
197 if (_analytics->num_alloc_rate_ms() > 3) {
198 double now_sec = os::elapsedTime();
199 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
200 double alloc_rate_ms = _analytics->predict_alloc_rate_ms();
201 desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
202 } else {
203 // otherwise we don't have enough info to make the prediction
204 }
205 }
206 desired_min_length += base_min_length;
207 // make sure we don't go below any user-defined minimum bound
208 return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
209 }
210
211 uint G1Policy::calculate_young_list_desired_max_length() const {
|
162 // When copying, we will likely need more bytes free than is live in the region.
163 // Add some safety margin to factor in the confidence of our guess, and the
164 // natural expected waste.
165 // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
166 // of the calculation: the lower the confidence, the more headroom.
167 // (100 + TargetPLABWastePct) represents the increase in expected bytes during
168 // copying due to anticipated waste in the PLABs.
169 const double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
170 const size_t expected_bytes_to_copy = (size_t)(safety_factor * bytes_to_copy);
171
172 if (expected_bytes_to_copy > free_bytes) {
173 // end condition 3: out-of-space
174 return false;
175 }
176
177 // success!
178 return true;
179 }
180 };
181
182 void G1Policy::record_new_target_heap_size(uint new_number_of_regions, uint reserve_regions) {
183 _reserve_regions = reserve_regions;
184 _young_gen_sizer->heap_size_changed(new_number_of_regions);
185 _ihop_control->update_target_occupancy(new_number_of_regions * HeapRegion::GrainBytes);
186 }
187
188 void G1Policy::update_heap_target_size(uint num_regions, uint soft_goal_num_regions) {
189 uint desired_number_of_regions = MIN2(num_regions, soft_goal_num_regions);
190
191 uint regular_reserve_regions = (uint)ceil((double)num_regions * G1ReservePercent / 100);
192 uint reserve_regions = regular_reserve_regions;
193 uint soft_reserve_regions = 0;
194
195 if (soft_goal_num_regions < num_regions) {
196 soft_reserve_regions = num_regions - soft_goal_num_regions +
197 (uint)ceil((double)soft_goal_num_regions * G1ReservePercent / 100);
198 reserve_regions = soft_reserve_regions;
199 }
200
201 // FIXME: this method is called very early during startup during initial heap expansion, so
202 // the _g1h member has not been set yet.
203 G1CollectedHeap* g1h = G1CollectedHeap::heap();
204 uint MBPerRegion = HeapRegion::GrainBytes / (1024 * 1024);
205 log_error(gc)("heap target update: soft-goal %u committed %u goal %u hard-reserve %u soft-reserve %u reserve %u free %u used %u",
206 soft_goal_num_regions * MBPerRegion, num_regions * MBPerRegion,
207 desired_number_of_regions * MBPerRegion,
208 regular_reserve_regions * MBPerRegion, soft_reserve_regions * MBPerRegion, reserve_regions * MBPerRegion,
209 g1h->num_free_regions() * MBPerRegion, g1h->num_used_regions() * MBPerRegion);
210
211 record_new_target_heap_size(desired_number_of_regions, reserve_regions);
212 }
213
214 uint G1Policy::calculate_young_list_desired_min_length(uint base_min_length) const {
215 uint desired_min_length = 0;
216 if (use_adaptive_young_list_length()) {
217 if (_analytics->num_alloc_rate_ms() > 3) {
218 double now_sec = os::elapsedTime();
219 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
220 double alloc_rate_ms = _analytics->predict_alloc_rate_ms();
221 desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
222 } else {
223 // otherwise we don't have enough info to make the prediction
224 }
225 }
226 desired_min_length += base_min_length;
227 // make sure we don't go below any user-defined minimum bound
228 return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
229 }
230
231 uint G1Policy::calculate_young_list_desired_max_length() const {
|