Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestEagerReclaimHumongousRegionsLog.java
40942 views
1
/*
2
* Copyright (c) 2017, 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 TestEagerReclaimHumongousRegionsLog
28
* @summary Check that G1 reports humongous eager reclaim statistics correctly.
29
* @requires vm.gc.G1
30
* @library /test/lib
31
* @modules java.base/jdk.internal.misc
32
* java.management
33
* @build sun.hotspot.WhiteBox
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @run driver gc.g1.TestEagerReclaimHumongousRegionsLog
36
*/
37
38
import sun.hotspot.WhiteBox;
39
40
import java.util.Arrays;
41
import jdk.test.lib.Asserts;
42
43
import jdk.test.lib.process.OutputAnalyzer;
44
import jdk.test.lib.process.ProcessTools;
45
46
public class TestEagerReclaimHumongousRegionsLog {
47
48
private static final String LogSeparator = ": ";
49
50
static final String SumSeparator = "Sum: ";
51
52
private static String getSumValue(String s) {
53
return s.substring(s.indexOf(SumSeparator) + SumSeparator.length(), s.indexOf(", Workers"));
54
}
55
56
public static void runTest() throws Exception {
57
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
58
"-Xbootclasspath/a:.",
59
"-XX:+UnlockExperimentalVMOptions",
60
"-XX:+UnlockDiagnosticVMOptions",
61
"-XX:+WhiteBoxAPI",
62
"-XX:+UseG1GC",
63
"-XX:G1HeapRegionSize=1M",
64
"-Xms128M",
65
"-Xmx128M",
66
"-Xlog:gc+phases=trace,gc+heap=info",
67
GCTest.class.getName());
68
OutputAnalyzer output = new OutputAnalyzer(pb.start());
69
70
output.shouldHaveExitValue(0);
71
72
System.out.println(output.getStdout());
73
74
// This gives an array of lines containing eager reclaim of humongous regions
75
// log messages contents after the ":" in the following order for every GC:
76
// Region Register: a.ams
77
// Eagerly Reclaim Humonguous Objects b.cms
78
// Humongous Total: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: c, Workers: 1
79
// Humongous Candidate: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: d, Workers: 1
80
// Humongous Reclaimed: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: e, Workers: 1
81
// Humongous Regions: f->g
82
83
String[] lines = Arrays.stream(output.getStdout().split("\\R"))
84
.filter(s -> (s.contains("Humongous") || s.contains("Region Register"))).map(s -> s.substring(s.indexOf(LogSeparator) + LogSeparator.length()))
85
.toArray(String[]::new);
86
87
Asserts.assertTrue(lines.length % 6 == 0, "There seems to be an unexpected amount of log messages (total: " + lines.length + ") per GC");
88
89
for (int i = 0; i < lines.length; i += 6) {
90
int total = Integer.parseInt(getSumValue(lines[i + 2]));
91
int candidate = Integer.parseInt(getSumValue(lines[i + 3]));
92
int reclaimed = Integer.parseInt(getSumValue(lines[i + 4]));
93
94
int before = Integer.parseInt(lines[i + 5].substring(0, 1));
95
int after = Integer.parseInt(lines[i + 5].substring(3, 4));
96
System.out.println("total " + total + " candidate " + candidate + " reclaimed " + reclaimed + " before " + before + " after " + after);
97
98
Asserts.assertEQ(total, candidate, "Not all humonguous objects are candidates");
99
Asserts.assertLTE(reclaimed, candidate, "The number of reclaimed objects must be less or equal than the number of candidates");
100
101
if (reclaimed > 0) {
102
Asserts.assertLT(after, before, "Number of regions after must be smaller than before.");
103
Asserts.assertEQ(reclaimed, candidate, "Must have reclaimed all candidates.");
104
Asserts.assertGT((before - after), reclaimed, "Number of regions reclaimed (" + (before - after) +
105
") must be larger than number of objects reclaimed (" + reclaimed + ")");
106
}
107
}
108
}
109
110
public static void main(String[] args) throws Exception {
111
runTest();
112
}
113
114
static class GCTest {
115
private static final WhiteBox WB = WhiteBox.getWhiteBox();
116
117
public static Object holder;
118
119
public static void main(String [] args) {
120
// Create a humongous objects spanning multiple regions so that the difference
121
// between number of humongous objects reclaimed and number of regions reclaimed
122
// is apparent.
123
holder = new byte[4 * 1024 * 1024];
124
WB.youngGC();
125
System.out.println(holder);
126
holder = null;
127
WB.youngGC();
128
}
129
}
130
}
131
132
133