< prev index next >
src/hotspot/share/gc/g1/g1HeapSizingPolicy.hpp
Print this page
rev 59703 : imported patch 8238687-investigate-memory-uncommit-during-young-gc
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -24,42 +24,86 @@
#ifndef SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
#define SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
#include "memory/allocation.hpp"
+#include "utilities/numberSeq.hpp"
class G1Analytics;
class G1CollectedHeap;
+//
+// Contains heuristics for heap sizing, i.e. expansion or shrinking, during operation
+// based on gc time ratio.
+//
+// The heuristics tracks both short term and long term behavior to effect heap
+// size change.
+//
+// Short term tracking is based on short-term gc time ratio behavior: for this we
+// record events for when actual gc time ratio is outside the range of
+// [GCTimeRatio * G1MinimumPercentOfGCTimeRatio, GCTimeRatio] or not in a counter.
+// If below that range, we decrement that counter, if above, we increment it.
+//
+// The intent of this mechanism is to filter short term events as heap sizing has
+// some overhead.
+//
+// If that counter reaches the MinOverThresholdForExpansion we consider expansion,
+// if that counter reaches -MinOverThresholdForShrink we consider heap shrinking.
+//
+// While doing so, we accumulate the difference to the midpoint of this range to
+// guide the expansion/shrinking amount.
+//
+// Further, if there is no short-term based resizing event for a "long" time, we
+// decay that counter, i.e. drop it towards zero again to avoid that previous
+// intermediate length short term behavior followed by a quiet time and a single
+// short term event causes unnecessary resizes.
+//
+// Long term behavior is solely managed by regularly comparing actual long term
+// gc time ratio with the boundaries of above range in regular long term
+// intervals. If current long term gc time ratio is outside, expand or shrink
+// respectively.
+//
class G1HeapSizingPolicy: public CHeapObj<mtGC> {
- // MinOverThresholdForGrowth must be less than the number of recorded
- // pause times in G1Analytics, representing the minimum number of pause
- // time ratios that exceed GCTimeRatio before a heap expansion will be triggered.
- const static uint MinOverThresholdForGrowth = 4;
+ // MinOverThresholdForExpansion/Shrink define the number of actual gc time
+ // ratios over the upper and lower thresholds respectively.
+ const static int MinOverThresholdForExpansion = 4;
+ const static int MinOverThresholdForShrink = 4;
const G1CollectedHeap* _g1h;
const G1Analytics* _analytics;
- const uint _num_prev_pauses_for_heuristics;
- // Ratio check data for determining if heap growth is necessary.
- uint _ratio_over_threshold_count;
- double _ratio_over_threshold_sum;
- uint _pauses_since_start;
+ const uint _long_term_interval;
+ // Number of times actual gc time ratio crossed lower and upper threshold
+ // recently; every time the upper threshold is exceeded, it is incremented,
+ // and decremented if the lower threshold is undercut.
+ int _ratio_exceeds_threshold;
+ // Recent actual gc time ratios relative to the middle of lower and upper threshold.
+ TruncatedSeq _recent_pause_ratios;
+ uint _long_term_count;
+
+ // Clear ratio tracking data used by resize_amount().
+ void reset_ratio_tracking_data();
+ void decay_ratio_tracking_data();
- // Scale "full" gc pause time threshold with heap size as we want to resize more
+ // Scale "full" gc time ratio threshold with heap size as we want to resize more
// eagerly at small heap sizes.
double scale_with_heap(double pause_time_threshold);
+ // Scale the ratio delta depending on how far it exceeds the actual target gc time
+ // ratio.
+ double scale_resize_ratio_delta(double ratio_delta);
+
G1HeapSizingPolicy(const G1CollectedHeap* g1h, const G1Analytics* analytics);
public:
- // If an expansion would be appropriate, because recent GC overhead had
- // exceeded the desired limit, return an amount to expand by.
- size_t expansion_amount();
+ // Return by how many bytes the heap should be changed based on recent gc time
+ // ratio after young collection. Positive values mean expansion is desired, and
+ // negative values mean desired shrinking.
+ ssize_t resize_amount_after_young_gc();
- // Clear ratio tracking data used by expansion_amount().
- void clear_ratio_check_data();
+ // Calculate the target capacity based on used bytes and free ratio.
+ size_t target_heap_capacity(size_t used_bytes, uintx free_ratio) const;
static G1HeapSizingPolicy* create(const G1CollectedHeap* g1h, const G1Analytics* analytics);
};
#endif // SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
< prev index next >