Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestGCLogMessages.java
40942 views
1
/*
2
* Copyright (c) 2014, 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
package gc.g1;
25
26
/*
27
* @test TestGCLogMessages
28
* @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962 8069330 8076463 8150630 8160055 8177059 8166191
29
* @summary Ensure the output for a minor GC with G1
30
* includes the expected necessary messages.
31
* @requires vm.gc.G1
32
* @library /test/lib
33
* @modules java.base/jdk.internal.misc
34
* java.management
35
* @build sun.hotspot.WhiteBox
36
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
37
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
38
* gc.g1.TestGCLogMessages
39
*/
40
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.Platform;
43
import jdk.test.lib.process.ProcessTools;
44
import sun.hotspot.code.Compiler;
45
46
public class TestGCLogMessages {
47
48
private enum Level {
49
OFF(""),
50
INFO("info"),
51
DEBUG("debug"),
52
TRACE("trace");
53
54
private String logName;
55
56
Level(String logName) {
57
this.logName = logName;
58
}
59
60
public boolean lessThan(Level other) {
61
return this.compareTo(other) < 0;
62
}
63
64
public String toString() {
65
return logName;
66
}
67
}
68
69
private class LogMessageWithLevel {
70
String message;
71
Level level;
72
73
public LogMessageWithLevel(String message, Level level) {
74
this.message = message;
75
this.level = level;
76
}
77
78
public boolean isAvailable() {
79
return true;
80
}
81
};
82
83
private class LogMessageWithLevelC2OrJVMCIOnly extends LogMessageWithLevel {
84
public LogMessageWithLevelC2OrJVMCIOnly(String message, Level level) {
85
super(message, level);
86
}
87
88
public boolean isAvailable() {
89
return Compiler.isC2OrJVMCIIncluded();
90
}
91
}
92
93
private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {
94
new LogMessageWithLevel("Pre Evacuate Collection Set", Level.INFO),
95
new LogMessageWithLevel("Evacuate Collection Set", Level.INFO),
96
new LogMessageWithLevel("Post Evacuate Collection Set", Level.INFO),
97
new LogMessageWithLevel("Other", Level.INFO),
98
99
// Merge Heap Roots
100
new LogMessageWithLevel("Merge Heap Roots", Level.INFO),
101
new LogMessageWithLevel("Prepare Merge Heap Roots", Level.DEBUG),
102
new LogMessageWithLevel("Eager Reclaim", Level.DEBUG),
103
new LogMessageWithLevel("Remembered Sets", Level.DEBUG),
104
new LogMessageWithLevel("Merged Sparse", Level.DEBUG),
105
new LogMessageWithLevel("Merged Fine", Level.DEBUG),
106
new LogMessageWithLevel("Merged Coarse", Level.DEBUG),
107
new LogMessageWithLevel("Hot Card Cache", Level.DEBUG),
108
new LogMessageWithLevel("Log Buffers", Level.DEBUG),
109
new LogMessageWithLevel("Dirty Cards", Level.DEBUG),
110
new LogMessageWithLevel("Skipped Cards", Level.DEBUG),
111
// Scan Heap Roots
112
new LogMessageWithLevel("Scan Heap Roots", Level.DEBUG),
113
new LogMessageWithLevel("Scanned Cards", Level.DEBUG),
114
new LogMessageWithLevel("Scanned Blocks", Level.DEBUG),
115
new LogMessageWithLevel("Claimed Chunks", Level.DEBUG),
116
// Code Roots Scan
117
new LogMessageWithLevel("Code Root Scan", Level.DEBUG),
118
// Object Copy
119
new LogMessageWithLevel("Object Copy", Level.DEBUG),
120
new LogMessageWithLevel("Copied Bytes", Level.DEBUG),
121
new LogMessageWithLevel("LAB Waste", Level.DEBUG),
122
new LogMessageWithLevel("LAB Undo Waste", Level.DEBUG),
123
// Ext Root Scan
124
new LogMessageWithLevel("Thread Roots", Level.TRACE),
125
new LogMessageWithLevel("CLDG Roots", Level.TRACE),
126
new LogMessageWithLevel("CM RefProcessor Roots", Level.TRACE),
127
new LogMessageWithLevel("JNI Global Roots", Level.TRACE),
128
new LogMessageWithLevel("VM Global Roots", Level.TRACE),
129
// Redirty Cards
130
new LogMessageWithLevel("Redirty Logged Cards", Level.DEBUG),
131
new LogMessageWithLevel("Redirtied Cards", Level.DEBUG),
132
// Misc Top-level
133
new LogMessageWithLevel("Purge Code Roots", Level.DEBUG),
134
new LogMessageWithLevel("Expand Heap After Collection", Level.DEBUG),
135
new LogMessageWithLevel("Region Register", Level.DEBUG),
136
new LogMessageWithLevel("Prepare Heap Roots", Level.DEBUG),
137
new LogMessageWithLevel("Concatenate Dirty Card Logs", Level.DEBUG),
138
// Free CSet
139
new LogMessageWithLevel("Free Collection Set", Level.DEBUG),
140
new LogMessageWithLevel("Serial Free Collection Set", Level.TRACE),
141
new LogMessageWithLevel("Young Free Collection Set", Level.TRACE),
142
new LogMessageWithLevel("Non-Young Free Collection Set", Level.TRACE),
143
// Rebuild Free List
144
new LogMessageWithLevel("Rebuild Free List", Level.DEBUG),
145
new LogMessageWithLevel("Serial Rebuild Free List", Level.TRACE),
146
new LogMessageWithLevel("Parallel Rebuild Free List", Level.TRACE),
147
148
// Merge PSS
149
new LogMessageWithLevel("Merge Per-Thread State", Level.DEBUG),
150
// TLAB handling
151
new LogMessageWithLevel("Prepare TLABs", Level.DEBUG),
152
new LogMessageWithLevel("Resize TLABs", Level.DEBUG),
153
// Reference Processing
154
new LogMessageWithLevel("Reference Processing", Level.DEBUG),
155
// VM internal reference processing
156
new LogMessageWithLevel("Weak Processing", Level.DEBUG),
157
new LogMessageWithLevel("JNI Weak", Level.DEBUG),
158
new LogMessageWithLevel("StringTable Weak", Level.DEBUG),
159
new LogMessageWithLevel("ResolvedMethodTable Weak", Level.DEBUG),
160
new LogMessageWithLevel("VM Weak", Level.DEBUG),
161
162
new LogMessageWithLevelC2OrJVMCIOnly("Update Derived Pointers", Level.DEBUG),
163
new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
164
};
165
166
void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
167
for (LogMessageWithLevel l : messages) {
168
if (level.lessThan(l.level) || !l.isAvailable()) {
169
output.shouldNotContain(l.message);
170
} else {
171
output.shouldMatch("\\[" + l.level + ".*" + l.message);
172
}
173
}
174
}
175
176
public static void main(String[] args) throws Exception {
177
new TestGCLogMessages().testNormalLogs();
178
new TestGCLogMessages().testConcurrentRefinementLogs();
179
if (Platform.isDebugBuild()) {
180
new TestGCLogMessages().testWithEvacuationFailureLogs();
181
}
182
new TestGCLogMessages().testWithConcurrentStart();
183
new TestGCLogMessages().testExpandHeap();
184
}
185
186
private void testNormalLogs() throws Exception {
187
188
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
189
"-Xmx10M",
190
GCTest.class.getName());
191
192
OutputAnalyzer output = new OutputAnalyzer(pb.start());
193
checkMessagesAtLevel(output, allLogMessages, Level.OFF);
194
output.shouldHaveExitValue(0);
195
196
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
197
"-Xmx10M",
198
"-Xlog:gc+phases=debug",
199
GCTest.class.getName());
200
201
output = new OutputAnalyzer(pb.start());
202
checkMessagesAtLevel(output, allLogMessages, Level.DEBUG);
203
204
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
205
"-Xmx10M",
206
"-Xlog:gc+phases=trace",
207
GCTest.class.getName());
208
209
output = new OutputAnalyzer(pb.start());
210
checkMessagesAtLevel(output, allLogMessages, Level.TRACE);
211
output.shouldHaveExitValue(0);
212
}
213
214
LogMessageWithLevel concRefineMessages[] = new LogMessageWithLevel[] {
215
new LogMessageWithLevel("Mutator refinement: ", Level.DEBUG),
216
new LogMessageWithLevel("Concurrent refinement: ", Level.DEBUG),
217
new LogMessageWithLevel("Total refinement: ", Level.DEBUG),
218
// "Concurrent refinement rate" optionally printed if any.
219
// "Generate dirty cards rate" optionally printed if any.
220
};
221
222
private void testConcurrentRefinementLogs() throws Exception {
223
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
224
"-Xmx10M",
225
"-Xlog:gc+refine+stats=debug",
226
GCTest.class.getName());
227
OutputAnalyzer output = new OutputAnalyzer(pb.start());
228
checkMessagesAtLevel(output, concRefineMessages, Level.DEBUG);
229
}
230
231
LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
232
new LogMessageWithLevel("Recalculate Used Memory", Level.DEBUG),
233
new LogMessageWithLevel("Restore Preserved Marks", Level.DEBUG),
234
new LogMessageWithLevel("Remove Self Forwards", Level.DEBUG),
235
};
236
237
private void testWithEvacuationFailureLogs() throws Exception {
238
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
239
"-Xmx32M",
240
"-Xmn16M",
241
"-XX:+G1EvacuationFailureALot",
242
"-XX:G1EvacuationFailureALotCount=100",
243
"-XX:G1EvacuationFailureALotInterval=1",
244
"-Xlog:gc+phases=debug",
245
GCTestWithEvacuationFailure.class.getName());
246
247
OutputAnalyzer output = new OutputAnalyzer(pb.start());
248
checkMessagesAtLevel(output, exhFailureMessages, Level.DEBUG);
249
output.shouldHaveExitValue(0);
250
251
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
252
"-Xmx32M",
253
"-Xmn16M",
254
"-Xms32M",
255
"-Xlog:gc+phases=trace",
256
GCTestWithEvacuationFailure.class.getName());
257
258
output = new OutputAnalyzer(pb.start());
259
checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);
260
output.shouldHaveExitValue(0);
261
}
262
263
private void testWithConcurrentStart() throws Exception {
264
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
265
"-Xmx10M",
266
"-Xbootclasspath/a:.",
267
"-Xlog:gc*=debug",
268
"-XX:+UnlockDiagnosticVMOptions",
269
"-XX:+WhiteBoxAPI",
270
GCTestWithConcurrentStart.class.getName());
271
272
OutputAnalyzer output = new OutputAnalyzer(pb.start());
273
output.shouldContain("Clear Claimed Marks");
274
output.shouldHaveExitValue(0);
275
}
276
277
private void testExpandHeap() throws Exception {
278
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
279
"-Xmx10M",
280
"-Xbootclasspath/a:.",
281
"-Xlog:gc+ergo+heap=debug",
282
"-XX:+UnlockDiagnosticVMOptions",
283
"-XX:+WhiteBoxAPI",
284
GCTest.class.getName());
285
286
OutputAnalyzer output = new OutputAnalyzer(pb.start());
287
output.shouldContain("Expand the heap. requested expansion amount: ");
288
output.shouldContain("B expansion amount: ");
289
output.shouldHaveExitValue(0);
290
}
291
292
293
static class GCTest {
294
private static byte[] garbage;
295
public static void main(String [] args) {
296
System.out.println("Creating garbage");
297
// create 128MB of garbage. This should result in at least one GC
298
for (int i = 0; i < 1024; i++) {
299
garbage = new byte[128 * 1024];
300
}
301
System.out.println("Done");
302
}
303
}
304
305
static class GCTestWithEvacuationFailure {
306
private static byte[] garbage;
307
private static byte[] largeObject;
308
private static Object[] holder = new Object[200]; // Must be larger than G1EvacuationFailureALotCount
309
310
public static void main(String [] args) {
311
largeObject = new byte[16*1024*1024];
312
System.out.println("Creating garbage");
313
// Create 16 MB of garbage. This should result in at least one GC,
314
// (Heap size is 32M, we use 17MB for the large object above)
315
// which is larger than G1EvacuationFailureALotInterval.
316
for (int i = 0; i < 16 * 1024; i++) {
317
holder[i % holder.length] = new byte[1024];
318
}
319
System.out.println("Done");
320
}
321
}
322
323
static class GCTestWithConcurrentStart {
324
public static void main(String [] args) {
325
sun.hotspot.WhiteBox WB = sun.hotspot.WhiteBox.getWhiteBox();
326
WB.g1StartConcMarkCycle();
327
}
328
}
329
330
}
331
332
333