Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestLargePageUseForHeap.java
40942 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.g1;
25
26
/*
27
* @test TestLargePageUseForHeap.java
28
* @summary Test that Java heap is allocated using large pages of the appropriate size if available.
29
* @bug 8221517
30
* @modules java.base/jdk.internal.misc
31
* @library /test/lib
32
* @requires vm.gc.G1
33
* @requires vm.opt.LargePageSizeInBytes == null
34
* @build sun.hotspot.WhiteBox
35
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
36
* @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
37
-XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages gc.g1.TestLargePageUseForHeap
38
*/
39
40
import jdk.test.lib.process.OutputAnalyzer;
41
import jdk.test.lib.process.ProcessTools;
42
import jtreg.SkippedException;
43
import sun.hotspot.WhiteBox;
44
45
public class TestLargePageUseForHeap {
46
static long largePageSize;
47
static long smallPageSize;
48
49
static void checkSize(OutputAnalyzer output, long expectedSize, String pattern) {
50
String pageSizeStr = output.firstMatch(pattern, 1);
51
52
if (pageSizeStr == null) {
53
output.reportDiagnosticSummary();
54
throw new RuntimeException("Match from '" + pattern + "' got 'null' expected: " + expectedSize);
55
}
56
57
long size = parseMemoryString(pageSizeStr);
58
if (size != expectedSize) {
59
output.reportDiagnosticSummary();
60
throw new RuntimeException("Match from '" + pattern + "' got " + size + " expected: " + expectedSize);
61
}
62
}
63
64
static boolean checkLargePageEnabled(OutputAnalyzer output) {
65
String lp = output.firstMatch("Large Page Support: (\\w*)", 1);
66
// Make sure large pages really are enabled.
67
if (lp == null || lp.equals("Disabled")) {
68
return false;
69
}
70
// This message is printed when tried to reserve a memory with large page but it failed.
71
String errorStr = "Reserve regular memory without large pages";
72
String heapPattern = ".*Heap: ";
73
// If errorStr is printed just before heap page log, reservation for Java Heap is failed.
74
String result = output.firstMatch(errorStr + "\n" +
75
"(?:.*Heap address: .*\n)?" // Heap address: 0x00000000f8000000, size: 128 MB, Compressed Oops mode: 32-bit
76
+ heapPattern);
77
if (result != null) {
78
return false;
79
}
80
return true;
81
}
82
83
static void checkHeap(OutputAnalyzer output, long expectedPageSize) throws Exception {
84
checkSize(output, expectedPageSize, "Heap: .*page_size=([^ ]+)");
85
}
86
87
static void testVM(long regionSize) throws Exception {
88
ProcessBuilder pb;
89
// Test with large page enabled.
90
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
91
"-XX:G1HeapRegionSize=" + regionSize,
92
"-Xmx128m",
93
"-Xlog:gc+init,pagesize,gc+heap+coops=debug",
94
"-XX:+UseLargePages",
95
"-version");
96
97
OutputAnalyzer output = new OutputAnalyzer(pb.start());
98
boolean largePageEnabled = checkLargePageEnabled(output);
99
checkHeap(output, largePageEnabled ? largePageSize : smallPageSize);
100
output.shouldHaveExitValue(0);
101
102
// Test with large page disabled.
103
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
104
"-XX:G1HeapRegionSize=" + regionSize,
105
"-Xmx128m",
106
"-Xlog:gc+init,pagesize,gc+heap+coops=debug",
107
"-XX:-UseLargePages",
108
"-version");
109
110
output = new OutputAnalyzer(pb.start());
111
checkHeap(output, smallPageSize);
112
output.shouldHaveExitValue(0);
113
}
114
115
public static void main(String[] args) throws Exception {
116
WhiteBox wb = WhiteBox.getWhiteBox();
117
smallPageSize = wb.getVMPageSize();
118
largePageSize = wb.getVMLargePageSize();
119
120
if (largePageSize == 0) {
121
throw new SkippedException("Large page support does not seem to be available on this platform.");
122
}
123
if (largePageSize == smallPageSize) {
124
throw new SkippedException("Large page support does not seem to be available on this platform."
125
+ "Small and large page size are the same.");
126
}
127
128
// G1HeapRegionSize=1MB
129
testVM(1 * 1024 * 1024);
130
131
// G1HeapRegionSize=2MB
132
testVM(2 * 1024 * 1024);
133
134
// G1HeapRegionSize=8MB
135
testVM(8 * 1024 * 1024);
136
}
137
138
public static long parseMemoryString(String value) {
139
long multiplier = 1;
140
141
if (value.endsWith("B")) {
142
multiplier = 1;
143
} else if (value.endsWith("K")) {
144
multiplier = 1024;
145
} else if (value.endsWith("M")) {
146
multiplier = 1024 * 1024;
147
} else if (value.endsWith("G")) {
148
multiplier = 1024 * 1024 * 1024;
149
} else {
150
throw new IllegalArgumentException("Expected memory string '" + value + "'to end with either of: B, K, M, G");
151
}
152
153
long longValue = Long.parseUnsignedLong(value.substring(0, value.length() - 1));
154
155
return longValue * multiplier;
156
}
157
}
158
159