< prev index next >

src/share/vm/gc/g1/g1CollectorPolicy.cpp

Print this page




 309     // end condition 1: not enough space for the young regions
 310     return false;
 311   }
 312 
 313   double accum_surv_rate = accum_yg_surv_rate_pred((int) young_length - 1);
 314   size_t bytes_to_copy =
 315                (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
 316   double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
 317   double young_other_time_ms = predict_young_other_time_ms(young_length);
 318   double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
 319   if (pause_time_ms > target_pause_time_ms) {
 320     // end condition 2: prediction is over the target pause time
 321     return false;
 322   }
 323 
 324   size_t free_bytes = (base_free_regions - young_length) * HeapRegion::GrainBytes;
 325 
 326   // When copying, we will likely need more bytes free than is live in the region.
 327   // Add some safety margin to factor in the confidence of our guess, and the
 328   // natural expected waste.
 329   // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
 330   // of the calculation: the lower the confidence, the more headroom.
 331   // (100 + TargetPLABWastePct) represents the increase in expected bytes during
 332   // copying due to anticipated waste in the PLABs.
 333   double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
 334   size_t expected_bytes_to_copy = (size_t)(safety_factor * bytes_to_copy);
 335 
 336   if (expected_bytes_to_copy > free_bytes) {
 337     // end condition 3: out-of-space
 338     return false;
 339   }
 340 
 341   // success!
 342   return true;
 343 }
 344 
 345 void G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
 346   // re-calculate the necessary reserve
 347   double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
 348   // We use ceiling so that if reserve_regions_d is > 0.0 (but
 349   // smaller than 1.0) we'll get 1.
 350   _reserve_regions = (uint) ceil(reserve_regions_d);
 351 
 352   _young_gen_sizer->heap_size_changed(new_number_of_regions);
 353 
 354   _ihop_control->update_target_occupancy(new_number_of_regions * HeapRegion::GrainBytes);


 680 
 681   _bytes_allocated_in_old_since_last_gc = 0;
 682 
 683   record_pause(FullGC, _full_collection_start_sec, end_sec);
 684 }
 685 
 686 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec) {
 687   // We only need to do this here as the policy will only be applied
 688   // to the GC we're about to start. so, no point is calculating this
 689   // every time we calculate / recalculate the target young length.
 690   update_survivors_policy();
 691 
 692   assert(_g1->used() == _g1->recalculate_used(),
 693          "sanity, used: " SIZE_FORMAT " recalculate_used: " SIZE_FORMAT,
 694          _g1->used(), _g1->recalculate_used());
 695 
 696   phase_times()->record_cur_collection_start_sec(start_time_sec);
 697   _pending_cards = _g1->pending_card_num();
 698 
 699   _collection_set->reset_bytes_used_before();

 700   _bytes_copied_during_gc = 0;
 701 
 702   collector_state()->set_last_gc_was_young(false);
 703 
 704   // do that for any other surv rate groups
 705   _short_lived_surv_rate_group->stop_adding_regions();
 706   _survivors_age_table.clear();
 707 
 708   assert( verify_young_ages(), "region age verification" );
 709 }
 710 
 711 void G1CollectorPolicy::record_concurrent_mark_init_end(double
 712                                                    mark_init_elapsed_time_ms) {
 713   collector_state()->set_during_marking(true);
 714   assert(!collector_state()->initiate_conc_mark_if_possible(), "we should have cleared it by now");
 715   collector_state()->set_during_initial_mark_pause(false);
 716 }
 717 
 718 void G1CollectorPolicy::record_concurrent_mark_remark_start() {
 719   _mark_remark_start_sec = os::elapsedTime();


1709     result += 1;
1710   }
1711   return (uint) result;
1712 }
1713 
1714 uint G1CollectorPolicy::calc_max_old_cset_length() const {
1715   // The max old CSet region bound is based on the threshold expressed
1716   // as a percentage of the heap size. I.e., it should bound the
1717   // number of old regions added to the CSet irrespective of how many
1718   // of them are available.
1719 
1720   const G1CollectedHeap* g1h = G1CollectedHeap::heap();
1721   const size_t region_num = g1h->num_regions();
1722   const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
1723   size_t result = region_num * perc / 100;
1724   // emulate ceiling
1725   if (100 * result < region_num * perc) {
1726     result += 1;
1727   }
1728   return (uint) result;









1729 }
1730 
1731 void G1CollectorPolicy::finalize_collection_set(double target_pause_time_ms) {
1732   double time_remaining_ms = _collection_set->finalize_young_part(target_pause_time_ms);
1733   _collection_set->finalize_old_part(time_remaining_ms);
1734 }
1735 


 309     // end condition 1: not enough space for the young regions
 310     return false;
 311   }
 312 
 313   double accum_surv_rate = accum_yg_surv_rate_pred((int) young_length - 1);
 314   size_t bytes_to_copy =
 315                (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
 316   double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
 317   double young_other_time_ms = predict_young_other_time_ms(young_length);
 318   double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
 319   if (pause_time_ms > target_pause_time_ms) {
 320     // end condition 2: prediction is over the target pause time
 321     return false;
 322   }
 323 
 324   size_t free_bytes = (base_free_regions - young_length) * HeapRegion::GrainBytes;
 325 
 326   // When copying, we will likely need more bytes free than is live in the region.
 327   // Add some safety margin to factor in the confidence of our guess, and the
 328   // natural expected waste.
 329   size_t expected_bytes_to_copy = (size_t)(bytes_to_copy * safety_factor());





 330 
 331   if (expected_bytes_to_copy > free_bytes) {
 332     // end condition 3: out-of-space
 333     return false;
 334   }
 335 
 336   // success!
 337   return true;
 338 }
 339 
 340 void G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
 341   // re-calculate the necessary reserve
 342   double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
 343   // We use ceiling so that if reserve_regions_d is > 0.0 (but
 344   // smaller than 1.0) we'll get 1.
 345   _reserve_regions = (uint) ceil(reserve_regions_d);
 346 
 347   _young_gen_sizer->heap_size_changed(new_number_of_regions);
 348 
 349   _ihop_control->update_target_occupancy(new_number_of_regions * HeapRegion::GrainBytes);


 675 
 676   _bytes_allocated_in_old_since_last_gc = 0;
 677 
 678   record_pause(FullGC, _full_collection_start_sec, end_sec);
 679 }
 680 
 681 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec) {
 682   // We only need to do this here as the policy will only be applied
 683   // to the GC we're about to start. so, no point is calculating this
 684   // every time we calculate / recalculate the target young length.
 685   update_survivors_policy();
 686 
 687   assert(_g1->used() == _g1->recalculate_used(),
 688          "sanity, used: " SIZE_FORMAT " recalculate_used: " SIZE_FORMAT,
 689          _g1->used(), _g1->recalculate_used());
 690 
 691   phase_times()->record_cur_collection_start_sec(start_time_sec);
 692   _pending_cards = _g1->pending_card_num();
 693 
 694   _collection_set->reset_bytes_used_before();
 695   _collection_set->reset_bytes_live_before();
 696   _bytes_copied_during_gc = 0;
 697 
 698   collector_state()->set_last_gc_was_young(false);
 699 
 700   // do that for any other surv rate groups
 701   _short_lived_surv_rate_group->stop_adding_regions();
 702   _survivors_age_table.clear();
 703 
 704   assert( verify_young_ages(), "region age verification" );
 705 }
 706 
 707 void G1CollectorPolicy::record_concurrent_mark_init_end(double
 708                                                    mark_init_elapsed_time_ms) {
 709   collector_state()->set_during_marking(true);
 710   assert(!collector_state()->initiate_conc_mark_if_possible(), "we should have cleared it by now");
 711   collector_state()->set_during_initial_mark_pause(false);
 712 }
 713 
 714 void G1CollectorPolicy::record_concurrent_mark_remark_start() {
 715   _mark_remark_start_sec = os::elapsedTime();


1705     result += 1;
1706   }
1707   return (uint) result;
1708 }
1709 
1710 uint G1CollectorPolicy::calc_max_old_cset_length() const {
1711   // The max old CSet region bound is based on the threshold expressed
1712   // as a percentage of the heap size. I.e., it should bound the
1713   // number of old regions added to the CSet irrespective of how many
1714   // of them are available.
1715 
1716   const G1CollectedHeap* g1h = G1CollectedHeap::heap();
1717   const size_t region_num = g1h->num_regions();
1718   const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
1719   size_t result = region_num * perc / 100;
1720   // emulate ceiling
1721   if (100 * result < region_num * perc) {
1722     result += 1;
1723   }
1724   return (uint) result;
1725 }
1726 
1727 size_t G1CollectorPolicy::available_bytes_estimate() {
1728   size_t estimated_available_bytes = 0;
1729   if (_free_regions_at_end_of_collection > _reserve_regions) {
1730     uint available_regions = _free_regions_at_end_of_collection - _reserve_regions;
1731     estimated_available_bytes = (size_t)((available_regions * HeapRegion::GrainBytes) / safety_factor());
1732   }
1733   return estimated_available_bytes;
1734 }
1735 
1736 void G1CollectorPolicy::finalize_collection_set(double target_pause_time_ms) {
1737   double time_remaining_ms = _collection_set->finalize_young_part(target_pause_time_ms);
1738   _collection_set->finalize_old_part(time_remaining_ms);
1739 }
1740 
< prev index next >