240 uint _old_cset_region_length; |
240 uint _old_cset_region_length; |
241 |
241 |
242 void init_cset_region_lengths(uint eden_cset_region_length, |
242 void init_cset_region_lengths(uint eden_cset_region_length, |
243 uint survivor_cset_region_length); |
243 uint survivor_cset_region_length); |
244 |
244 |
245 uint eden_cset_region_length() { return _eden_cset_region_length; } |
245 uint eden_cset_region_length() const { return _eden_cset_region_length; } |
246 uint survivor_cset_region_length() { return _survivor_cset_region_length; } |
246 uint survivor_cset_region_length() const { return _survivor_cset_region_length; } |
247 uint old_cset_region_length() { return _old_cset_region_length; } |
247 uint old_cset_region_length() const { return _old_cset_region_length; } |
248 |
248 |
249 uint _free_regions_at_end_of_collection; |
249 uint _free_regions_at_end_of_collection; |
250 |
250 |
251 size_t _recorded_rs_lengths; |
251 size_t _recorded_rs_lengths; |
252 size_t _max_rs_lengths; |
252 size_t _max_rs_lengths; |
253 double _sigma; |
253 double _sigma; |
254 |
254 |
255 size_t _rs_lengths_prediction; |
255 size_t _rs_lengths_prediction; |
256 |
256 |
257 double sigma() { return _sigma; } |
257 double sigma() const { return _sigma; } |
258 |
258 |
259 // A function that prevents us putting too much stock in small sample |
259 // A function that prevents us putting too much stock in small sample |
260 // sets. Returns a number between 2.0 and 1.0, depending on the number |
260 // sets. Returns a number between 2.0 and 1.0, depending on the number |
261 // of samples. 5 or more samples yields one; fewer scales linearly from |
261 // of samples. 5 or more samples yields one; fewer scales linearly from |
262 // 2.0 at 1 sample to 1.0 at 5. |
262 // 2.0 at 1 sample to 1.0 at 5. |
263 double confidence_factor(int samples) { |
263 double confidence_factor(int samples) const { |
264 if (samples > 4) return 1.0; |
264 if (samples > 4) return 1.0; |
265 else return 1.0 + sigma() * ((double)(5 - samples))/2.0; |
265 else return 1.0 + sigma() * ((double)(5 - samples))/2.0; |
266 } |
266 } |
267 |
267 |
268 double get_new_neg_prediction(TruncatedSeq* seq) { |
268 double get_new_neg_prediction(TruncatedSeq* seq) { |
301 |
301 |
302 #ifndef PRODUCT |
302 #ifndef PRODUCT |
303 bool verify_young_ages(); |
303 bool verify_young_ages(); |
304 #endif // PRODUCT |
304 #endif // PRODUCT |
305 |
305 |
306 double get_new_prediction(TruncatedSeq* seq) { |
306 double get_new_prediction(TruncatedSeq* seq) const { |
307 return MAX2(seq->davg() + sigma() * seq->dsd(), |
307 return MAX2(seq->davg() + sigma() * seq->dsd(), |
308 seq->davg() * confidence_factor(seq->num())); |
308 seq->davg() * confidence_factor(seq->num())); |
309 } |
309 } |
310 |
310 |
311 void record_max_rs_lengths(size_t rs_lengths) { |
311 void record_max_rs_lengths(size_t rs_lengths) { |
312 _max_rs_lengths = rs_lengths; |
312 _max_rs_lengths = rs_lengths; |
313 } |
313 } |
314 |
314 |
315 size_t predict_rs_length_diff() { |
315 size_t predict_rs_length_diff() const { |
316 return (size_t) get_new_prediction(_rs_length_diff_seq); |
316 return (size_t) get_new_prediction(_rs_length_diff_seq); |
317 } |
317 } |
318 |
318 |
319 double predict_alloc_rate_ms() { |
319 double predict_alloc_rate_ms() const { |
320 return get_new_prediction(_alloc_rate_ms_seq); |
320 return get_new_prediction(_alloc_rate_ms_seq); |
321 } |
321 } |
322 |
322 |
323 double predict_cost_per_card_ms() { |
323 double predict_cost_per_card_ms() const { |
324 return get_new_prediction(_cost_per_card_ms_seq); |
324 return get_new_prediction(_cost_per_card_ms_seq); |
325 } |
325 } |
326 |
326 |
327 double predict_rs_update_time_ms(size_t pending_cards) { |
327 double predict_rs_update_time_ms(size_t pending_cards) const { |
328 return (double) pending_cards * predict_cost_per_card_ms(); |
328 return (double) pending_cards * predict_cost_per_card_ms(); |
329 } |
329 } |
330 |
330 |
331 double predict_young_cards_per_entry_ratio() { |
331 double predict_young_cards_per_entry_ratio() const { |
332 return get_new_prediction(_young_cards_per_entry_ratio_seq); |
332 return get_new_prediction(_young_cards_per_entry_ratio_seq); |
333 } |
333 } |
334 |
334 |
335 double predict_mixed_cards_per_entry_ratio() { |
335 double predict_mixed_cards_per_entry_ratio() const { |
336 if (_mixed_cards_per_entry_ratio_seq->num() < 2) { |
336 if (_mixed_cards_per_entry_ratio_seq->num() < 2) { |
337 return predict_young_cards_per_entry_ratio(); |
337 return predict_young_cards_per_entry_ratio(); |
338 } else { |
338 } else { |
339 return get_new_prediction(_mixed_cards_per_entry_ratio_seq); |
339 return get_new_prediction(_mixed_cards_per_entry_ratio_seq); |
340 } |
340 } |
341 } |
341 } |
342 |
342 |
343 size_t predict_young_card_num(size_t rs_length) { |
343 size_t predict_young_card_num(size_t rs_length) const { |
344 return (size_t) ((double) rs_length * |
344 return (size_t) ((double) rs_length * |
345 predict_young_cards_per_entry_ratio()); |
345 predict_young_cards_per_entry_ratio()); |
346 } |
346 } |
347 |
347 |
348 size_t predict_non_young_card_num(size_t rs_length) { |
348 size_t predict_non_young_card_num(size_t rs_length) const { |
349 return (size_t) ((double) rs_length * |
349 return (size_t) ((double) rs_length * |
350 predict_mixed_cards_per_entry_ratio()); |
350 predict_mixed_cards_per_entry_ratio()); |
351 } |
351 } |
352 |
352 |
353 double predict_rs_scan_time_ms(size_t card_num) { |
353 double predict_rs_scan_time_ms(size_t card_num) const { |
354 if (collector_state()->gcs_are_young()) { |
354 if (collector_state()->gcs_are_young()) { |
355 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
355 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
356 } else { |
356 } else { |
357 return predict_mixed_rs_scan_time_ms(card_num); |
357 return predict_mixed_rs_scan_time_ms(card_num); |
358 } |
358 } |
359 } |
359 } |
360 |
360 |
361 double predict_mixed_rs_scan_time_ms(size_t card_num) { |
361 double predict_mixed_rs_scan_time_ms(size_t card_num) const { |
362 if (_mixed_cost_per_entry_ms_seq->num() < 3) { |
362 if (_mixed_cost_per_entry_ms_seq->num() < 3) { |
363 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
363 return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq); |
364 } else { |
364 } else { |
365 return (double) (card_num * |
365 return (double) (card_num * |
366 get_new_prediction(_mixed_cost_per_entry_ms_seq)); |
366 get_new_prediction(_mixed_cost_per_entry_ms_seq)); |
367 } |
367 } |
368 } |
368 } |
369 |
369 |
370 double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) { |
370 double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const { |
371 if (_cost_per_byte_ms_during_cm_seq->num() < 3) { |
371 if (_cost_per_byte_ms_during_cm_seq->num() < 3) { |
372 return (1.1 * (double) bytes_to_copy) * |
372 return (1.1 * (double) bytes_to_copy) * |
373 get_new_prediction(_cost_per_byte_ms_seq); |
373 get_new_prediction(_cost_per_byte_ms_seq); |
374 } else { |
374 } else { |
375 return (double) bytes_to_copy * |
375 return (double) bytes_to_copy * |
376 get_new_prediction(_cost_per_byte_ms_during_cm_seq); |
376 get_new_prediction(_cost_per_byte_ms_during_cm_seq); |
377 } |
377 } |
378 } |
378 } |
379 |
379 |
380 double predict_object_copy_time_ms(size_t bytes_to_copy) { |
380 double predict_object_copy_time_ms(size_t bytes_to_copy) const { |
381 if (collector_state()->during_concurrent_mark()) { |
381 if (collector_state()->during_concurrent_mark()) { |
382 return predict_object_copy_time_ms_during_cm(bytes_to_copy); |
382 return predict_object_copy_time_ms_during_cm(bytes_to_copy); |
383 } else { |
383 } else { |
384 return (double) bytes_to_copy * |
384 return (double) bytes_to_copy * |
385 get_new_prediction(_cost_per_byte_ms_seq); |
385 get_new_prediction(_cost_per_byte_ms_seq); |
386 } |
386 } |
387 } |
387 } |
388 |
388 |
389 double predict_constant_other_time_ms() { |
389 double predict_constant_other_time_ms() const { |
390 return get_new_prediction(_constant_other_time_ms_seq); |
390 return get_new_prediction(_constant_other_time_ms_seq); |
391 } |
391 } |
392 |
392 |
393 double predict_young_other_time_ms(size_t young_num) { |
393 double predict_young_other_time_ms(size_t young_num) const { |
394 return (double) young_num * |
394 return (double) young_num * |
395 get_new_prediction(_young_other_cost_per_region_ms_seq); |
395 get_new_prediction(_young_other_cost_per_region_ms_seq); |
396 } |
396 } |
397 |
397 |
398 double predict_non_young_other_time_ms(size_t non_young_num) { |
398 double predict_non_young_other_time_ms(size_t non_young_num) const { |
399 return (double) non_young_num * |
399 return (double) non_young_num * |
400 get_new_prediction(_non_young_other_cost_per_region_ms_seq); |
400 get_new_prediction(_non_young_other_cost_per_region_ms_seq); |
401 } |
401 } |
402 |
402 |
403 double predict_base_elapsed_time_ms(size_t pending_cards); |
403 double predict_base_elapsed_time_ms(size_t pending_cards) const; |
404 double predict_base_elapsed_time_ms(size_t pending_cards, |
404 double predict_base_elapsed_time_ms(size_t pending_cards, |
405 size_t scanned_cards); |
405 size_t scanned_cards) const; |
406 size_t predict_bytes_to_copy(HeapRegion* hr); |
406 size_t predict_bytes_to_copy(HeapRegion* hr) const; |
407 double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc); |
407 double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc) const; |
408 |
408 |
409 void set_recorded_rs_lengths(size_t rs_lengths); |
409 void set_recorded_rs_lengths(size_t rs_lengths); |
410 |
410 |
411 uint cset_region_length() { return young_cset_region_length() + |
411 uint cset_region_length() const { return young_cset_region_length() + |
412 old_cset_region_length(); } |
412 old_cset_region_length(); } |
413 uint young_cset_region_length() { return eden_cset_region_length() + |
413 uint young_cset_region_length() const { return eden_cset_region_length() + |
414 survivor_cset_region_length(); } |
414 survivor_cset_region_length(); } |
415 |
415 |
416 double predict_survivor_regions_evac_time(); |
416 double predict_survivor_regions_evac_time() const; |
417 |
417 |
418 void cset_regions_freed() { |
418 void cset_regions_freed() { |
419 bool propagate = collector_state()->should_propagate(); |
419 bool propagate = collector_state()->should_propagate(); |
420 _short_lived_surv_rate_group->all_surviving_words_recorded(propagate); |
420 _short_lived_surv_rate_group->all_surviving_words_recorded(propagate); |
421 _survivor_surv_rate_group->all_surviving_words_recorded(propagate); |
421 _survivor_surv_rate_group->all_surviving_words_recorded(propagate); |
424 |
424 |
425 G1MMUTracker* mmu_tracker() { |
425 G1MMUTracker* mmu_tracker() { |
426 return _mmu_tracker; |
426 return _mmu_tracker; |
427 } |
427 } |
428 |
428 |
429 double max_pause_time_ms() { |
429 const G1MMUTracker* mmu_tracker() const { |
|
430 return _mmu_tracker; |
|
431 } |
|
432 |
|
433 double max_pause_time_ms() const { |
430 return _mmu_tracker->max_gc_time() * 1000.0; |
434 return _mmu_tracker->max_gc_time() * 1000.0; |
431 } |
435 } |
432 |
436 |
433 double predict_remark_time_ms() { |
437 double predict_remark_time_ms() const { |
434 return get_new_prediction(_concurrent_mark_remark_times_ms); |
438 return get_new_prediction(_concurrent_mark_remark_times_ms); |
435 } |
439 } |
436 |
440 |
437 double predict_cleanup_time_ms() { |
441 double predict_cleanup_time_ms() const { |
438 return get_new_prediction(_concurrent_mark_cleanup_times_ms); |
442 return get_new_prediction(_concurrent_mark_cleanup_times_ms); |
439 } |
443 } |
440 |
444 |
441 // Returns an estimate of the survival rate of the region at yg-age |
445 // Returns an estimate of the survival rate of the region at yg-age |
442 // "yg_age". |
446 // "yg_age". |
443 double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) { |
447 double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) const { |
444 TruncatedSeq* seq = surv_rate_group->get_seq(age); |
448 TruncatedSeq* seq = surv_rate_group->get_seq(age); |
445 if (seq->num() == 0) |
449 if (seq->num() == 0) |
446 gclog_or_tty->print("BARF! age is %d", age); |
450 gclog_or_tty->print("BARF! age is %d", age); |
447 guarantee( seq->num() > 0, "invariant" ); |
451 guarantee( seq->num() > 0, "invariant" ); |
448 double pred = get_new_prediction(seq); |
452 double pred = get_new_prediction(seq); |
449 if (pred > 1.0) |
453 if (pred > 1.0) |
450 pred = 1.0; |
454 pred = 1.0; |
451 return pred; |
455 return pred; |
452 } |
456 } |
453 |
457 |
454 double predict_yg_surv_rate(int age) { |
458 double predict_yg_surv_rate(int age) const { |
455 return predict_yg_surv_rate(age, _short_lived_surv_rate_group); |
459 return predict_yg_surv_rate(age, _short_lived_surv_rate_group); |
456 } |
460 } |
457 |
461 |
458 double accum_yg_surv_rate_pred(int age) { |
462 double accum_yg_surv_rate_pred(int age) const { |
459 return _short_lived_surv_rate_group->accum_surv_rate_pred(age); |
463 return _short_lived_surv_rate_group->accum_surv_rate_pred(age); |
460 } |
464 } |
461 |
465 |
462 private: |
466 private: |
463 // Statistics kept per GC stoppage, pause or full. |
467 // Statistics kept per GC stoppage, pause or full. |
554 void update_young_list_target_length(size_t rs_lengths = (size_t) -1); |
558 void update_young_list_target_length(size_t rs_lengths = (size_t) -1); |
555 |
559 |
556 // Calculate and return the minimum desired young list target |
560 // Calculate and return the minimum desired young list target |
557 // length. This is the minimum desired young list length according |
561 // length. This is the minimum desired young list length according |
558 // to the user's inputs. |
562 // to the user's inputs. |
559 uint calculate_young_list_desired_min_length(uint base_min_length); |
563 uint calculate_young_list_desired_min_length(uint base_min_length) const; |
560 |
564 |
561 // Calculate and return the maximum desired young list target |
565 // Calculate and return the maximum desired young list target |
562 // length. This is the maximum desired young list length according |
566 // length. This is the maximum desired young list length according |
563 // to the user's inputs. |
567 // to the user's inputs. |
564 uint calculate_young_list_desired_max_length(); |
568 uint calculate_young_list_desired_max_length() const; |
565 |
569 |
566 // Calculate and return the maximum young list target length that |
570 // Calculate and return the maximum young list target length that |
567 // can fit into the pause time goal. The parameters are: rs_lengths |
571 // can fit into the pause time goal. The parameters are: rs_lengths |
568 // represent the prediction of how large the young RSet lengths will |
572 // represent the prediction of how large the young RSet lengths will |
569 // be, base_min_length is the already existing number of regions in |
573 // be, base_min_length is the already existing number of regions in |
570 // the young list, min_length and max_length are the desired min and |
574 // the young list, min_length and max_length are the desired min and |
571 // max young list length according to the user's inputs. |
575 // max young list length according to the user's inputs. |
572 uint calculate_young_list_target_length(size_t rs_lengths, |
576 uint calculate_young_list_target_length(size_t rs_lengths, |
573 uint base_min_length, |
577 uint base_min_length, |
574 uint desired_min_length, |
578 uint desired_min_length, |
575 uint desired_max_length); |
579 uint desired_max_length) const; |
576 |
580 |
577 // Calculate and return chunk size (in number of regions) for parallel |
581 // Calculate and return chunk size (in number of regions) for parallel |
578 // concurrent mark cleanup. |
582 // concurrent mark cleanup. |
579 uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions); |
583 uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const; |
580 |
584 |
581 // Check whether a given young length (young_length) fits into the |
585 // Check whether a given young length (young_length) fits into the |
582 // given target pause time and whether the prediction for the amount |
586 // given target pause time and whether the prediction for the amount |
583 // of objects to be copied for the given length will fit into the |
587 // of objects to be copied for the given length will fit into the |
584 // given free space (expressed by base_free_regions). It is used by |
588 // given free space (expressed by base_free_regions). It is used by |
585 // calculate_young_list_target_length(). |
589 // calculate_young_list_target_length(). |
586 bool predict_will_fit(uint young_length, double base_time_ms, |
590 bool predict_will_fit(uint young_length, double base_time_ms, |
587 uint base_free_regions, double target_pause_time_ms); |
591 uint base_free_regions, double target_pause_time_ms) const; |
588 |
592 |
589 // Calculate the minimum number of old regions we'll add to the CSet |
593 // Calculate the minimum number of old regions we'll add to the CSet |
590 // during a mixed GC. |
594 // during a mixed GC. |
591 uint calc_min_old_cset_length(); |
595 uint calc_min_old_cset_length() const; |
592 |
596 |
593 // Calculate the maximum number of old regions we'll add to the CSet |
597 // Calculate the maximum number of old regions we'll add to the CSet |
594 // during a mixed GC. |
598 // during a mixed GC. |
595 uint calc_max_old_cset_length(); |
599 uint calc_max_old_cset_length() const; |
596 |
600 |
597 // Returns the given amount of uncollected reclaimable space |
601 // Returns the given amount of uncollected reclaimable space |
598 // as a percentage of the current heap capacity. |
602 // as a percentage of the current heap capacity. |
599 double reclaimable_bytes_perc(size_t reclaimable_bytes); |
603 double reclaimable_bytes_perc(size_t reclaimable_bytes) const; |
600 |
604 |
601 public: |
605 public: |
602 |
606 |
603 G1CollectorPolicy(); |
607 G1CollectorPolicy(); |
604 |
608 |
605 virtual G1CollectorPolicy* as_g1_policy() { return this; } |
609 virtual G1CollectorPolicy* as_g1_policy() { return this; } |
606 |
610 |
|
611 const G1CollectorState* collector_state() const; |
607 G1CollectorState* collector_state(); |
612 G1CollectorState* collector_state(); |
608 |
613 |
609 G1GCPhaseTimes* phase_times() const { return _phase_times; } |
614 G1GCPhaseTimes* phase_times() const { return _phase_times; } |
610 |
615 |
611 // Check the current value of the young list RSet lengths and |
616 // Check the current value of the young list RSet lengths and |