hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
changeset 2741 34e2a243d69a
parent 2344 f2e09ba7ceab
child 2881 74a1337e4acc
equal deleted inserted replaced
2738:7a72e5ed1d10 2741:34e2a243d69a
   134 
   134 
   135   _pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
   135   _pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
   136   _scanned_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
   136   _scanned_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
   137   _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)),
   137   _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)),
   138 
   138 
   139   _pause_time_target_ms((double) G1MaxPauseTimeMS),
   139   _pause_time_target_ms((double) MaxGCPauseMillis),
   140 
   140 
   141   // </NEW PREDICTION>
   141   // </NEW PREDICTION>
   142 
   142 
   143   _in_young_gc_mode(false),
   143   _in_young_gc_mode(false),
   144   _full_young_gcs(true),
   144   _full_young_gcs(true),
   218   _par_last_obj_copy_times_ms = new double[_parallel_gc_threads];
   218   _par_last_obj_copy_times_ms = new double[_parallel_gc_threads];
   219 
   219 
   220   _par_last_termination_times_ms = new double[_parallel_gc_threads];
   220   _par_last_termination_times_ms = new double[_parallel_gc_threads];
   221 
   221 
   222   // start conservatively
   222   // start conservatively
   223   _expensive_region_limit_ms = 0.5 * (double) G1MaxPauseTimeMS;
   223   _expensive_region_limit_ms = 0.5 * (double) MaxGCPauseMillis;
   224 
   224 
   225   // <NEW PREDICTION>
   225   // <NEW PREDICTION>
   226 
   226 
   227   int index;
   227   int index;
   228   if (ParallelGCThreads == 0)
   228   if (ParallelGCThreads == 0)
   247   _non_young_other_cost_per_region_ms_seq->add(
   247   _non_young_other_cost_per_region_ms_seq->add(
   248                            non_young_other_cost_per_region_ms_defaults[index]);
   248                            non_young_other_cost_per_region_ms_defaults[index]);
   249 
   249 
   250   // </NEW PREDICTION>
   250   // </NEW PREDICTION>
   251 
   251 
   252   double time_slice  = (double) G1TimeSliceMS / 1000.0;
   252   double time_slice  = (double) GCPauseIntervalMillis / 1000.0;
   253   double max_gc_time = (double) G1MaxPauseTimeMS / 1000.0;
   253   double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
   254   guarantee(max_gc_time < time_slice,
   254   guarantee(max_gc_time < time_slice,
   255             "Max GC time should not be greater than the time slice");
   255             "Max GC time should not be greater than the time slice");
   256   _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
   256   _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
   257   _sigma = (double) G1ConfidencePerc / 100.0;
   257   _sigma = (double) G1ConfidencePercent / 100.0;
   258 
   258 
   259   // start conservatively (around 50ms is about right)
   259   // start conservatively (around 50ms is about right)
   260   _concurrent_mark_init_times_ms->add(0.05);
   260   _concurrent_mark_init_times_ms->add(0.05);
   261   _concurrent_mark_remark_times_ms->add(0.05);
   261   _concurrent_mark_remark_times_ms->add(0.05);
   262   _concurrent_mark_cleanup_times_ms->add(0.20);
   262   _concurrent_mark_cleanup_times_ms->add(0.20);
   263   _tenuring_threshold = MaxTenuringThreshold;
   263   _tenuring_threshold = MaxTenuringThreshold;
   264 
   264 
   265   if (G1UseSurvivorSpace) {
   265   if (G1UseSurvivorSpaces) {
   266     // if G1FixedSurvivorSpaceSize is 0 which means the size is not
   266     // if G1FixedSurvivorSpaceSize is 0 which means the size is not
   267     // fixed, then _max_survivor_regions will be calculated at
   267     // fixed, then _max_survivor_regions will be calculated at
   268     // calculate_young_list_target_config during initialization
   268     // calculate_young_list_target_config during initialization
   269     _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes;
   269     _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes;
   270   } else {
   270   } else {
   449 
   449 
   450 void G1CollectorPolicy::calculate_young_list_target_config(size_t rs_lengths) {
   450 void G1CollectorPolicy::calculate_young_list_target_config(size_t rs_lengths) {
   451   guarantee( adaptive_young_list_length(), "pre-condition" );
   451   guarantee( adaptive_young_list_length(), "pre-condition" );
   452 
   452 
   453   double start_time_sec = os::elapsedTime();
   453   double start_time_sec = os::elapsedTime();
   454   size_t min_reserve_perc = MAX2((size_t)2, (size_t)G1MinReservePerc);
   454   size_t min_reserve_perc = MAX2((size_t)2, (size_t)G1MinReservePercent);
   455   min_reserve_perc = MIN2((size_t) 50, min_reserve_perc);
   455   min_reserve_perc = MIN2((size_t) 50, min_reserve_perc);
   456   size_t reserve_regions =
   456   size_t reserve_regions =
   457     (size_t) ((double) min_reserve_perc * (double) _g1->n_regions() / 100.0);
   457     (size_t) ((double) min_reserve_perc * (double) _g1->n_regions() / 100.0);
   458 
   458 
   459   if (full_young_gcs() && _free_regions_at_end_of_collection > 0) {
   459   if (full_young_gcs() && _free_regions_at_end_of_collection > 0) {
  1107   _short_lived_surv_rate_group->stop_adding_regions();
  1107   _short_lived_surv_rate_group->stop_adding_regions();
  1108   size_t short_lived_so_length = _young_list_so_prefix_length;
  1108   size_t short_lived_so_length = _young_list_so_prefix_length;
  1109   _short_lived_surv_rate_group->record_scan_only_prefix(short_lived_so_length);
  1109   _short_lived_surv_rate_group->record_scan_only_prefix(short_lived_so_length);
  1110   tag_scan_only(short_lived_so_length);
  1110   tag_scan_only(short_lived_so_length);
  1111 
  1111 
  1112   if (G1UseSurvivorSpace) {
  1112   if (G1UseSurvivorSpaces) {
  1113     _survivors_age_table.clear();
  1113     _survivors_age_table.clear();
  1114   }
  1114   }
  1115 
  1115 
  1116   assert( verify_young_ages(), "region age verification" );
  1116   assert( verify_young_ages(), "region age verification" );
  1117 }
  1117 }
  1824     _pending_cards_seq->add((double) _pending_cards);
  1824     _pending_cards_seq->add((double) _pending_cards);
  1825     _scanned_cards_seq->add((double) cards_scanned);
  1825     _scanned_cards_seq->add((double) cards_scanned);
  1826     _rs_lengths_seq->add((double) _max_rs_lengths);
  1826     _rs_lengths_seq->add((double) _max_rs_lengths);
  1827 
  1827 
  1828     double expensive_region_limit_ms =
  1828     double expensive_region_limit_ms =
  1829       (double) G1MaxPauseTimeMS - predict_constant_other_time_ms();
  1829       (double) MaxGCPauseMillis - predict_constant_other_time_ms();
  1830     if (expensive_region_limit_ms < 0.0) {
  1830     if (expensive_region_limit_ms < 0.0) {
  1831       // this means that the other time was predicted to be longer than
  1831       // this means that the other time was predicted to be longer than
  1832       // than the max pause time
  1832       // than the max pause time
  1833       expensive_region_limit_ms = (double) G1MaxPauseTimeMS;
  1833       expensive_region_limit_ms = (double) MaxGCPauseMillis;
  1834     }
  1834     }
  1835     _expensive_region_limit_ms = expensive_region_limit_ms;
  1835     _expensive_region_limit_ms = expensive_region_limit_ms;
  1836 
  1836 
  1837     if (PREDICTIONS_VERBOSE) {
  1837     if (PREDICTIONS_VERBOSE) {
  1838       gclog_or_tty->print_cr("");
  1838       gclog_or_tty->print_cr("");
  2091   _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
  2091   _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
  2092   _prev_collection_pause_end_ms = end_time_sec * 1000.0;
  2092   _prev_collection_pause_end_ms = end_time_sec * 1000.0;
  2093 }
  2093 }
  2094 
  2094 
  2095 double G1CollectorPolicy::recent_avg_time_for_pauses_ms() {
  2095 double G1CollectorPolicy::recent_avg_time_for_pauses_ms() {
  2096   if (_recent_pause_times_ms->num() == 0) return (double) G1MaxPauseTimeMS;
  2096   if (_recent_pause_times_ms->num() == 0) return (double) MaxGCPauseMillis;
  2097   else return _recent_pause_times_ms->avg();
  2097   else return _recent_pause_times_ms->avg();
  2098 }
  2098 }
  2099 
  2099 
  2100 double G1CollectorPolicy::recent_avg_time_for_CH_strong_ms() {
  2100 double G1CollectorPolicy::recent_avg_time_for_CH_strong_ms() {
  2101   if (_recent_CH_strong_roots_times_ms->num() == 0)
  2101   if (_recent_CH_strong_roots_times_ms->num() == 0)
  2102     return (double)G1MaxPauseTimeMS/3.0;
  2102     return (double)MaxGCPauseMillis/3.0;
  2103   else return _recent_CH_strong_roots_times_ms->avg();
  2103   else return _recent_CH_strong_roots_times_ms->avg();
  2104 }
  2104 }
  2105 
  2105 
  2106 double G1CollectorPolicy::recent_avg_time_for_G1_strong_ms() {
  2106 double G1CollectorPolicy::recent_avg_time_for_G1_strong_ms() {
  2107   if (_recent_G1_strong_roots_times_ms->num() == 0)
  2107   if (_recent_G1_strong_roots_times_ms->num() == 0)
  2108     return (double)G1MaxPauseTimeMS/3.0;
  2108     return (double)MaxGCPauseMillis/3.0;
  2109   else return _recent_G1_strong_roots_times_ms->avg();
  2109   else return _recent_G1_strong_roots_times_ms->avg();
  2110 }
  2110 }
  2111 
  2111 
  2112 double G1CollectorPolicy::recent_avg_time_for_evac_ms() {
  2112 double G1CollectorPolicy::recent_avg_time_for_evac_ms() {
  2113   if (_recent_evac_times_ms->num() == 0) return (double)G1MaxPauseTimeMS/3.0;
  2113   if (_recent_evac_times_ms->num() == 0) return (double)MaxGCPauseMillis/3.0;
  2114   else return _recent_evac_times_ms->avg();
  2114   else return _recent_evac_times_ms->avg();
  2115 }
  2115 }
  2116 
  2116 
  2117 int G1CollectorPolicy::number_of_recent_gcs() {
  2117 int G1CollectorPolicy::number_of_recent_gcs() {
  2118   assert(_recent_CH_strong_roots_times_ms->num() ==
  2118   assert(_recent_CH_strong_roots_times_ms->num() ==
  2195   res = MIN2(res, 1.0);
  2195   res = MIN2(res, 1.0);
  2196   return res;
  2196   return res;
  2197 }
  2197 }
  2198 
  2198 
  2199 size_t G1CollectorPolicy::expansion_amount() {
  2199 size_t G1CollectorPolicy::expansion_amount() {
  2200   if ((int)(recent_avg_pause_time_ratio() * 100.0) > G1GCPct) {
  2200   if ((int)(recent_avg_pause_time_ratio() * 100.0) > G1GCPercent) {
  2201     // We will double the existing space, or take G1ExpandByPctOfAvail % of
  2201     // We will double the existing space, or take
  2202     // the available expansion space, whichever is smaller, bounded below
  2202     // G1ExpandByPercentOfAvailable % of the available expansion
  2203     // by a minimum expansion (unless that's all that's left.)
  2203     // space, whichever is smaller, bounded below by a minimum
       
  2204     // expansion (unless that's all that's left.)
  2204     const size_t min_expand_bytes = 1*M;
  2205     const size_t min_expand_bytes = 1*M;
  2205     size_t reserved_bytes = _g1->g1_reserved_obj_bytes();
  2206     size_t reserved_bytes = _g1->g1_reserved_obj_bytes();
  2206     size_t committed_bytes = _g1->capacity();
  2207     size_t committed_bytes = _g1->capacity();
  2207     size_t uncommitted_bytes = reserved_bytes - committed_bytes;
  2208     size_t uncommitted_bytes = reserved_bytes - committed_bytes;
  2208     size_t expand_bytes;
  2209     size_t expand_bytes;
  2209     size_t expand_bytes_via_pct =
  2210     size_t expand_bytes_via_pct =
  2210       uncommitted_bytes * G1ExpandByPctOfAvail / 100;
  2211       uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
  2211     expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
  2212     expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
  2212     expand_bytes = MAX2(expand_bytes, min_expand_bytes);
  2213     expand_bytes = MAX2(expand_bytes, min_expand_bytes);
  2213     expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
  2214     expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
  2214     if (G1PolicyVerbose > 1) {
  2215     if (G1PolicyVerbose > 1) {
  2215       gclog_or_tty->print("Decided to expand: ratio = %5.2f, "
  2216       gclog_or_tty->print("Decided to expand: ratio = %5.2f, "
  2589 }
  2590 }
  2590 
  2591 
  2591 // Calculates survivor space parameters.
  2592 // Calculates survivor space parameters.
  2592 void G1CollectorPolicy::calculate_survivors_policy()
  2593 void G1CollectorPolicy::calculate_survivors_policy()
  2593 {
  2594 {
  2594   if (!G1UseSurvivorSpace) {
  2595   if (!G1UseSurvivorSpaces) {
  2595     return;
  2596     return;
  2596   }
  2597   }
  2597   if (G1FixedSurvivorSpaceSize == 0) {
  2598   if (G1FixedSurvivorSpaceSize == 0) {
  2598     _max_survivor_regions = _young_list_target_length / SurvivorRatio;
  2599     _max_survivor_regions = _young_list_target_length / SurvivorRatio;
  2599   } else {
  2600   } else {
  2849 
  2850 
  2850 // Add the heap region to the collection set and return the conservative
  2851 // Add the heap region to the collection set and return the conservative
  2851 // estimate of the number of live bytes.
  2852 // estimate of the number of live bytes.
  2852 void G1CollectorPolicy::
  2853 void G1CollectorPolicy::
  2853 add_to_collection_set(HeapRegion* hr) {
  2854 add_to_collection_set(HeapRegion* hr) {
  2854   if (G1TraceRegions) {
  2855   if (G1PrintRegions) {
  2855     gclog_or_tty->print_cr("added region to cset %d:["PTR_FORMAT", "PTR_FORMAT"], "
  2856     gclog_or_tty->print_cr("added region to cset %d:["PTR_FORMAT", "PTR_FORMAT"], "
  2856                   "top "PTR_FORMAT", young %s",
  2857                   "top "PTR_FORMAT", young %s",
  2857                   hr->hrs_index(), hr->bottom(), hr->end(),
  2858                   hr->hrs_index(), hr->bottom(), hr->end(),
  2858                   hr->top(), (hr->is_young()) ? "YES" : "NO");
  2859                   hr->top(), (hr->is_young()) ? "YES" : "NO");
  2859   }
  2860   }