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 #include "precompiled.hpp"
26 #include "gc/g1/g1CollectedHeap.inline.hpp"
27 #include "gc/g1/g1IHOPControl.hpp"
28 #include "gc/g1/g1Predictions.hpp"
29 #include "gc/g1/g1Trace.hpp"
30 #include "logging/log.hpp"
31
32 G1IHOPControl::G1IHOPControl(double initial_ihop_percent) :
33 _initial_ihop_percent(initial_ihop_percent),
34 _target_occupancy(0),
35 _last_allocation_time_s(0.0),
36 _last_allocated_bytes(0)
37 {
38 assert(_initial_ihop_percent >= 0.0 && _initial_ihop_percent <= 100.0, "Initial IHOP value must be between 0 and 100 but is %.3f", initial_ihop_percent);
39 }
40
41 void G1IHOPControl::update_target_occupancy(size_t new_target_occupancy) {
42 log_debug(gc, ihop)("Target occupancy update: old: " SIZE_FORMAT "B, new: " SIZE_FORMAT "B",
43 _target_occupancy, new_target_occupancy);
44 _target_occupancy = new_target_occupancy;
45 }
46
47 void G1IHOPControl::update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) {
48 assert(allocation_time_s >= 0.0, "Allocation time must be positive but is %.3f", allocation_time_s);
49
50 _last_allocation_time_s = allocation_time_s;
51 _last_allocated_bytes = allocated_bytes;
52 }
53
54 void G1IHOPControl::print() {
55 assert(_target_occupancy > 0, "Target occupancy still not updated yet.");
56 size_t cur_conc_mark_start_threshold = get_conc_mark_start_threshold();
57 log_debug(gc, ihop)("Basic information (value update), threshold: " SIZE_FORMAT "B (%1.2f), target occupancy: " SIZE_FORMAT "B, current occupancy: " SIZE_FORMAT "B, "
58 "recent allocation size: " SIZE_FORMAT "B, recent allocation duration: %1.2fms, recent old gen allocation rate: %1.2fB/s, recent marking phase length: %1.2fms",
59 cur_conc_mark_start_threshold,
60 percent_of(cur_conc_mark_start_threshold, _target_occupancy),
61 _target_occupancy,
62 G1CollectedHeap::heap()->used(),
63 _last_allocated_bytes,
64 _last_allocation_time_s * 1000.0,
65 _last_allocation_time_s > 0.0 ? _last_allocated_bytes / _last_allocation_time_s : 0.0,
66 last_marking_length_s() * 1000.0);
67 }
68
69 void G1IHOPControl::send_trace_event(G1NewTracer* tracer) {
70 assert(_target_occupancy > 0, "Target occupancy still not updated yet.");
71 tracer->report_basic_ihop_statistics(get_conc_mark_start_threshold(),
72 _target_occupancy,
73 G1CollectedHeap::heap()->used(),
74 _last_allocated_bytes,
75 _last_allocation_time_s,
76 last_marking_length_s());
77 }
78
79 G1StaticIHOPControl::G1StaticIHOPControl(double ihop_percent) :
80 G1IHOPControl(ihop_percent),
81 _last_marking_length_s(0.0) {
82 }
83
84 G1AdaptiveIHOPControl::G1AdaptiveIHOPControl(double ihop_percent,
85 G1Predictions const* predictor,
86 size_t heap_reserve_percent,
87 size_t heap_waste_percent) :
88 G1IHOPControl(ihop_percent),
89 _heap_reserve_percent(heap_reserve_percent),
90 _heap_waste_percent(heap_waste_percent),
91 _predictor(predictor),
92 _marking_times_s(10, 0.95),
93 _allocation_rate_s(10, 0.95),
94 _last_unrestrained_young_size(0)
95 {
96 }
97
98 size_t G1AdaptiveIHOPControl::actual_target_threshold() const {
99 guarantee(_target_occupancy > 0, "Target occupancy still not updated yet.");
100 // The actual target threshold takes the heap reserve and the expected waste in
101 // free space into account.
102 // _heap_reserve is that part of the total heap capacity that is reserved for
103 // eventual promotion failure.
104 // _heap_waste is the amount of space will never be reclaimed in any
105 // heap, so can not be used for allocation during marking and must always be
106 // considered.
107
108 double safe_total_heap_percentage = MIN2((double)(_heap_reserve_percent + _heap_waste_percent), 100.0);
128 double pred_promotion_rate = predict(&_allocation_rate_s);
129 size_t pred_promotion_size = (size_t)(pred_marking_time * pred_promotion_rate);
130
131 size_t predicted_needed_bytes_during_marking =
132 pred_promotion_size +
133 // In reality we would need the maximum size of the young gen during
134 // marking. This is a conservative estimate.
135 _last_unrestrained_young_size;
136
137 size_t internal_threshold = actual_target_threshold();
138 size_t predicted_initiating_threshold = predicted_needed_bytes_during_marking < internal_threshold ?
139 internal_threshold - predicted_needed_bytes_during_marking :
140 0;
141 return predicted_initiating_threshold;
142 } else {
143 // Use the initial value.
144 return (size_t)(_initial_ihop_percent * _target_occupancy / 100.0);
145 }
146 }
147
148 void G1AdaptiveIHOPControl::update_allocation_info(double allocation_time_s,
149 size_t allocated_bytes,
150 size_t additional_buffer_size) {
151 G1IHOPControl::update_allocation_info(allocation_time_s, allocated_bytes, additional_buffer_size);
152
153 double allocation_rate = (double) allocated_bytes / allocation_time_s;
154 _allocation_rate_s.add(allocation_rate);
155
156 _last_unrestrained_young_size = additional_buffer_size;
157 }
158
159 void G1AdaptiveIHOPControl::update_marking_length(double marking_length_s) {
160 assert(marking_length_s >= 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
161 _marking_times_s.add(marking_length_s);
162 }
163
164 void G1AdaptiveIHOPControl::print() {
165 G1IHOPControl::print();
166 size_t actual_target = actual_target_threshold();
167 log_debug(gc, ihop)("Adaptive IHOP information (value update), threshold: " SIZE_FORMAT "B (%1.2f), internal target occupancy: " SIZE_FORMAT "B, "
168 "occupancy: " SIZE_FORMAT "B, additional buffer size: " SIZE_FORMAT "B, predicted old gen allocation rate: %1.2fB/s, "
169 "predicted marking phase length: %1.2fms, prediction active: %s",
170 get_conc_mark_start_threshold(),
171 percent_of(get_conc_mark_start_threshold(), actual_target),
172 actual_target,
173 G1CollectedHeap::heap()->used(),
174 _last_unrestrained_young_size,
|
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 #include "precompiled.hpp"
26 #include "gc/g1/g1CollectedHeap.inline.hpp"
27 #include "gc/g1/g1IHOPControl.hpp"
28 #include "gc/g1/g1Predictions.hpp"
29 #include "gc/g1/g1Trace.hpp"
30 #include "logging/log.hpp"
31
32 G1IHOPControl::G1IHOPControl(double initial_ihop_percent,
33 G1OldGenAllocationTracker const* old_gen_alloc_tracker) :
34 _initial_ihop_percent(initial_ihop_percent),
35 _target_occupancy(0),
36 _last_allocation_time_s(0.0),
37 _old_gen_alloc_tracker(old_gen_alloc_tracker)
38 {
39 assert(_initial_ihop_percent >= 0.0 && _initial_ihop_percent <= 100.0, "Initial IHOP value must be between 0 and 100 but is %.3f", initial_ihop_percent);
40 }
41
42 void G1IHOPControl::update_target_occupancy(size_t new_target_occupancy) {
43 log_debug(gc, ihop)("Target occupancy update: old: " SIZE_FORMAT "B, new: " SIZE_FORMAT "B",
44 _target_occupancy, new_target_occupancy);
45 _target_occupancy = new_target_occupancy;
46 }
47
48 void G1IHOPControl::update_allocation_info(double allocation_time_s, size_t additional_buffer_size) {
49 assert(allocation_time_s >= 0.0, "Allocation time must be positive but is %.3f", allocation_time_s);
50
51 _last_allocation_time_s = allocation_time_s;
52 }
53
54 void G1IHOPControl::print() {
55 assert(_target_occupancy > 0, "Target occupancy still not updated yet.");
56 size_t cur_conc_mark_start_threshold = get_conc_mark_start_threshold();
57 log_debug(gc, ihop)("Basic information (value update), threshold: " SIZE_FORMAT "B (%1.2f), target occupancy: " SIZE_FORMAT "B, current occupancy: " SIZE_FORMAT "B, "
58 "recent allocation size: " SIZE_FORMAT "B, recent allocation duration: %1.2fms, recent old gen allocation rate: %1.2fB/s, recent marking phase length: %1.2fms",
59 cur_conc_mark_start_threshold,
60 percent_of(cur_conc_mark_start_threshold, _target_occupancy),
61 _target_occupancy,
62 G1CollectedHeap::heap()->used(),
63 _old_gen_alloc_tracker->last_period_old_bytes(),
64 _last_allocation_time_s * 1000.0,
65 _last_allocation_time_s > 0.0 ? _old_gen_alloc_tracker->last_period_old_bytes() / _last_allocation_time_s : 0.0,
66 last_marking_length_s() * 1000.0);
67 }
68
69 void G1IHOPControl::send_trace_event(G1NewTracer* tracer) {
70 assert(_target_occupancy > 0, "Target occupancy still not updated yet.");
71 tracer->report_basic_ihop_statistics(get_conc_mark_start_threshold(),
72 _target_occupancy,
73 G1CollectedHeap::heap()->used(),
74 _old_gen_alloc_tracker->last_period_old_bytes(),
75 _last_allocation_time_s,
76 last_marking_length_s());
77 }
78
79 G1StaticIHOPControl::G1StaticIHOPControl(double ihop_percent,
80 G1OldGenAllocationTracker const* old_gen_alloc_tracker) :
81 G1IHOPControl(ihop_percent, old_gen_alloc_tracker),
82 _last_marking_length_s(0.0) {
83 }
84
85 G1AdaptiveIHOPControl::G1AdaptiveIHOPControl(double ihop_percent,
86 G1OldGenAllocationTracker const* old_gen_alloc_tracker,
87 G1Predictions const* predictor,
88 size_t heap_reserve_percent,
89 size_t heap_waste_percent) :
90 G1IHOPControl(ihop_percent, old_gen_alloc_tracker),
91 _heap_reserve_percent(heap_reserve_percent),
92 _heap_waste_percent(heap_waste_percent),
93 _predictor(predictor),
94 _marking_times_s(10, 0.95),
95 _allocation_rate_s(10, 0.95),
96 _last_unrestrained_young_size(0)
97 {
98 }
99
100 size_t G1AdaptiveIHOPControl::actual_target_threshold() const {
101 guarantee(_target_occupancy > 0, "Target occupancy still not updated yet.");
102 // The actual target threshold takes the heap reserve and the expected waste in
103 // free space into account.
104 // _heap_reserve is that part of the total heap capacity that is reserved for
105 // eventual promotion failure.
106 // _heap_waste is the amount of space will never be reclaimed in any
107 // heap, so can not be used for allocation during marking and must always be
108 // considered.
109
110 double safe_total_heap_percentage = MIN2((double)(_heap_reserve_percent + _heap_waste_percent), 100.0);
130 double pred_promotion_rate = predict(&_allocation_rate_s);
131 size_t pred_promotion_size = (size_t)(pred_marking_time * pred_promotion_rate);
132
133 size_t predicted_needed_bytes_during_marking =
134 pred_promotion_size +
135 // In reality we would need the maximum size of the young gen during
136 // marking. This is a conservative estimate.
137 _last_unrestrained_young_size;
138
139 size_t internal_threshold = actual_target_threshold();
140 size_t predicted_initiating_threshold = predicted_needed_bytes_during_marking < internal_threshold ?
141 internal_threshold - predicted_needed_bytes_during_marking :
142 0;
143 return predicted_initiating_threshold;
144 } else {
145 // Use the initial value.
146 return (size_t)(_initial_ihop_percent * _target_occupancy / 100.0);
147 }
148 }
149
150 double G1AdaptiveIHOPControl::last_mutator_period_old_allocation_rate() const {
151 assert(_last_allocation_time_s > 0, "This should not be called when the last GC is full");
152
153 return _old_gen_alloc_tracker->last_period_net_survived_old_bytes() / _last_allocation_time_s;
154 }
155
156 void G1AdaptiveIHOPControl::update_allocation_info(double allocation_time_s,
157 size_t additional_buffer_size) {
158 G1IHOPControl::update_allocation_info(allocation_time_s, additional_buffer_size);
159 _allocation_rate_s.add(last_mutator_period_old_allocation_rate());
160
161 _last_unrestrained_young_size = additional_buffer_size;
162 }
163
164 void G1AdaptiveIHOPControl::update_marking_length(double marking_length_s) {
165 assert(marking_length_s >= 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
166 _marking_times_s.add(marking_length_s);
167 }
168
169 void G1AdaptiveIHOPControl::print() {
170 G1IHOPControl::print();
171 size_t actual_target = actual_target_threshold();
172 log_debug(gc, ihop)("Adaptive IHOP information (value update), threshold: " SIZE_FORMAT "B (%1.2f), internal target occupancy: " SIZE_FORMAT "B, "
173 "occupancy: " SIZE_FORMAT "B, additional buffer size: " SIZE_FORMAT "B, predicted old gen allocation rate: %1.2fB/s, "
174 "predicted marking phase length: %1.2fms, prediction active: %s",
175 get_conc_mark_start_threshold(),
176 percent_of(get_conc_mark_start_threshold(), actual_target),
177 actual_target,
178 G1CollectedHeap::heap()->used(),
179 _last_unrestrained_young_size,
|