Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1Analytics.cpp
40957 views
1
/*
2
* Copyright (c) 2016, 2021, 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/g1Analytics.hpp"
27
#include "gc/g1/g1Predictions.hpp"
28
#include "gc/shared/gc_globals.hpp"
29
#include "runtime/globals.hpp"
30
#include "runtime/os.hpp"
31
#include "utilities/debug.hpp"
32
#include "utilities/globalDefinitions.hpp"
33
#include "utilities/numberSeq.hpp"
34
35
// Different defaults for different number of GC threads
36
// They were chosen by running GCOld and SPECjbb on debris with different
37
// numbers of GC threads and choosing them based on the results
38
39
// all the same
40
static double rs_length_diff_defaults[] = {
41
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
42
};
43
44
static double cost_per_logged_card_ms_defaults[] = {
45
0.01, 0.005, 0.005, 0.003, 0.003, 0.002, 0.002, 0.0015
46
};
47
48
// all the same
49
static double young_card_merge_to_scan_ratio_defaults[] = {
50
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
51
};
52
53
static double young_only_cost_per_card_scan_ms_defaults[] = {
54
0.015, 0.01, 0.01, 0.008, 0.008, 0.0055, 0.0055, 0.005
55
};
56
57
static double cost_per_byte_ms_defaults[] = {
58
0.00006, 0.00003, 0.00003, 0.000015, 0.000015, 0.00001, 0.00001, 0.000009
59
};
60
61
// these should be pretty consistent
62
static double constant_other_time_ms_defaults[] = {
63
5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0
64
};
65
66
static double young_other_cost_per_region_ms_defaults[] = {
67
0.3, 0.2, 0.2, 0.15, 0.15, 0.12, 0.12, 0.1
68
};
69
70
static double non_young_other_cost_per_region_ms_defaults[] = {
71
1.0, 0.7, 0.7, 0.5, 0.5, 0.42, 0.42, 0.30
72
};
73
74
G1Analytics::G1Analytics(const G1Predictions* predictor) :
75
_predictor(predictor),
76
_recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
77
_concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
78
_concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
79
_alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
80
_prev_collection_pause_end_ms(0.0),
81
_rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
82
_concurrent_refine_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
83
_dirtied_cards_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
84
_young_card_merge_to_scan_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
85
_mixed_card_merge_to_scan_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
86
_young_cost_per_card_scan_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
87
_mixed_cost_per_card_scan_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
88
_young_cost_per_card_merge_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
89
_mixed_cost_per_card_merge_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
90
_copy_cost_per_byte_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
91
_constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
92
_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
93
_non_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
94
_pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
95
_rs_length_seq(new TruncatedSeq(TruncatedSeqLength)),
96
_cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)),
97
_recent_prev_end_times_for_all_gcs_sec(new TruncatedSeq(NumPrevPausesForHeuristics)),
98
_long_term_pause_time_ratio(0.0),
99
_short_term_pause_time_ratio(0.0) {
100
101
// Seed sequences with initial values.
102
_recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
103
_prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
104
105
int index = MIN2(ParallelGCThreads - 1, 7u);
106
107
_rs_length_diff_seq->add(rs_length_diff_defaults[index]);
108
// Start with inverse of maximum STW cost.
109
_concurrent_refine_rate_ms_seq->add(1/cost_per_logged_card_ms_defaults[0]);
110
// Some applications have very low rates for logging cards.
111
_dirtied_cards_rate_ms_seq->add(0.0);
112
_young_card_merge_to_scan_ratio_seq->add(young_card_merge_to_scan_ratio_defaults[index]);
113
_young_cost_per_card_scan_ms_seq->add(young_only_cost_per_card_scan_ms_defaults[index]);
114
115
_copy_cost_per_byte_ms_seq->add(cost_per_byte_ms_defaults[index]);
116
_constant_other_time_ms_seq->add(constant_other_time_ms_defaults[index]);
117
_young_other_cost_per_region_ms_seq->add(young_other_cost_per_region_ms_defaults[index]);
118
_non_young_other_cost_per_region_ms_seq->add(non_young_other_cost_per_region_ms_defaults[index]);
119
120
// start conservatively (around 50ms is about right)
121
_concurrent_mark_remark_times_ms->add(0.05);
122
_concurrent_mark_cleanup_times_ms->add(0.20);
123
}
124
125
bool G1Analytics::enough_samples_available(TruncatedSeq const* seq) const {
126
return seq->num() >= 3;
127
}
128
129
double G1Analytics::predict_in_unit_interval(TruncatedSeq const* seq) const {
130
return _predictor->predict_in_unit_interval(seq);
131
}
132
133
size_t G1Analytics::predict_size(TruncatedSeq const* seq) const {
134
return (size_t)predict_zero_bounded(seq);
135
}
136
137
double G1Analytics::predict_zero_bounded(TruncatedSeq const* seq) const {
138
return _predictor->predict_zero_bounded(seq);
139
}
140
141
int G1Analytics::num_alloc_rate_ms() const {
142
return _alloc_rate_ms_seq->num();
143
}
144
145
void G1Analytics::report_concurrent_mark_remark_times_ms(double ms) {
146
_concurrent_mark_remark_times_ms->add(ms);
147
}
148
149
void G1Analytics::report_alloc_rate_ms(double alloc_rate) {
150
_alloc_rate_ms_seq->add(alloc_rate);
151
}
152
153
void G1Analytics::compute_pause_time_ratios(double end_time_sec, double pause_time_ms) {
154
double long_interval_ms = (end_time_sec - oldest_known_gc_end_time_sec()) * 1000.0;
155
double gc_pause_time_ms = _recent_gc_times_ms->sum() - _recent_gc_times_ms->oldest() + pause_time_ms;
156
_long_term_pause_time_ratio = gc_pause_time_ms / long_interval_ms;
157
_long_term_pause_time_ratio = clamp(_long_term_pause_time_ratio, 0.0, 1.0);
158
159
double short_interval_ms = (end_time_sec - most_recent_gc_end_time_sec()) * 1000.0;
160
_short_term_pause_time_ratio = pause_time_ms / short_interval_ms;
161
_short_term_pause_time_ratio = clamp(_short_term_pause_time_ratio, 0.0, 1.0);
162
}
163
164
void G1Analytics::report_concurrent_refine_rate_ms(double cards_per_ms) {
165
_concurrent_refine_rate_ms_seq->add(cards_per_ms);
166
}
167
168
void G1Analytics::report_dirtied_cards_rate_ms(double cards_per_ms) {
169
_dirtied_cards_rate_ms_seq->add(cards_per_ms);
170
}
171
172
void G1Analytics::report_cost_per_card_scan_ms(double cost_per_card_ms, bool for_young_gc) {
173
if (for_young_gc) {
174
_young_cost_per_card_scan_ms_seq->add(cost_per_card_ms);
175
} else {
176
_mixed_cost_per_card_scan_ms_seq->add(cost_per_card_ms);
177
}
178
}
179
180
void G1Analytics::report_cost_per_card_merge_ms(double cost_per_card_ms, bool for_young_gc) {
181
if (for_young_gc) {
182
_young_cost_per_card_merge_ms_seq->add(cost_per_card_ms);
183
} else {
184
_mixed_cost_per_card_merge_ms_seq->add(cost_per_card_ms);
185
}
186
}
187
188
void G1Analytics::report_card_merge_to_scan_ratio(double merge_to_scan_ratio, bool for_young_gc) {
189
if (for_young_gc) {
190
_young_card_merge_to_scan_ratio_seq->add(merge_to_scan_ratio);
191
} else {
192
_mixed_card_merge_to_scan_ratio_seq->add(merge_to_scan_ratio);
193
}
194
}
195
196
void G1Analytics::report_rs_length_diff(double rs_length_diff) {
197
_rs_length_diff_seq->add(rs_length_diff);
198
}
199
200
void G1Analytics::report_cost_per_byte_ms(double cost_per_byte_ms, bool mark_or_rebuild_in_progress) {
201
if (mark_or_rebuild_in_progress) {
202
_cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms);
203
} else {
204
_copy_cost_per_byte_ms_seq->add(cost_per_byte_ms);
205
}
206
}
207
208
void G1Analytics::report_young_other_cost_per_region_ms(double other_cost_per_region_ms) {
209
_young_other_cost_per_region_ms_seq->add(other_cost_per_region_ms);
210
}
211
212
void G1Analytics::report_non_young_other_cost_per_region_ms(double other_cost_per_region_ms) {
213
_non_young_other_cost_per_region_ms_seq->add(other_cost_per_region_ms);
214
}
215
216
void G1Analytics::report_constant_other_time_ms(double constant_other_time_ms) {
217
_constant_other_time_ms_seq->add(constant_other_time_ms);
218
}
219
220
void G1Analytics::report_pending_cards(double pending_cards) {
221
_pending_cards_seq->add(pending_cards);
222
}
223
224
void G1Analytics::report_rs_length(double rs_length) {
225
_rs_length_seq->add(rs_length);
226
}
227
228
double G1Analytics::predict_alloc_rate_ms() const {
229
return predict_zero_bounded(_alloc_rate_ms_seq);
230
}
231
232
double G1Analytics::predict_concurrent_refine_rate_ms() const {
233
return predict_zero_bounded(_concurrent_refine_rate_ms_seq);
234
}
235
236
double G1Analytics::predict_dirtied_cards_rate_ms() const {
237
return predict_zero_bounded(_dirtied_cards_rate_ms_seq);
238
}
239
240
double G1Analytics::predict_young_card_merge_to_scan_ratio() const {
241
return predict_in_unit_interval(_young_card_merge_to_scan_ratio_seq);
242
}
243
244
size_t G1Analytics::predict_scan_card_num(size_t rs_length, bool for_young_gc) const {
245
if (for_young_gc || !enough_samples_available(_mixed_card_merge_to_scan_ratio_seq)) {
246
return (size_t)(rs_length * predict_young_card_merge_to_scan_ratio());
247
} else {
248
return (size_t)(rs_length * predict_in_unit_interval(_mixed_card_merge_to_scan_ratio_seq));
249
}
250
}
251
252
double G1Analytics::predict_card_merge_time_ms(size_t card_num, bool for_young_gc) const {
253
if (for_young_gc || !enough_samples_available(_mixed_cost_per_card_merge_ms_seq)) {
254
return card_num * predict_zero_bounded(_young_cost_per_card_merge_ms_seq);
255
} else {
256
return card_num * predict_zero_bounded(_mixed_cost_per_card_merge_ms_seq);
257
}
258
}
259
260
double G1Analytics::predict_card_scan_time_ms(size_t card_num, bool for_young_gc) const {
261
if (for_young_gc || !enough_samples_available(_mixed_cost_per_card_scan_ms_seq)) {
262
return card_num * predict_zero_bounded(_young_cost_per_card_scan_ms_seq);
263
} else {
264
return card_num * predict_zero_bounded(_mixed_cost_per_card_scan_ms_seq);
265
}
266
}
267
268
double G1Analytics::predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const {
269
if (!enough_samples_available(_cost_per_byte_ms_during_cm_seq)) {
270
return (1.1 * bytes_to_copy) * predict_zero_bounded(_copy_cost_per_byte_ms_seq);
271
} else {
272
return bytes_to_copy * predict_zero_bounded(_cost_per_byte_ms_during_cm_seq);
273
}
274
}
275
276
double G1Analytics::predict_object_copy_time_ms(size_t bytes_to_copy, bool during_concurrent_mark) const {
277
if (during_concurrent_mark) {
278
return predict_object_copy_time_ms_during_cm(bytes_to_copy);
279
} else {
280
return bytes_to_copy * predict_zero_bounded(_copy_cost_per_byte_ms_seq);
281
}
282
}
283
284
double G1Analytics::predict_constant_other_time_ms() const {
285
return predict_zero_bounded(_constant_other_time_ms_seq);
286
}
287
288
double G1Analytics::predict_young_other_time_ms(size_t young_num) const {
289
return young_num * predict_zero_bounded(_young_other_cost_per_region_ms_seq);
290
}
291
292
double G1Analytics::predict_non_young_other_time_ms(size_t non_young_num) const {
293
return non_young_num * predict_zero_bounded(_non_young_other_cost_per_region_ms_seq);
294
}
295
296
double G1Analytics::predict_remark_time_ms() const {
297
return predict_zero_bounded(_concurrent_mark_remark_times_ms);
298
}
299
300
double G1Analytics::predict_cleanup_time_ms() const {
301
return predict_zero_bounded(_concurrent_mark_cleanup_times_ms);
302
}
303
304
size_t G1Analytics::predict_rs_length() const {
305
return predict_size(_rs_length_seq) + predict_size(_rs_length_diff_seq);
306
}
307
308
size_t G1Analytics::predict_pending_cards() const {
309
return predict_size(_pending_cards_seq);
310
}
311
312
double G1Analytics::oldest_known_gc_end_time_sec() const {
313
return _recent_prev_end_times_for_all_gcs_sec->oldest();
314
}
315
316
double G1Analytics::most_recent_gc_end_time_sec() const {
317
return _recent_prev_end_times_for_all_gcs_sec->last();
318
}
319
320
void G1Analytics::update_recent_gc_times(double end_time_sec,
321
double pause_time_ms) {
322
_recent_gc_times_ms->add(pause_time_ms);
323
_recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
324
}
325
326
void G1Analytics::report_concurrent_mark_cleanup_times_ms(double ms) {
327
_concurrent_mark_cleanup_times_ms->add(ms);
328
}
329
330