Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/arguments/TestMaxRAMFlags.java
40948 views
1
/*
2
* Copyright (c) 2019, 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.arguments;
25
26
/*
27
* @test TestMaxRAMFlags
28
* @bug 8222252
29
* @summary Verify correct MaxHeapSize and UseCompressedOops when MaxRAM and MaxRAMPercentage
30
* are specified.
31
* @library /test/lib
32
* @library /
33
* @requires vm.bits == "64"
34
* @modules java.base/jdk.internal.misc
35
* java.management
36
* @build sun.hotspot.WhiteBox
37
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
38
* @run driver gc.arguments.TestMaxRAMFlags
39
* @author [email protected]
40
*/
41
42
import java.util.regex.Matcher;
43
import java.util.regex.Pattern;
44
45
import java.util.ArrayList;
46
import java.util.Arrays;
47
48
import jdk.test.lib.process.OutputAnalyzer;
49
import jdk.test.lib.process.ProcessTools;
50
51
public class TestMaxRAMFlags {
52
53
private static void checkMaxRAMSize(long maxram, int maxrampercent, boolean forcecoop, long expectheap, boolean expectcoop) throws Exception {
54
55
ArrayList<String> args = new ArrayList<String>();
56
args.add("-XX:MaxRAM=" + maxram);
57
args.add("-XX:MaxRAMPercentage=" + maxrampercent);
58
if (forcecoop) {
59
args.add("-XX:+UseCompressedOops");
60
}
61
62
args.add("-XX:+PrintFlagsFinal");
63
args.add("-version");
64
65
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(args);
66
OutputAnalyzer output = new OutputAnalyzer(pb.start());
67
output.shouldHaveExitValue(0);
68
String stdout = output.getStdout();
69
70
long actualheap = new Long(getFlagValue("MaxHeapSize", stdout)).longValue();
71
if (actualheap != expectheap) {
72
throw new RuntimeException("MaxHeapSize value set to " + actualheap +
73
", expected " + expectheap + " when running with the following flags: " + Arrays.asList(args).toString());
74
}
75
76
boolean actualcoop = getFlagBoolValue("UseCompressedOops", stdout);
77
if (actualcoop != expectcoop) {
78
throw new RuntimeException("UseCompressedOops set to " + actualcoop +
79
", expected " + expectcoop + " when running with the following flags: " + Arrays.asList(args).toString());
80
}
81
}
82
83
private static long getHeapBaseMinAddress() throws Exception {
84
ArrayList<String> args = new ArrayList<String>();
85
args.add("-XX:+PrintFlagsFinal");
86
args.add("-version");
87
88
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(args);
89
OutputAnalyzer output = new OutputAnalyzer(pb.start());
90
output.shouldHaveExitValue(0);
91
String stdout = output.getStdout();
92
return (new Long(getFlagValue("HeapBaseMinAddress", stdout)).longValue());
93
}
94
95
private static String getFlagValue(String flag, String where) {
96
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
97
if (!m.find()) {
98
throw new RuntimeException("Could not find value for flag " + flag + " in output string");
99
}
100
String match = m.group();
101
return match.substring(match.lastIndexOf(" ") + 1, match.length());
102
}
103
104
private static boolean getFlagBoolValue(String flag, String where) {
105
Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
106
if (!m.find()) {
107
throw new RuntimeException("Could not find value for flag " + flag + " in output string");
108
}
109
return m.group(1).equals("true");
110
}
111
112
public static void main(String args[]) throws Exception {
113
// Tests
114
// 1. Verify that MaxRAMPercentage overrides UseCompressedOops Ergo
115
// 2. Verify that UseCompressedOops forces compressed oops limit even
116
// when other flags are specified.
117
118
long oneG = 1L * 1024L * 1024L * 1024L;
119
120
// Hotspot startup logic reduces MaxHeapForCompressedOops by HeapBaseMinAddress
121
// in order to get zero based compressed oops offsets.
122
long heapbaseminaddr = getHeapBaseMinAddress();
123
long maxcoopheap = TestUseCompressedOopsErgoTools.getMaxHeapForCompressedOops(new String [0]) - heapbaseminaddr;
124
125
// Args: MaxRAM , MaxRAMPercentage, forcecoop, expect heap, expect coop
126
checkMaxRAMSize(maxcoopheap - oneG, 100, false, maxcoopheap - oneG, true);
127
checkMaxRAMSize(maxcoopheap + oneG, 100, false, maxcoopheap + oneG, false);
128
checkMaxRAMSize(maxcoopheap + oneG, 100, true, maxcoopheap, true);
129
}
130
}
131
132