Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/Metaspace/MaxMetaspaceSizeEnvVarTest.java
32284 views
1
/*
2
* Copyright (c) 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
* @test
26
* @bug 8260349
27
* @summary test that setting via the env-var and options file shows up as expected
28
* @library /testlibrary
29
* @run driver MaxMetaspaceSizeEnvVarTest
30
*/
31
32
import java.io.PrintWriter;
33
import java.lang.management.ManagementFactory;
34
import java.lang.management.MemoryPoolMXBean;
35
import java.util.NoSuchElementException;
36
37
import com.oracle.java.testlibrary.ProcessTools;
38
import com.oracle.java.testlibrary.OutputAnalyzer;
39
40
public class MaxMetaspaceSizeEnvVarTest {
41
42
// This is the test class we exec, passing the MaxMetaspaceSize flag
43
// by different mechanisms.
44
static class Main {
45
public static void main(String[] args) throws Exception {
46
long expected = Long.parseLong(args[0]);
47
MemoryPoolMXBean metaspaceMemoryPool =
48
ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)
49
.stream()
50
.filter(pool -> "Metaspace".equals(pool.getName()))
51
.findFirst()
52
.orElseThrow(() -> new NoSuchElementException("No value present"));
53
long max = metaspaceMemoryPool.getUsage().getMax();
54
System.out.println("Metaspace max usage is " + max);
55
if (max != expected) {
56
throw new RuntimeException("Metaspace max " + max +
57
" != " + expected);
58
}
59
}
60
}
61
62
static void report(String msg) {
63
System.out.println(msg);
64
System.err.println(msg);
65
}
66
67
public static void main(String... args) throws Exception {
68
final String max = String.valueOf(9 * 1024 * 1024); // 9 MB
69
final String flagRaw = "MaxMetaspaceSize=" + max;
70
final String flag = "-XX:" + flagRaw;
71
final String main = "MaxMetaspaceSizeEnvVarTest$Main";
72
73
ProcessBuilder pb = null;
74
OutputAnalyzer output = null;
75
76
int test = 1;
77
report("Test " + test + ": flag not set");
78
79
Main.main(new String[] { "-1" }); // -1 == undefined size
80
report("------ end Test " + test);
81
test++;
82
83
report("Test " + test + ": normal command-line flag");
84
pb = ProcessTools.createJavaProcessBuilder(flag, main, max);
85
output = new OutputAnalyzer(pb.start());
86
output.shouldHaveExitValue(0);
87
output.reportDiagnosticSummary();
88
report("------ end Test " + test);
89
test++;
90
91
String[] envVars = {
92
"_JAVA_OPTIONS",
93
"JAVA_TOOL_OPTIONS"
94
};
95
96
for (String envVar : envVars) {
97
report("Test " + test + ": " + envVar + " env-var");
98
pb = ProcessTools.createJavaProcessBuilder(main, max);
99
pb.environment().put(envVar, flag);
100
output = new OutputAnalyzer(pb.start());
101
output.shouldHaveExitValue(0);
102
output.reportDiagnosticSummary();
103
report("------ end Test " + test);
104
test++;
105
}
106
107
report("Test " + test + ": .hotspotrc file");
108
final String rcFile = ".hotspotrc";
109
final String rcFileFlag = "-XX:Flags=" + rcFile;
110
111
PrintWriter pw = new PrintWriter(rcFile);
112
pw.println(flagRaw);
113
pw.close();
114
pb = ProcessTools.createJavaProcessBuilder(rcFileFlag, main, max);
115
output = new OutputAnalyzer(pb.start());
116
output.shouldHaveExitValue(0);
117
output.reportDiagnosticSummary();
118
report("------ end Test " + test);
119
}
120
}
121
122