hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp
changeset 35059 1805414a18bc
parent 35058 ec2a8bd1615b
parent 34673 9037365190c1
child 35061 be6025ebffea
equal deleted inserted replaced
35058:ec2a8bd1615b 35059:1805414a18bc
   189     G1ErgoVerbose::set_enabled(false);
   189     G1ErgoVerbose::set_enabled(false);
   190   }
   190   }
   191 
   191 
   192   _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
   192   _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
   193   _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
   193   _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
       
   194   clear_ratio_check_data();
   194 
   195 
   195   _phase_times = new G1GCPhaseTimes(_parallel_gc_threads);
   196   _phase_times = new G1GCPhaseTimes(_parallel_gc_threads);
   196 
   197 
   197   int index = MIN2(_parallel_gc_threads - 1, 7);
   198   int index = MIN2(_parallel_gc_threads - 1, 7);
   198 
   199 
  1078       } else {
  1079       } else {
  1079         assert(_recent_avg_pause_time_ratio - 1.0 > 0.0, "Ctl-point invariant");
  1080         assert(_recent_avg_pause_time_ratio - 1.0 > 0.0, "Ctl-point invariant");
  1080         _recent_avg_pause_time_ratio = 1.0;
  1081         _recent_avg_pause_time_ratio = 1.0;
  1081       }
  1082       }
  1082     }
  1083     }
       
  1084 
       
  1085     // Compute the ratio of just this last pause time to the entire time range stored
       
  1086     // in the vectors. Comparing this pause to the entire range, rather than only the
       
  1087     // most recent interval, has the effect of smoothing over a possible transient 'burst'
       
  1088     // of more frequent pauses that don't really reflect a change in heap occupancy.
       
  1089     // This reduces the likelihood of a needless heap expansion being triggered.
       
  1090     _last_pause_time_ratio =
       
  1091       (pause_time_ms * _recent_prev_end_times_for_all_gcs_sec->num()) / interval_ms;
  1083   }
  1092   }
  1084 
  1093 
  1085   bool new_in_marking_window = collector_state()->in_marking_window();
  1094   bool new_in_marking_window = collector_state()->in_marking_window();
  1086   bool new_in_marking_window_im = false;
  1095   bool new_in_marking_window_im = false;
  1087   if (last_pause_included_initial_mark) {
  1096   if (last_pause_included_initial_mark) {
  1595   _recent_gc_times_ms->add(elapsed_ms);
  1604   _recent_gc_times_ms->add(elapsed_ms);
  1596   _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
  1605   _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
  1597   _prev_collection_pause_end_ms = end_time_sec * 1000.0;
  1606   _prev_collection_pause_end_ms = end_time_sec * 1000.0;
  1598 }
  1607 }
  1599 
  1608 
  1600 size_t G1CollectorPolicy::expansion_amount() const {
  1609 void G1CollectorPolicy::clear_ratio_check_data() {
       
  1610   _ratio_over_threshold_count = 0;
       
  1611   _ratio_over_threshold_sum = 0.0;
       
  1612   _pauses_since_start = 0;
       
  1613 }
       
  1614 
       
  1615 size_t G1CollectorPolicy::expansion_amount() {
  1601   double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
  1616   double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
       
  1617   double last_gc_overhead = _last_pause_time_ratio * 100.0;
  1602   double threshold = _gc_overhead_perc;
  1618   double threshold = _gc_overhead_perc;
  1603   if (recent_gc_overhead > threshold) {
  1619   size_t expand_bytes = 0;
  1604     // We will double the existing space, or take
  1620 
  1605     // G1ExpandByPercentOfAvailable % of the available expansion
  1621   // If the heap is at less than half its maximum size, scale the threshold down,
  1606     // space, whichever is smaller, bounded below by a minimum
  1622   // to a limit of 1. Thus the smaller the heap is, the more likely it is to expand,
  1607     // expansion (unless that's all that's left.)
  1623   // though the scaling code will likely keep the increase small.
  1608     const size_t min_expand_bytes = 1*M;
  1624   if (_g1->capacity() <= _g1->max_capacity() / 2) {
       
  1625     threshold *= (double)_g1->capacity() / (double)(_g1->max_capacity() / 2);
       
  1626     threshold = MAX2(threshold, 1.0);
       
  1627   }
       
  1628 
       
  1629   // If the last GC time ratio is over the threshold, increment the count of
       
  1630   // times it has been exceeded, and add this ratio to the sum of exceeded
       
  1631   // ratios.
       
  1632   if (last_gc_overhead > threshold) {
       
  1633     _ratio_over_threshold_count++;
       
  1634     _ratio_over_threshold_sum += last_gc_overhead;
       
  1635   }
       
  1636 
       
  1637   // Check if we've had enough GC time ratio checks that were over the
       
  1638   // threshold to trigger an expansion. We'll also expand if we've
       
  1639   // reached the end of the history buffer and the average of all entries
       
  1640   // is still over the threshold. This indicates a smaller number of GCs were
       
  1641   // long enough to make the average exceed the threshold.
       
  1642   bool filled_history_buffer = _pauses_since_start == NumPrevPausesForHeuristics;
       
  1643   if ((_ratio_over_threshold_count == MinOverThresholdForGrowth) ||
       
  1644       (filled_history_buffer && (recent_gc_overhead > threshold))) {
       
  1645     size_t min_expand_bytes = HeapRegion::GrainBytes;
  1609     size_t reserved_bytes = _g1->max_capacity();
  1646     size_t reserved_bytes = _g1->max_capacity();
  1610     size_t committed_bytes = _g1->capacity();
  1647     size_t committed_bytes = _g1->capacity();
  1611     size_t uncommitted_bytes = reserved_bytes - committed_bytes;
  1648     size_t uncommitted_bytes = reserved_bytes - committed_bytes;
  1612     size_t expand_bytes;
       
  1613     size_t expand_bytes_via_pct =
  1649     size_t expand_bytes_via_pct =
  1614       uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
  1650       uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
  1615     expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
  1651     double scale_factor = 1.0;
  1616     expand_bytes = MAX2(expand_bytes, min_expand_bytes);
  1652 
  1617     expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
  1653     // If the current size is less than 1/4 of the Initial heap size, expand
       
  1654     // by half of the delta between the current and Initial sizes. IE, grow
       
  1655     // back quickly.
       
  1656     //
       
  1657     // Otherwise, take the current size, or G1ExpandByPercentOfAvailable % of
       
  1658     // the available expansion space, whichever is smaller, as the base
       
  1659     // expansion size. Then possibly scale this size according to how much the
       
  1660     // threshold has (on average) been exceeded by. If the delta is small
       
  1661     // (less than the StartScaleDownAt value), scale the size down linearly, but
       
  1662     // not by less than MinScaleDownFactor. If the delta is large (greater than
       
  1663     // the StartScaleUpAt value), scale up, but adding no more than MaxScaleUpFactor
       
  1664     // times the base size. The scaling will be linear in the range from
       
  1665     // StartScaleUpAt to (StartScaleUpAt + ScaleUpRange). In other words,
       
  1666     // ScaleUpRange sets the rate of scaling up.
       
  1667     if (committed_bytes < InitialHeapSize / 4) {
       
  1668       expand_bytes = (InitialHeapSize - committed_bytes) / 2;
       
  1669     } else {
       
  1670       double const MinScaleDownFactor = 0.2;
       
  1671       double const MaxScaleUpFactor = 2;
       
  1672       double const StartScaleDownAt = _gc_overhead_perc;
       
  1673       double const StartScaleUpAt = _gc_overhead_perc * 1.5;
       
  1674       double const ScaleUpRange = _gc_overhead_perc * 2.0;
       
  1675 
       
  1676       double ratio_delta;
       
  1677       if (filled_history_buffer) {
       
  1678         ratio_delta = recent_gc_overhead - threshold;
       
  1679       } else {
       
  1680         ratio_delta = (_ratio_over_threshold_sum/_ratio_over_threshold_count) - threshold;
       
  1681       }
       
  1682 
       
  1683       expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
       
  1684       if (ratio_delta < StartScaleDownAt) {
       
  1685         scale_factor = ratio_delta / StartScaleDownAt;
       
  1686         scale_factor = MAX2(scale_factor, MinScaleDownFactor);
       
  1687       } else if (ratio_delta > StartScaleUpAt) {
       
  1688         scale_factor = 1 + ((ratio_delta - StartScaleUpAt) / ScaleUpRange);
       
  1689         scale_factor = MIN2(scale_factor, MaxScaleUpFactor);
       
  1690       }
       
  1691     }
  1618 
  1692 
  1619     ergo_verbose5(ErgoHeapSizing,
  1693     ergo_verbose5(ErgoHeapSizing,
  1620                   "attempt heap expansion",
  1694                   "attempt heap expansion",
  1621                   ergo_format_reason("recent GC overhead higher than "
  1695                   ergo_format_reason("recent GC overhead higher than "
  1622                                      "threshold after GC")
  1696                                      "threshold after GC")
  1623                   ergo_format_perc("recent GC overhead")
  1697                   ergo_format_perc("recent GC overhead")
  1624                   ergo_format_perc("threshold")
  1698                   ergo_format_perc("current threshold")
  1625                   ergo_format_byte("uncommitted")
  1699                   ergo_format_byte("uncommitted")
  1626                   ergo_format_byte_perc("calculated expansion amount"),
  1700                   ergo_format_byte_perc("base expansion amount and scale"),
  1627                   recent_gc_overhead, threshold,
  1701                   recent_gc_overhead, threshold,
  1628                   uncommitted_bytes,
  1702                   uncommitted_bytes,
  1629                   expand_bytes_via_pct, (double) G1ExpandByPercentOfAvailable);
  1703                   expand_bytes, scale_factor * 100);
  1630 
  1704 
  1631     return expand_bytes;
  1705     expand_bytes = static_cast<size_t>(expand_bytes * scale_factor);
       
  1706 
       
  1707     // Ensure the expansion size is at least the minimum growth amount
       
  1708     // and at most the remaining uncommitted byte size.
       
  1709     expand_bytes = MAX2(expand_bytes, min_expand_bytes);
       
  1710     expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
       
  1711 
       
  1712     clear_ratio_check_data();
  1632   } else {
  1713   } else {
  1633     return 0;
  1714     // An expansion was not triggered. If we've started counting, increment
  1634   }
  1715     // the number of checks we've made in the current window.  If we've
       
  1716     // reached the end of the window without resizing, clear the counters to
       
  1717     // start again the next time we see a ratio above the threshold.
       
  1718     if (_ratio_over_threshold_count > 0) {
       
  1719       _pauses_since_start++;
       
  1720       if (_pauses_since_start > NumPrevPausesForHeuristics) {
       
  1721         clear_ratio_check_data();
       
  1722       }
       
  1723     }
       
  1724   }
       
  1725 
       
  1726   return expand_bytes;
  1635 }
  1727 }
  1636 
  1728 
  1637 void G1CollectorPolicy::print_tracing_info() const {
  1729 void G1CollectorPolicy::print_tracing_info() const {
  1638   _trace_young_gen_time_data.print();
  1730   _trace_young_gen_time_data.print();
  1639   _trace_old_gen_time_data.print();
  1731   _trace_old_gen_time_data.print();