Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/logging/TestMetaSpaceLog.java
40942 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
package gc.logging;
26
27
import java.io.File;
28
import java.net.URL;
29
import java.net.URLClassLoader;
30
import java.util.regex.Pattern;
31
import java.util.regex.Matcher;
32
33
import jdk.test.lib.Asserts;
34
import jdk.test.lib.process.OutputAnalyzer;
35
import jdk.test.lib.process.ProcessTools;
36
import sun.hotspot.WhiteBox;
37
38
/*
39
* @test TestMetaSpaceLog
40
* @bug 8211123
41
* @summary Ensure that the Metaspace is updated in the log
42
* @library /test/lib
43
* @modules java.base/jdk.internal.misc
44
* java.management
45
* @requires vm.gc != "Epsilon"
46
* @requires vm.gc != "Z"
47
* @requires os.maxMemory >= 2G
48
*
49
* @compile TestMetaSpaceLog.java
50
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
51
* @run driver gc.logging.TestMetaSpaceLog
52
*/
53
54
public class TestMetaSpaceLog {
55
private static Pattern metaSpaceRegexp;
56
57
static {
58
// Do this once here.
59
// Scan for Metaspace update notices as part of the GC log, e.g. in this form:
60
// [gc,metaspace ] GC(0) Metaspace: 11895K(14208K)->11895K(14208K) NonClass: 10552K(12544K)->10552K(12544K) Class: 1343K(1664K)->1343K(1664K)
61
metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*");
62
}
63
64
public static void main(String[] args) throws Exception {
65
testMetaSpaceUpdate();
66
}
67
68
private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) {
69
// At least one metaspace line from GC should show GC being collected.
70
boolean foundCollectedMetaSpace = output.asLines().stream()
71
.filter(s -> s.contains("[gc,metaspace"))
72
.anyMatch(TestMetaSpaceLog::check);
73
Asserts.assertTrue(foundCollectedMetaSpace);
74
}
75
76
private static boolean check(String line) {
77
Matcher m = metaSpaceRegexp.matcher(line);
78
if (m.matches()) {
79
// Numbers for Metaspace occupation should grow.
80
long before = Long.parseLong(m.group(1));
81
long after = Long.parseLong(m.group(2));
82
return before > after;
83
}
84
return false;
85
}
86
87
private static void testMetaSpaceUpdate() throws Exception {
88
// Propagate test.src for the jar file.
89
String testSrc= "-Dtest.src=" + System.getProperty("test.src", ".");
90
91
ProcessBuilder pb =
92
ProcessTools.createTestJvm(
93
"-Xlog:gc*",
94
"-Xbootclasspath/a:.",
95
"-XX:+UnlockDiagnosticVMOptions",
96
"-XX:+WhiteBoxAPI",
97
"-Xmx1000M",
98
"-Xms1000M",
99
testSrc, StressMetaSpace.class.getName());
100
101
OutputAnalyzer output = null;
102
try {
103
output = new OutputAnalyzer(pb.start());
104
verifyContainsMetaSpaceUpdate(output);
105
} catch (Exception e) {
106
// For error diagnosis: print and throw.
107
e.printStackTrace();
108
output.reportDiagnosticSummary();
109
throw e;
110
}
111
}
112
113
static class StressMetaSpace {
114
private static URL[] urls = new URL[1];
115
116
static {
117
try {
118
File jarFile = new File(System.getProperty("test.src") + "/testcases.jar");
119
urls[0] = jarFile.toURI().toURL();
120
} catch (Exception e) {
121
e.printStackTrace();
122
}
123
}
124
125
public static void main(String args[]) {
126
WhiteBox wb = WhiteBox.getWhiteBox();
127
for(int i = 0; i < 10000; i++) {
128
loadClass(wb);
129
}
130
wb.fullGC();
131
}
132
133
public static void loadClass(WhiteBox wb) {
134
try {
135
URLClassLoader ucl = new URLClassLoader(urls);
136
Class.forName("case00", false, ucl);
137
} catch (Exception e) {
138
e.printStackTrace();
139
}
140
}
141
}
142
}
143
144