27 |
27 |
28 #include "gc/g1/collectionSetChooser.hpp" |
28 #include "gc/g1/collectionSetChooser.hpp" |
29 #include "gc/g1/g1CollectorState.hpp" |
29 #include "gc/g1/g1CollectorState.hpp" |
30 #include "gc/g1/g1InCSetState.hpp" |
30 #include "gc/g1/g1InCSetState.hpp" |
31 #include "gc/g1/g1MMUTracker.hpp" |
31 #include "gc/g1/g1MMUTracker.hpp" |
|
32 #include "gc/g1/g1Predictions.hpp" |
32 #include "gc/shared/collectorPolicy.hpp" |
33 #include "gc/shared/collectorPolicy.hpp" |
33 |
34 |
34 // A G1CollectorPolicy makes policy decisions that determine the |
35 // A G1CollectorPolicy makes policy decisions that determine the |
35 // characteristics of the collector. Examples include: |
36 // characteristics of the collector. Examples include: |
36 // * choice of collection set. |
37 // * choice of collection set. |
159 return _adaptive_size; |
160 return _adaptive_size; |
160 } |
161 } |
161 }; |
162 }; |
162 |
163 |
163 class G1CollectorPolicy: public CollectorPolicy { |
164 class G1CollectorPolicy: public CollectorPolicy { |
164 private: |
165 private: |
|
166 G1Predictions _predictor; |
|
167 |
|
168 double get_new_prediction(TruncatedSeq const* seq) const; |
|
169 |
165 // either equal to the number of parallel threads, if ParallelGCThreads |
170 // either equal to the number of parallel threads, if ParallelGCThreads |
166 // has been set, or 1 otherwise |
171 // has been set, or 1 otherwise |
167 int _parallel_gc_threads; |
172 int _parallel_gc_threads; |
168 |
173 |
169 // The number of GC threads currently active. |
174 // The number of GC threads currently active. |
170 uintx _no_of_gc_threads; |
175 uintx _no_of_gc_threads; |
171 |
176 |
172 enum SomePrivateConstants { |
|
173 NumPrevPausesForHeuristics = 10 |
|
174 }; |
|
175 |
|
176 G1MMUTracker* _mmu_tracker; |
177 G1MMUTracker* _mmu_tracker; |
177 |
178 |
178 void initialize_alignments(); |
179 void initialize_alignments(); |
179 void initialize_flags(); |
180 void initialize_flags(); |
180 |
181 |
249 |
251 |
250 uint _free_regions_at_end_of_collection; |
252 uint _free_regions_at_end_of_collection; |
251 |
253 |
252 size_t _recorded_rs_lengths; |
254 size_t _recorded_rs_lengths; |
253 size_t _max_rs_lengths; |
255 size_t _max_rs_lengths; |
254 double _sigma; |
|
255 |
256 |
256 size_t _rs_lengths_prediction; |
257 size_t _rs_lengths_prediction; |
257 |
|
258 double sigma() const { return _sigma; } |
|
259 |
|
260 // A function that prevents us putting too much stock in small sample |
|
261 // sets. Returns a number between 2.0 and 1.0, depending on the number |
|
262 // of samples. 5 or more samples yields one; fewer scales linearly from |
|
263 // 2.0 at 1 sample to 1.0 at 5. |
|
264 double confidence_factor(int samples) const { |
|
265 if (samples > 4) return 1.0; |
|
266 else return 1.0 + sigma() * ((double)(5 - samples))/2.0; |
|
267 } |
|
268 |
|
269 double get_new_neg_prediction(TruncatedSeq* seq) { |
|
270 return seq->davg() - sigma() * seq->dsd(); |
|
271 } |
|
272 |
258 |
273 #ifndef PRODUCT |
259 #ifndef PRODUCT |
274 bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group); |
260 bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group); |
275 #endif // PRODUCT |
261 #endif // PRODUCT |
276 |
262 |
302 |
290 |
303 #ifndef PRODUCT |
291 #ifndef PRODUCT |
304 bool verify_young_ages(); |
292 bool verify_young_ages(); |
305 #endif // PRODUCT |
293 #endif // PRODUCT |
306 |
294 |
307 double get_new_prediction(TruncatedSeq* seq) const { |
|
308 return MAX2(seq->davg() + sigma() * seq->dsd(), |
|
309 seq->davg() * confidence_factor(seq->num())); |
|
310 } |
|
311 |
|
312 void record_max_rs_lengths(size_t rs_lengths) { |
295 void record_max_rs_lengths(size_t rs_lengths) { |
313 _max_rs_lengths = rs_lengths; |
296 _max_rs_lengths = rs_lengths; |
314 } |
297 } |
315 |
298 |
316 size_t predict_rs_length_diff() const { |
299 size_t predict_rs_length_diff() const; |
317 return (size_t) get_new_prediction(_rs_length_diff_seq); |
300 |
318 } |
301 double predict_alloc_rate_ms() const; |
319 |
302 |
320 double predict_alloc_rate_ms() const { |
303 double predict_cost_per_card_ms() const; |
321 return get_new_prediction(_alloc_rate_ms_seq); |
304 |
322 } |
305 double predict_scan_hcc_ms() const; |
323 |
306 |
324 double predict_cost_per_card_ms() const { |
307 double predict_rs_update_time_ms(size_t pending_cards) const; |
325 return get_new_prediction(_cost_per_card_ms_seq); |
308 |
326 } |
309 double predict_young_cards_per_entry_ratio() const; |
327 |
310 |
328 double predict_scan_hcc_ms() const { |
311 double predict_mixed_cards_per_entry_ratio() const; |
329 return get_new_prediction(_cost_scan_hcc_seq); |
312 |
330 } |
313 size_t predict_young_card_num(size_t rs_length) const; |
331 |
314 |
332 double predict_rs_update_time_ms(size_t pending_cards) const { |
315 size_t predict_non_young_card_num(size_t rs_length) const; |
333 return (double) pending_cards * predict_cost_per_card_ms() + predict_scan_hcc_ms(); |
316 |
334 } |
317 double predict_rs_scan_time_ms(size_t card_num) const; |
335 |
318 |
336 double predict_young_cards_per_entry_ratio() const { |
319 double predict_mixed_rs_scan_time_ms(size_t card_num) const; |
337 return get_new_prediction(_young_cards_per_entry_ratio_seq); |
320 |
338 } |
321 double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const; |
339 |
322 |
340 double predict_mixed_cards_per_entry_ratio() const { |
323 double predict_object_copy_time_ms(size_t bytes_to_copy) const; |
341 if (_mixed_cards_per_entry_ratio_seq->num() < 2) { |
324 |
342 return predict_young_cards_per_entry_ratio(); |
325 double predict_constant_other_time_ms() const; |
343 } else { |
326 |
344 return get_new_prediction(_mixed_cards_per_entry_ratio_seq); |
327 double predict_young_other_time_ms(size_t young_num) const; |
345 } |
328 |
346 } |
329 double predict_non_young_other_time_ms(size_t non_young_num) const; |
347 |
|
348 size_t predict_young_card_num(size_t rs_length) const { |
|
349 return (size_t) ((double) rs_length * |
|
350 predict_young_cards_per_entry_ratio()); |
|
351 } |
|
352 |
|
353 size_t predict_non_young_card_num(size_t rs_length) const { |
|
354 return (size_t) ((double) rs_length * |
|
355 predict_mixed_cards_per_entry_ratio()); |
|
356 } |
|
357 |
|
358 double predict_rs_scan_time_ms(size_t card_num) const { |
|
359 if (collector_state()->gcs_are_young()) { |
|
360 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
|
361 } else { |
|
362 return predict_mixed_rs_scan_time_ms(card_num); |
|
363 } |
|
364 } |
|
365 |
|
366 double predict_mixed_rs_scan_time_ms(size_t card_num) const { |
|
367 if (_mixed_cost_per_entry_ms_seq->num() < 3) { |
|
368 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
|
369 } else { |
|
370 return (double) (card_num * |
|
371 get_new_prediction(_mixed_cost_per_entry_ms_seq)); |
|
372 } |
|
373 } |
|
374 |
|
375 double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const { |
|
376 if (_cost_per_byte_ms_during_cm_seq->num() < 3) { |
|
377 return (1.1 * (double) bytes_to_copy) * |
|
378 get_new_prediction(_cost_per_byte_ms_seq); |
|
379 } else { |
|
380 return (double) bytes_to_copy * |
|
381 get_new_prediction(_cost_per_byte_ms_during_cm_seq); |
|
382 } |
|
383 } |
|
384 |
|
385 double predict_object_copy_time_ms(size_t bytes_to_copy) const { |
|
386 if (collector_state()->during_concurrent_mark()) { |
|
387 return predict_object_copy_time_ms_during_cm(bytes_to_copy); |
|
388 } else { |
|
389 return (double) bytes_to_copy * |
|
390 get_new_prediction(_cost_per_byte_ms_seq); |
|
391 } |
|
392 } |
|
393 |
|
394 double predict_constant_other_time_ms() const { |
|
395 return get_new_prediction(_constant_other_time_ms_seq); |
|
396 } |
|
397 |
|
398 double predict_young_other_time_ms(size_t young_num) const { |
|
399 return (double) young_num * |
|
400 get_new_prediction(_young_other_cost_per_region_ms_seq); |
|
401 } |
|
402 |
|
403 double predict_non_young_other_time_ms(size_t non_young_num) const { |
|
404 return (double) non_young_num * |
|
405 get_new_prediction(_non_young_other_cost_per_region_ms_seq); |
|
406 } |
|
407 |
330 |
408 double predict_base_elapsed_time_ms(size_t pending_cards) const; |
331 double predict_base_elapsed_time_ms(size_t pending_cards) const; |
409 double predict_base_elapsed_time_ms(size_t pending_cards, |
332 double predict_base_elapsed_time_ms(size_t pending_cards, |
410 size_t scanned_cards) const; |
333 size_t scanned_cards) const; |
411 size_t predict_bytes_to_copy(HeapRegion* hr) const; |
334 size_t predict_bytes_to_copy(HeapRegion* hr) const; |
437 |
360 |
438 double max_pause_time_ms() const { |
361 double max_pause_time_ms() const { |
439 return _mmu_tracker->max_gc_time() * 1000.0; |
362 return _mmu_tracker->max_gc_time() * 1000.0; |
440 } |
363 } |
441 |
364 |
442 double predict_remark_time_ms() const { |
365 double predict_remark_time_ms() const; |
443 return get_new_prediction(_concurrent_mark_remark_times_ms); |
366 |
444 } |
367 double predict_cleanup_time_ms() const; |
445 |
|
446 double predict_cleanup_time_ms() const { |
|
447 return get_new_prediction(_concurrent_mark_cleanup_times_ms); |
|
448 } |
|
449 |
368 |
450 // Returns an estimate of the survival rate of the region at yg-age |
369 // Returns an estimate of the survival rate of the region at yg-age |
451 // "yg_age". |
370 // "yg_age". |
452 double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) const { |
371 double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) const; |
453 TruncatedSeq* seq = surv_rate_group->get_seq(age); |
372 |
454 if (seq->num() == 0) |
373 double predict_yg_surv_rate(int age) const; |
455 gclog_or_tty->print("BARF! age is %d", age); |
374 |
456 guarantee( seq->num() > 0, "invariant" ); |
375 double accum_yg_surv_rate_pred(int age) const; |
457 double pred = get_new_prediction(seq); |
|
458 if (pred > 1.0) |
|
459 pred = 1.0; |
|
460 return pred; |
|
461 } |
|
462 |
|
463 double predict_yg_surv_rate(int age) const { |
|
464 return predict_yg_surv_rate(age, _short_lived_surv_rate_group); |
|
465 } |
|
466 |
|
467 double accum_yg_surv_rate_pred(int age) const { |
|
468 return _short_lived_surv_rate_group->accum_surv_rate_pred(age); |
|
469 } |
|
470 |
376 |
471 private: |
377 private: |
472 // Statistics kept per GC stoppage, pause or full. |
378 // Statistics kept per GC stoppage, pause or full. |
473 TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec; |
379 TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec; |
474 |
380 |