1 /*
2 * Copyright (c) 2015, 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_G1IHOPCONTROL_HPP
26 #define SHARE_GC_G1_G1IHOPCONTROL_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/numberSeq.hpp"
30
31 class G1Predictions;
32 class G1NewTracer;
33
34 // Base class for algorithms that calculate the heap occupancy at which
35 // concurrent marking should start. This heap usage threshold should be relative
36 // to old gen size.
37 class G1IHOPControl : public CHeapObj<mtGC> {
38 protected:
39 // The initial IHOP value relative to the target occupancy.
40 double _initial_ihop_percent;
41 // The target maximum occupancy of the heap. The target occupancy is the number
42 // of bytes when marking should be finished and reclaim started.
43 size_t _target_occupancy;
44
45 // Most recent complete mutator allocation period in seconds.
46 double _last_allocation_time_s;
47 // Amount of bytes allocated during _last_allocation_time_s.
48 size_t _last_allocated_bytes;
49
50 // Initialize an instance with the initial IHOP value in percent. The target
51 // occupancy will be updated at the first heap expansion.
52 G1IHOPControl(double initial_ihop_percent);
53
54 // Most recent time from the end of the concurrent start to the start of the first
55 // mixed gc.
56 virtual double last_marking_length_s() const = 0;
57 public:
58 virtual ~G1IHOPControl() { }
59
60 // Get the current non-young occupancy at which concurrent marking should start.
61 virtual size_t get_conc_mark_start_threshold() = 0;
62
63 // Adjust target occupancy.
64 virtual void update_target_occupancy(size_t new_target_occupancy);
65 // Update information about time during which allocations in the Java heap occurred,
66 // how large these allocations were in bytes, and an additional buffer.
67 // The allocations should contain any amount of space made unusable for further
68 // allocation, e.g. any waste caused by TLAB allocation, space at the end of
69 // humongous objects that can not be used for allocation, etc.
70 // Together with the target occupancy, this additional buffer should contain the
71 // difference between old gen size and total heap size at the start of reclamation,
72 // and space required for that reclamation.
73 virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size);
74 // Update the time spent in the mutator beginning from the end of concurrent start to
75 // the first mixed gc.
76 virtual void update_marking_length(double marking_length_s) = 0;
77
78 virtual void print();
79 virtual void send_trace_event(G1NewTracer* tracer);
80 };
81
82 // The returned concurrent mark starting occupancy threshold is a fixed value
83 // relative to the maximum heap size.
84 class G1StaticIHOPControl : public G1IHOPControl {
85 // Most recent mutator time between the end of concurrent mark to the start of the
86 // first mixed gc.
87 double _last_marking_length_s;
88 protected:
89 double last_marking_length_s() const { return _last_marking_length_s; }
90 public:
91 G1StaticIHOPControl(double ihop_percent);
92
93 size_t get_conc_mark_start_threshold() {
94 guarantee(_target_occupancy > 0, "Target occupancy must have been initialized.");
95 return (size_t) (_initial_ihop_percent * _target_occupancy / 100.0);
96 }
97
98 virtual void update_marking_length(double marking_length_s) {
99 assert(marking_length_s > 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
100 _last_marking_length_s = marking_length_s;
101 }
102 };
103
104 // This algorithm tries to return a concurrent mark starting occupancy value that
105 // makes sure that during marking the given target occupancy is never exceeded,
106 // based on predictions of current allocation rate and time periods between
107 // concurrent start and the first mixed gc.
108 class G1AdaptiveIHOPControl : public G1IHOPControl {
109 size_t _heap_reserve_percent; // Percentage of maximum heap capacity we should avoid to touch
110 size_t _heap_waste_percent; // Percentage of free heap that should be considered as waste.
111
115 TruncatedSeq _allocation_rate_s;
116
117 // The most recent unrestrained size of the young gen. This is used as an additional
118 // factor in the calculation of the threshold, as the threshold is based on
119 // non-young gen occupancy at the end of GC. For the IHOP threshold, we need to
120 // consider the young gen size during that time too.
121 // Since we cannot know what young gen sizes are used in the future, we will just
122 // use the current one. We expect that this one will be one with a fairly large size,
123 // as there is no marking or mixed gc that could impact its size too much.
124 size_t _last_unrestrained_young_size;
125
126 // Get a new prediction bounded below by zero from the given sequence.
127 double predict(TruncatedSeq const* seq) const;
128
129 bool have_enough_data_for_prediction() const;
130
131 // The "actual" target threshold the algorithm wants to keep during and at the
132 // end of marking. This is typically lower than the requested threshold, as the
133 // algorithm needs to consider restrictions by the environment.
134 size_t actual_target_threshold() const;
135 protected:
136 virtual double last_marking_length_s() const { return _marking_times_s.last(); }
137 public:
138 G1AdaptiveIHOPControl(double ihop_percent,
139 G1Predictions const* predictor,
140 size_t heap_reserve_percent, // The percentage of total heap capacity that should not be tapped into.
141 size_t heap_waste_percent); // The percentage of the free space in the heap that we think is not usable for allocation.
142
143 virtual size_t get_conc_mark_start_threshold();
144
145 virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size);
146 virtual void update_marking_length(double marking_length_s);
147
148 virtual void print();
149 virtual void send_trace_event(G1NewTracer* tracer);
150 };
151
152 #endif // SHARE_GC_G1_G1IHOPCONTROL_HPP
|
1 /*
2 * Copyright (c) 2015, 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_G1IHOPCONTROL_HPP
26 #define SHARE_GC_G1_G1IHOPCONTROL_HPP
27
28 #include "gc/g1/g1OldGenAllocationTracker.hpp"
29 #include "memory/allocation.hpp"
30 #include "utilities/numberSeq.hpp"
31
32 class G1Predictions;
33 class G1NewTracer;
34
35 // Base class for algorithms that calculate the heap occupancy at which
36 // concurrent marking should start. This heap usage threshold should be relative
37 // to old gen size.
38 class G1IHOPControl : public CHeapObj<mtGC> {
39 protected:
40 // The initial IHOP value relative to the target occupancy.
41 double _initial_ihop_percent;
42 // The target maximum occupancy of the heap. The target occupancy is the number
43 // of bytes when marking should be finished and reclaim started.
44 size_t _target_occupancy;
45
46 // Most recent complete mutator allocation period in seconds.
47 double _last_allocation_time_s;
48
49 const G1OldGenAllocationTracker* _old_gen_alloc_tracker;
50 // Initialize an instance with the old gen allocation tracker and the
51 // initial IHOP value in percent. The target occupancy will be updated
52 // at the first heap expansion.
53 G1IHOPControl(double ihop_percent, G1OldGenAllocationTracker const* old_gen_alloc_tracker);
54
55 // Most recent time from the end of the concurrent start to the start of the first
56 // mixed gc.
57 virtual double last_marking_length_s() const = 0;
58 public:
59 virtual ~G1IHOPControl() { }
60
61 // Get the current non-young occupancy at which concurrent marking should start.
62 virtual size_t get_conc_mark_start_threshold() = 0;
63
64 // Adjust target occupancy.
65 virtual void update_target_occupancy(size_t new_target_occupancy);
66 // Update information about time during which allocations in the Java heap occurred,
67 // how large these allocations were in bytes, and an additional buffer.
68 // The allocations should contain any amount of space made unusable for further
69 // allocation, e.g. any waste caused by TLAB allocation, space at the end of
70 // humongous objects that can not be used for allocation, etc.
71 // Together with the target occupancy, this additional buffer should contain the
72 // difference between old gen size and total heap size at the start of reclamation,
73 // and space required for that reclamation.
74 virtual void update_allocation_info(double allocation_time_s, size_t additional_buffer_size);
75 // Update the time spent in the mutator beginning from the end of concurrent start to
76 // the first mixed gc.
77 virtual void update_marking_length(double marking_length_s) = 0;
78
79 virtual void print();
80 virtual void send_trace_event(G1NewTracer* tracer);
81 };
82
83 // The returned concurrent mark starting occupancy threshold is a fixed value
84 // relative to the maximum heap size.
85 class G1StaticIHOPControl : public G1IHOPControl {
86 // Most recent mutator time between the end of concurrent mark to the start of the
87 // first mixed gc.
88 double _last_marking_length_s;
89 protected:
90 double last_marking_length_s() const { return _last_marking_length_s; }
91 public:
92 G1StaticIHOPControl(double ihop_percent, G1OldGenAllocationTracker const* old_gen_alloc_tracker);
93
94 size_t get_conc_mark_start_threshold() {
95 guarantee(_target_occupancy > 0, "Target occupancy must have been initialized.");
96 return (size_t) (_initial_ihop_percent * _target_occupancy / 100.0);
97 }
98
99 virtual void update_marking_length(double marking_length_s) {
100 assert(marking_length_s > 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
101 _last_marking_length_s = marking_length_s;
102 }
103 };
104
105 // This algorithm tries to return a concurrent mark starting occupancy value that
106 // makes sure that during marking the given target occupancy is never exceeded,
107 // based on predictions of current allocation rate and time periods between
108 // concurrent start and the first mixed gc.
109 class G1AdaptiveIHOPControl : public G1IHOPControl {
110 size_t _heap_reserve_percent; // Percentage of maximum heap capacity we should avoid to touch
111 size_t _heap_waste_percent; // Percentage of free heap that should be considered as waste.
112
116 TruncatedSeq _allocation_rate_s;
117
118 // The most recent unrestrained size of the young gen. This is used as an additional
119 // factor in the calculation of the threshold, as the threshold is based on
120 // non-young gen occupancy at the end of GC. For the IHOP threshold, we need to
121 // consider the young gen size during that time too.
122 // Since we cannot know what young gen sizes are used in the future, we will just
123 // use the current one. We expect that this one will be one with a fairly large size,
124 // as there is no marking or mixed gc that could impact its size too much.
125 size_t _last_unrestrained_young_size;
126
127 // Get a new prediction bounded below by zero from the given sequence.
128 double predict(TruncatedSeq const* seq) const;
129
130 bool have_enough_data_for_prediction() const;
131
132 // The "actual" target threshold the algorithm wants to keep during and at the
133 // end of marking. This is typically lower than the requested threshold, as the
134 // algorithm needs to consider restrictions by the environment.
135 size_t actual_target_threshold() const;
136
137 // This is used by Adaptive IHOP to sample the old gen allocation rate.
138 // Different from the regular old gen allocation rate, this method considers the
139 // humongous objects that can be reclaimed early by young GCs. Since we cannot
140 // track the life cycle of individual humongous objects, we assume that such
141 // objects were all newly allocated and not survivors, unless more were
142 // reclaimed than allocated.
143 double last_mutator_period_old_allocation_rate() const;
144 protected:
145 virtual double last_marking_length_s() const { return _marking_times_s.last(); }
146 public:
147 G1AdaptiveIHOPControl(double ihop_percent,
148 G1OldGenAllocationTracker const* old_gen_alloc_tracker,
149 G1Predictions const* predictor,
150 size_t heap_reserve_percent, // The percentage of total heap capacity that should not be tapped into.
151 size_t heap_waste_percent); // The percentage of the free space in the heap that we think is not usable for allocation.
152
153 virtual size_t get_conc_mark_start_threshold();
154
155 virtual void update_allocation_info(double allocation_time_s, size_t additional_buffer_size);
156 virtual void update_marking_length(double marking_length_s);
157
158 virtual void print();
159 virtual void send_trace_event(G1NewTracer* tracer);
160 };
161
162 #endif // SHARE_GC_G1_G1IHOPCONTROL_HPP
|