1 /*
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
26 #define SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
27
28 #include "memory/allocation.hpp"
29
30 class G1Analytics;
31 class G1CollectedHeap;
32
33 class G1HeapSizingPolicy: public CHeapObj<mtGC> {
34 // MinOverThresholdForGrowth must be less than the number of recorded
35 // pause times in G1Analytics, representing the minimum number of pause
36 // time ratios that exceed GCTimeRatio before a heap expansion will be triggered.
37 const static uint MinOverThresholdForGrowth = 4;
38
39 const G1CollectedHeap* _g1h;
40 const G1Analytics* _analytics;
41
42 const uint _num_prev_pauses_for_heuristics;
43 // Ratio check data for determining if heap growth is necessary.
44 uint _ratio_over_threshold_count;
45 double _ratio_over_threshold_sum;
46 uint _pauses_since_start;
47
48 // Scale "full" gc pause time threshold with heap size as we want to resize more
49 // eagerly at small heap sizes.
50 double scale_with_heap(double pause_time_threshold);
51
52 G1HeapSizingPolicy(const G1CollectedHeap* g1h, const G1Analytics* analytics);
53 public:
54
55 // If an expansion would be appropriate, because recent GC overhead had
56 // exceeded the desired limit, return an amount to expand by.
57 size_t expansion_amount();
58
59 // Clear ratio tracking data used by expansion_amount().
60 void clear_ratio_check_data();
61
62 static G1HeapSizingPolicy* create(const G1CollectedHeap* g1h, const G1Analytics* analytics);
63 };
64
65 #endif // SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
|
1 /*
2 * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
26 #define SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/numberSeq.hpp"
30
31 class G1Analytics;
32 class G1CollectedHeap;
33
34 //
35 // Contains heuristics for heap sizing, i.e. expansion or shrinking, during operation
36 // based on gc time ratio.
37 //
38 // The heuristics tracks both short term and long term behavior to effect heap
39 // size change.
40 //
41 // Short term tracking is based on short-term gc time ratio behavior: for this we
42 // record events for when actual gc time ratio is outside the range of
43 // [GCTimeRatio * G1MinimumPercentOfGCTimeRatio, GCTimeRatio] or not in a counter.
44 // If below that range, we decrement that counter, if above, we increment it.
45 //
46 // The intent of this mechanism is to filter short term events as heap sizing has
47 // some overhead.
48 //
49 // If that counter reaches the MinOverThresholdForExpansion we consider expansion,
50 // if that counter reaches -MinOverThresholdForShrink we consider heap shrinking.
51 //
52 // While doing so, we accumulate the difference to the midpoint of this range to
53 // guide the expansion/shrinking amount.
54 //
55 // Further, if there is no short-term based resizing event for a "long" time, we
56 // decay that counter, i.e. drop it towards zero again to avoid that previous
57 // intermediate length short term behavior followed by a quiet time and a single
58 // short term event causes unnecessary resizes.
59 //
60 // Long term behavior is solely managed by regularly comparing actual long term
61 // gc time ratio with the boundaries of above range in regular long term
62 // intervals. If current long term gc time ratio is outside, expand or shrink
63 // respectively.
64 //
65 class G1HeapSizingPolicy: public CHeapObj<mtGC> {
66 // MinOverThresholdForExpansion/Shrink define the number of actual gc time
67 // ratios over the upper and lower thresholds respectively.
68 const static int MinOverThresholdForExpansion = 4;
69 const static int MinOverThresholdForShrink = 4;
70
71 const G1CollectedHeap* _g1h;
72 const G1Analytics* _analytics;
73
74 const uint _long_term_interval;
75 // Number of times actual gc time ratio crossed lower and upper threshold
76 // recently; every time the upper threshold is exceeded, it is incremented,
77 // and decremented if the lower threshold is undercut.
78 int _ratio_exceeds_threshold;
79 // Recent actual gc time ratios relative to the middle of lower and upper threshold.
80 TruncatedSeq _recent_pause_ratios;
81 uint _long_term_count;
82
83 // Clear ratio tracking data used by resize_amount().
84 void reset_ratio_tracking_data();
85 void decay_ratio_tracking_data();
86
87 // Scale "full" gc time ratio threshold with heap size as we want to resize more
88 // eagerly at small heap sizes.
89 double scale_with_heap(double pause_time_threshold);
90
91 // Scale the ratio delta depending on how far it exceeds the actual target gc time
92 // ratio.
93 double scale_resize_ratio_delta(double ratio_delta);
94
95 G1HeapSizingPolicy(const G1CollectedHeap* g1h, const G1Analytics* analytics);
96 public:
97
98 // Return by how many bytes the heap should be changed based on recent gc time
99 // ratio after young collection. Positive values mean expansion is desired, and
100 // negative values mean desired shrinking.
101 ssize_t resize_amount_after_young_gc();
102
103 // Calculate the target capacity based on used bytes and free ratio.
104 size_t target_heap_capacity(size_t used_bytes, uintx free_ratio) const;
105
106 static G1HeapSizingPolicy* create(const G1CollectedHeap* g1h, const G1Analytics* analytics);
107 };
108
109 #endif // SHARE_GC_G1_G1HEAPSIZINGPOLICY_HPP
|