Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestLargePageUseForAuxMemory.java
40942 views
1
/*
2
* Copyright (c) 2015, 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 TestLargePageUseForAuxMemory.java
28
* @summary Test that auxiliary data structures are allocated using large pages if available.
29
* @bug 8058354 8079208
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 -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages gc.g1.TestLargePageUseForAuxMemory
37
*/
38
39
import java.lang.Math;
40
import jdk.test.lib.process.OutputAnalyzer;
41
import jdk.test.lib.process.ProcessTools;
42
import jdk.test.lib.Asserts;
43
import jdk.test.lib.Platform;
44
import jtreg.SkippedException;
45
import sun.hotspot.WhiteBox;
46
47
public class TestLargePageUseForAuxMemory {
48
static final long HEAP_REGION_SIZE = 1 * 1024 * 1024;
49
static long largePageSize;
50
static long smallPageSize;
51
static long allocGranularity;
52
53
static boolean largePagesEnabled(OutputAnalyzer output) {
54
// The gc+init logging includes information about large pages.
55
String lp = output.firstMatch("Large Page Support: (\\w*)", 1);
56
return lp != null && lp.equals("Enabled");
57
}
58
59
static boolean largePagesAllocationFailure(OutputAnalyzer output, String pattern) {
60
// Check if there is a large page failure associated with the data structure
61
// being checked. In case of a large page allocation failure the output will
62
// include logs like this for the affected data structure:
63
// [0.048s][debug][gc,heap,coops] Reserve regular memory without large pages
64
// [0.048s][info ][pagesize ] Next Bitmap: ... page_size=4K ...
65
//
66
// The pattern passed in should match the second line.
67
String failureMatch = output.firstMatch("Reserve regular memory without large pages\\n.*" + pattern, 1);
68
if (failureMatch != null) {
69
return true;
70
}
71
return false;
72
}
73
74
static void checkSize(OutputAnalyzer output, long expectedSize, String pattern) {
75
// First check the output for any large page allocation failure associated with
76
// the checked data structure. If we detect a failure then expect small pages.
77
if (largePagesAllocationFailure(output, pattern)) {
78
// This should only happen when we are expecting large pages
79
if (expectedSize == smallPageSize) {
80
throw new RuntimeException("Expected small page size when large page failure was detected");
81
}
82
expectedSize = smallPageSize;
83
}
84
85
// Now check what page size is traced.
86
String pageSizeStr = output.firstMatch(pattern, 1);
87
if (pageSizeStr == null) {
88
output.reportDiagnosticSummary();
89
throw new RuntimeException("Match from '" + pattern + "' got 'null' expected: " + expectedSize);
90
}
91
92
long size = parseMemoryString(pageSizeStr);
93
if (size != expectedSize) {
94
output.reportDiagnosticSummary();
95
throw new RuntimeException("Match from '" + pattern + "' got " + size + " expected: " + expectedSize);
96
}
97
}
98
99
static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception {
100
checkSize(output, expectedPageSize, "Block Offset Table: .*page_size=([^ ]+)");
101
checkSize(output, expectedPageSize, "Card Counts Table: .*page_size=([^ ]+)");
102
}
103
104
static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception {
105
checkSize(output, expectedPageSize, "Prev Bitmap: .*page_size=([^ ]+)");
106
checkSize(output, expectedPageSize, "Next Bitmap: .*page_size=([^ ]+)");
107
}
108
109
static void testVM(String what, long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {
110
System.out.println(what + " heapsize " + heapsize + " card table should use large pages " + cardsShouldUseLargePages + " " +
111
"bitmaps should use large pages " + bitmapShouldUseLargePages);
112
ProcessBuilder pb;
113
// Test with large page enabled.
114
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
115
"-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
116
"-Xmx" + heapsize,
117
"-Xlog:pagesize,gc+init,gc+heap+coops=debug",
118
"-XX:+UseLargePages",
119
"-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds
120
"-XX:ObjectAlignmentInBytes=8",
121
"-version");
122
123
OutputAnalyzer output = new OutputAnalyzer(pb.start());
124
// Only expect large page size if large pages are enabled.
125
if (largePagesEnabled(output)) {
126
checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize));
127
checkBitmaps(output, (bitmapShouldUseLargePages ? largePageSize : smallPageSize));
128
} else {
129
checkSmallTables(output, smallPageSize);
130
checkBitmaps(output, smallPageSize);
131
}
132
output.shouldHaveExitValue(0);
133
134
// Test with large page disabled.
135
pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
136
"-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
137
"-Xmx" + heapsize,
138
"-Xlog:pagesize",
139
"-XX:-UseLargePages",
140
"-XX:+IgnoreUnrecognizedVMOptions", // there is no ObjectAlignmentInBytes in 32 bit builds
141
"-XX:ObjectAlignmentInBytes=8",
142
"-version");
143
144
output = new OutputAnalyzer(pb.start());
145
checkSmallTables(output, smallPageSize);
146
checkBitmaps(output, smallPageSize);
147
output.shouldHaveExitValue(0);
148
}
149
150
private static long gcd(long x, long y) {
151
while (x > 0) {
152
long t = x;
153
x = y % x;
154
y = t;
155
}
156
return y;
157
}
158
159
private static long lcm(long x, long y) {
160
return x * (y / gcd(x, y));
161
}
162
163
public static void main(String[] args) throws Exception {
164
// Size that a single card covers.
165
final int cardSize = 512;
166
WhiteBox wb = WhiteBox.getWhiteBox();
167
smallPageSize = wb.getVMPageSize();
168
largePageSize = wb.getVMLargePageSize();
169
allocGranularity = wb.getVMAllocationGranularity();
170
final long heapAlignment = lcm(cardSize * smallPageSize, largePageSize);
171
172
if (largePageSize == 0) {
173
throw new SkippedException("Large page support does not seem to be available on this platform.");
174
}
175
if (largePageSize == smallPageSize) {
176
throw new SkippedException("Large page support does not seem to be available on this platform."
177
+ "Small and large page size are the same.");
178
}
179
180
// To get large pages for the card table etc. we need at least a 1G heap (with 4k page size).
181
// 32 bit systems will have problems reserving such an amount of contiguous space, so skip the
182
// test there.
183
if (!Platform.is32bit()) {
184
final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;
185
final long heapSizeDiffForCardTable = Math.max(Math.max(allocGranularity * cardSize, HEAP_REGION_SIZE), largePageSize);
186
187
Asserts.assertGT(heapSizeForCardTableUsingLargePages, heapSizeDiffForCardTable,
188
"To test we would require to use an invalid heap size");
189
testVM("case1: card table and bitmap use large pages (barely)", heapSizeForCardTableUsingLargePages, true, true);
190
testVM("case2: card table and bitmap use large pages (extra slack)", heapSizeForCardTableUsingLargePages + heapSizeDiffForCardTable, true, true);
191
testVM("case3: only bitmap uses large pages (barely not)", heapSizeForCardTableUsingLargePages - heapSizeDiffForCardTable, false, true);
192
}
193
194
// Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test
195
// everywhere.
196
final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte
197
final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;
198
final long heapSizeDiffForBitmap = Math.max(Math.max(allocGranularity * bitmapTranslationFactor, HEAP_REGION_SIZE),
199
Math.max(largePageSize, heapAlignment));
200
201
Asserts.assertGT(heapSizeForBitmapUsingLargePages, heapSizeDiffForBitmap,
202
"To test we would require to use an invalid heap size");
203
204
testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
205
testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
206
testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
207
}
208
209
public static long parseMemoryString(String value) {
210
long multiplier = 1;
211
212
if (value.endsWith("B")) {
213
multiplier = 1;
214
} else if (value.endsWith("K")) {
215
multiplier = 1024;
216
} else if (value.endsWith("M")) {
217
multiplier = 1024 * 1024;
218
} else if (value.endsWith("G")) {
219
multiplier = 1024 * 1024 * 1024;
220
} else {
221
throw new IllegalArgumentException("Expected memory string '" + value + "'to end with either of: B, K, M, G");
222
}
223
224
long longValue = Long.parseUnsignedLong(value.substring(0, value.length() - 1));
225
226
return longValue * multiplier;
227
}
228
}
229
230