Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/shared/test_gcTimer.cpp
41149 views
1
/*
2
* Copyright (c) 2001, 2018, 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
#include "precompiled.hpp"
25
#include "gc/shared/gcTimer.hpp"
26
#include "utilities/ticks.hpp"
27
#include "unittest.hpp"
28
29
class GCTimerTest {
30
public:
31
static void register_gc_start(GCTimer* const timer, jlong ticks) {
32
timer->register_gc_start(Ticks(ticks));
33
}
34
static void register_gc_end(GCTimer* const timer, jlong ticks) {
35
timer->register_gc_end(Ticks(ticks));
36
}
37
static void register_gc_pause_start(GCTimer* const timer, jlong ticks) {
38
timer->register_gc_pause_start("pause", Ticks(ticks));
39
}
40
static void register_gc_pause_end(GCTimer* const timer, jlong ticks) {
41
timer->register_gc_pause_end(Ticks(ticks));
42
}
43
static void register_gc_concurrent_start(ConcurrentGCTimer* const timer, jlong ticks) {
44
timer->register_gc_concurrent_start("concurrent", Ticks(ticks));
45
}
46
static void register_gc_concurrent_end(ConcurrentGCTimer* const timer, jlong ticks) {
47
timer->register_gc_concurrent_end(Ticks(ticks));
48
}
49
50
static Tickspan duration(jlong ticks) { return Ticks(ticks) - Ticks(0); }
51
};
52
53
static Tickspan duration(jlong ticks) { return GCTimerTest::duration(ticks); }
54
55
TEST(GCTimer, start) {
56
GCTimer gc_timer;
57
GCTimerTest::register_gc_start(&gc_timer, 1);
58
59
EXPECT_EQ(1, gc_timer.gc_start().value());
60
}
61
62
TEST(GCTimer, end) {
63
GCTimer gc_timer;
64
65
GCTimerTest::register_gc_start(&gc_timer, 1);
66
GCTimerTest::register_gc_end(&gc_timer, 2);
67
68
EXPECT_EQ(2, gc_timer.gc_end().value());
69
}
70
71
TEST(GCTimer, pause) {
72
GCTimer gc_timer;
73
74
GCTimerTest::register_gc_start(&gc_timer, 1);
75
GCTimerTest::register_gc_pause_start(&gc_timer, 2);
76
GCTimerTest::register_gc_pause_end(&gc_timer, 4);
77
GCTimerTest::register_gc_end(&gc_timer, 5);
78
79
TimePartitions* partitions = gc_timer.time_partitions();
80
EXPECT_EQ(1, partitions->num_phases());
81
EXPECT_EQ(duration(2), partitions->sum_of_pauses());
82
83
EXPECT_EQ(5, gc_timer.gc_end().value());
84
}
85
86
TEST(ConcurrentGCTimer, pause) {
87
ConcurrentGCTimer gc_timer;
88
89
GCTimerTest::register_gc_start(&gc_timer, 1);
90
GCTimerTest::register_gc_pause_start(&gc_timer, 2);
91
GCTimerTest::register_gc_pause_end(&gc_timer, 4);
92
GCTimerTest::register_gc_end(&gc_timer, 7);
93
94
TimePartitions* partitions = gc_timer.time_partitions();
95
EXPECT_EQ(1, partitions->num_phases());
96
EXPECT_EQ(duration(2), partitions->sum_of_pauses());
97
98
EXPECT_EQ(7, gc_timer.gc_end().value());
99
}
100
101
TEST(ConcurrentGCTimer, concurrent) {
102
ConcurrentGCTimer gc_timer;
103
104
GCTimerTest::register_gc_start(&gc_timer, 1);
105
GCTimerTest::register_gc_concurrent_start(&gc_timer, 2);
106
GCTimerTest::register_gc_concurrent_end(&gc_timer, 4);
107
GCTimerTest::register_gc_end(&gc_timer, 5);
108
109
TimePartitions* partitions = gc_timer.time_partitions();
110
EXPECT_EQ(1, partitions->num_phases());
111
EXPECT_EQ(duration(0), partitions->sum_of_pauses());
112
113
EXPECT_EQ(5, gc_timer.gc_end().value());
114
}
115
116
class TimePartitionsTest {
117
public:
118
119
static void validate_gc_phase(GCPhase* phase, int level, const char* name, const jlong& start, const jlong& end) {
120
EXPECT_EQ(level, phase->level());
121
EXPECT_STREQ(name, phase->name());
122
EXPECT_EQ(start, phase->start().value());
123
EXPECT_EQ(end, phase->end().value());
124
}
125
126
static void validate_pauses(const TimePartitions& time_partitions, const Tickspan& expected_sum_of_pauses, const Tickspan& expected_longest_pause) {
127
EXPECT_EQ(expected_sum_of_pauses, time_partitions.sum_of_pauses());
128
EXPECT_EQ(expected_longest_pause, time_partitions.longest_pause());
129
}
130
static void validate_pauses(const TimePartitions& time_partitions, const Tickspan& expected_pause) {
131
validate_pauses(time_partitions, expected_pause, expected_pause);
132
}
133
static void validate_pauses(const TimePartitions& time_partitions, jlong end, jlong start) {
134
validate_pauses(time_partitions, Ticks(end) - Ticks(start));
135
}
136
static void validate_pauses(const TimePartitions& time_partitions, jlong all_end, jlong all_start, jlong longest_end, jlong longest_start) {
137
validate_pauses(time_partitions, Ticks(all_end) - Ticks(all_start), Ticks(longest_end) - Ticks(longest_start));
138
}
139
140
static void report_gc_phase_start(TimePartitions* const partitions, const char* name, jlong ticks, GCPhase::PhaseType type=GCPhase::PausePhaseType) {
141
partitions->report_gc_phase_start(name, Ticks(ticks), type);
142
}
143
144
static void report_gc_phase_end(TimePartitions* const partitions, jlong ticks) {
145
partitions->report_gc_phase_end(Ticks(ticks));
146
}
147
};
148
149
TEST(TimePartitionPhasesIterator, one_pause) {
150
TimePartitions time_partitions;
151
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);
152
TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);
153
154
TimePartitionPhasesIterator iter(&time_partitions);
155
156
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 8));
157
158
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 8, 2));
159
160
EXPECT_FALSE(iter.has_next()) << "Too many elements";
161
}
162
163
TEST(TimePartitionPhasesIterator, two_pauses) {
164
TimePartitions time_partitions;
165
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase1", 2);
166
TimePartitionsTest::report_gc_phase_end(&time_partitions, 3);
167
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase2", 4);
168
TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);
169
170
TimePartitionPhasesIterator iter(&time_partitions);
171
172
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase1", 2, 3));
173
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase2", 4, 6));
174
175
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 3, 0, 2, 0));
176
177
EXPECT_FALSE(iter.has_next()) << "Too many elements";
178
}
179
180
TEST(TimePartitionPhasesIterator, one_sub_pause_phase) {
181
TimePartitions time_partitions;
182
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);
183
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase", 3);
184
TimePartitionsTest::report_gc_phase_end(&time_partitions, 4);
185
TimePartitionsTest::report_gc_phase_end(&time_partitions, 5);
186
187
TimePartitionPhasesIterator iter(&time_partitions);
188
189
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 5));
190
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase", 3, 4));
191
192
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 3, 0));
193
194
EXPECT_FALSE(iter.has_next()) << "Too many elements";
195
}
196
197
TEST(TimePartitionPhasesIterator, max_nested_pause_phases) {
198
TimePartitions time_partitions;
199
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);
200
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);
201
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 4);
202
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 5);
203
TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);
204
TimePartitionsTest::report_gc_phase_end(&time_partitions, 7);
205
TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);
206
TimePartitionsTest::report_gc_phase_end(&time_partitions, 9);
207
208
TimePartitionPhasesIterator iter(&time_partitions);
209
210
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 9));
211
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8));
212
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase2", 4, 7));
213
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 3, "SubPhase3", 5, 6));
214
215
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 7, 0));
216
217
EXPECT_FALSE(iter.has_next()) << "Too many elements";
218
}
219
220
TEST(TimePartitionPhasesIterator, many_sub_pause_phases) {
221
TimePartitions time_partitions;
222
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);
223
224
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);
225
TimePartitionsTest::report_gc_phase_end(&time_partitions, 4);
226
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 5);
227
TimePartitionsTest::report_gc_phase_end(&time_partitions, 6);
228
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 7);
229
TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);
230
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase4", 9);
231
TimePartitionsTest::report_gc_phase_end(&time_partitions, 10);
232
233
TimePartitionsTest::report_gc_phase_end(&time_partitions, 11);
234
235
TimePartitionPhasesIterator iter(&time_partitions);
236
237
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 11));
238
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 4));
239
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase2", 5, 6));
240
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase3", 7, 8));
241
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase4", 9, 10));
242
243
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 9, 0));
244
245
EXPECT_FALSE(iter.has_next()) << "Too many elements";
246
}
247
248
TEST(TimePartitionPhasesIterator, many_sub_pause_phases2) {
249
TimePartitions time_partitions;
250
TimePartitionsTest::report_gc_phase_start(&time_partitions, "PausePhase", 2);
251
252
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase1", 3);
253
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase11", 4);
254
TimePartitionsTest::report_gc_phase_end(&time_partitions, 5);
255
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase12", 6);
256
TimePartitionsTest::report_gc_phase_end(&time_partitions, 7);
257
TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);
258
259
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase2", 9);
260
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase21", 10);
261
TimePartitionsTest::report_gc_phase_end(&time_partitions, 11);
262
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase22", 12);
263
TimePartitionsTest::report_gc_phase_end(&time_partitions, 13);
264
TimePartitionsTest::report_gc_phase_end(&time_partitions, 14);
265
266
TimePartitionsTest::report_gc_phase_start(&time_partitions, "SubPhase3", 15);
267
TimePartitionsTest::report_gc_phase_end(&time_partitions, 16);
268
269
TimePartitionsTest::report_gc_phase_end(&time_partitions, 17);
270
271
TimePartitionPhasesIterator iter(&time_partitions);
272
273
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "PausePhase", 2, 17));
274
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8));
275
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase11", 4, 5));
276
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase12", 6, 7));
277
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase2", 9, 14));
278
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase21", 10, 11));
279
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 2, "SubPhase22", 12, 13));
280
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 1, "SubPhase3", 15, 16));
281
282
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, 15, 0));
283
284
EXPECT_FALSE(iter.has_next()) << "Too many elements";
285
}
286
287
TEST(TimePartitionPhasesIterator, one_concurrent) {
288
TimePartitions time_partitions;
289
TimePartitionsTest::report_gc_phase_start(&time_partitions, "ConcurrentPhase", 2, GCPhase::ConcurrentPhaseType);
290
TimePartitionsTest::report_gc_phase_end(&time_partitions, 8);
291
292
TimePartitionPhasesIterator iter(&time_partitions);
293
294
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_gc_phase(iter.next(), 0, "ConcurrentPhase", 2, 8));
295
// ConcurrentPhaseType should not affect to both 'sum_of_pauses()' and 'longest_pause()'.
296
EXPECT_NO_FATAL_FAILURE(TimePartitionsTest::validate_pauses(time_partitions, Tickspan()));
297
298
EXPECT_FALSE(iter.has_next()) << "Too many elements";
299
}
300
301