29 * @requires vm.flagless
30 * @comment Testing compressed class pointers without compressed oops is not possible
31 * on MacOS because the heap is given an arbitrary address that occasionally
32 * collides with where we would ideally have placed the compressed class space.
33 * @requires os.family != "mac"
34 * @library /test/lib
35 * @modules java.base/jdk.internal.misc
36 * java.management
37 * @run driver CompressedClassPointers
38 */
39
40 import jdk.test.lib.Platform;
41 import jdk.test.lib.process.ProcessTools;
42 import jdk.test.lib.process.OutputAnalyzer;
43 import jtreg.SkippedException;
44
45 public class CompressedClassPointers {
46
47 static final String logging_option = "-Xlog:gc+metaspace=trace,metaspace=info,cds=trace";
48 static final String reserveCCSAnywhere = "Reserving compressed class space anywhere";
49
50 // Returns true if we are to test the narrow klass base; we only do this on
51 // platforms where we can be reasonably shure that we get reproducable placement).
52 static boolean testNarrowKlassBase() {
53 if (Platform.isWindows()) {
54 return false;
55 }
56 return true;
57
58 }
59
60 // Returns true if the output indicates that the ccs is reserved anywhere.
61 static boolean isCCSReservedAnywhere(OutputAnalyzer output) {
62 if (output.getOutput().contains(reserveCCSAnywhere)) {
63 return true;
64 } else {
65 return false;
66 }
67 }
68
69 // CDS off, small heap, ccs size default (1G)
70 // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.
71 public static void smallHeapTest() throws Exception {
72 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
73 "-XX:+UnlockDiagnosticVMOptions",
74 "-XX:SharedBaseAddress=8g",
75 "-Xmx128m",
76 logging_option,
77 "-Xshare:off",
78 "-XX:+VerifyBeforeGC", "-version");
79 OutputAnalyzer output = new OutputAnalyzer(pb.start());
204 output.shouldHaveExitValue(0);
205
206 } catch (RuntimeException e) {
207 output.shouldContain("Unable to use shared archive");
208 output.shouldHaveExitValue(1);
209 }
210 }
211
212 public static void smallHeapTestNoCoop() throws Exception {
213 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
214 "-XX:-UseCompressedOops",
215 "-XX:+UseCompressedClassPointers",
216 "-XX:+UnlockDiagnosticVMOptions",
217 "-XX:SharedBaseAddress=8g",
218 "-Xmx128m",
219 "-Xlog:gc+metaspace=trace",
220 "-Xshare:off",
221 "-Xlog:cds=trace",
222 "-XX:+VerifyBeforeGC", "-version");
223 OutputAnalyzer output = new OutputAnalyzer(pb.start());
224 if (!isCCSReservedAnywhere(output)) {
225 output.shouldContain("Narrow klass base: 0x0000000000000000");
226 }
227 output.shouldHaveExitValue(0);
228 }
229
230 public static void smallHeapTestWith1GNoCoop() throws Exception {
231 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
232 "-XX:-UseCompressedOops",
233 "-XX:+UseCompressedClassPointers",
234 "-XX:+UnlockDiagnosticVMOptions",
235 "-XX:CompressedClassSpaceSize=1g",
236 "-Xmx128m",
237 "-Xlog:gc+metaspace=trace",
238 "-Xshare:off",
239 "-Xlog:cds=trace",
240 "-XX:+VerifyBeforeGC", "-version");
241 OutputAnalyzer output = new OutputAnalyzer(pb.start());
242 if (!isCCSReservedAnywhere(output)) {
243 output.shouldContain("Narrow klass base: 0x0000000000000000");
244 }
245 if (!Platform.isAArch64() && !Platform.isPPC()) {
246 // Currently relax this test for Aarch64 and ppc.
247 output.shouldContain("Narrow klass shift: 0");
248 }
249 output.shouldHaveExitValue(0);
250 }
251
252 public static void largeHeapTestNoCoop() throws Exception {
253 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
254 "-XX:-UseCompressedOops",
255 "-XX:+UseCompressedClassPointers",
256 "-XX:+UnlockDiagnosticVMOptions",
257 "-XX:+UnlockExperimentalVMOptions",
258 "-Xmx30g",
259 "-Xlog:gc+metaspace=trace",
260 "-Xshare:off",
261 "-Xlog:cds=trace",
262 "-XX:+VerifyBeforeGC", "-version");
263 OutputAnalyzer output = new OutputAnalyzer(pb.start());
264 if (!isCCSReservedAnywhere(output)) {
265 output.shouldContain("Narrow klass base: 0x0000000000000000");
266 }
267 if (!Platform.isAArch64() && !Platform.isPPC()) {
268 // Currently relax this test for Aarch64 and ppc.
269 output.shouldContain("Narrow klass shift: 0");
270 }
271 output.shouldHaveExitValue(0);
272 }
273
274 public static void largePagesTestNoCoop() throws Exception {
275 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
276 "-XX:-UseCompressedOops",
277 "-XX:+UseCompressedClassPointers",
278 "-XX:+UnlockDiagnosticVMOptions",
279 "-Xmx128m",
280 "-XX:+UseLargePages",
281 "-Xlog:gc+metaspace=trace",
282 "-XX:+VerifyBeforeGC", "-version");
283 OutputAnalyzer output = new OutputAnalyzer(pb.start());
284 output.shouldContain("Narrow klass base:");
285 output.shouldHaveExitValue(0);
286 }
287
|
29 * @requires vm.flagless
30 * @comment Testing compressed class pointers without compressed oops is not possible
31 * on MacOS because the heap is given an arbitrary address that occasionally
32 * collides with where we would ideally have placed the compressed class space.
33 * @requires os.family != "mac"
34 * @library /test/lib
35 * @modules java.base/jdk.internal.misc
36 * java.management
37 * @run driver CompressedClassPointers
38 */
39
40 import jdk.test.lib.Platform;
41 import jdk.test.lib.process.ProcessTools;
42 import jdk.test.lib.process.OutputAnalyzer;
43 import jtreg.SkippedException;
44
45 public class CompressedClassPointers {
46
47 static final String logging_option = "-Xlog:gc+metaspace=trace,metaspace=info,cds=trace";
48 static final String reserveCCSAnywhere = "Reserving compressed class space anywhere";
49 static final String usesCompactObjectHeadersPat = "UseCompactObjectHeaders 1";
50
51 // Returns true if we are to test the narrow klass base; we only do this on
52 // platforms where we can be reasonably shure that we get reproducable placement).
53 static boolean testNarrowKlassBase() {
54 if (Platform.isWindows()) {
55 return false;
56 }
57 return true;
58
59 }
60
61 // Returns true if the output indicates that the VM uses compact object headers
62 static boolean usesCompactObjectHeaders(OutputAnalyzer output) {
63 return output.getOutput().contains(usesCompactObjectHeadersPat);
64 }
65
66 // Returns true if the output indicates that the ccs is reserved anywhere.
67 static boolean isCCSReservedAnywhere(OutputAnalyzer output) {
68 if (output.getOutput().contains(reserveCCSAnywhere)) {
69 return true;
70 } else {
71 return false;
72 }
73 }
74
75 // CDS off, small heap, ccs size default (1G)
76 // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.
77 public static void smallHeapTest() throws Exception {
78 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
79 "-XX:+UnlockDiagnosticVMOptions",
80 "-XX:SharedBaseAddress=8g",
81 "-Xmx128m",
82 logging_option,
83 "-Xshare:off",
84 "-XX:+VerifyBeforeGC", "-version");
85 OutputAnalyzer output = new OutputAnalyzer(pb.start());
210 output.shouldHaveExitValue(0);
211
212 } catch (RuntimeException e) {
213 output.shouldContain("Unable to use shared archive");
214 output.shouldHaveExitValue(1);
215 }
216 }
217
218 public static void smallHeapTestNoCoop() throws Exception {
219 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
220 "-XX:-UseCompressedOops",
221 "-XX:+UseCompressedClassPointers",
222 "-XX:+UnlockDiagnosticVMOptions",
223 "-XX:SharedBaseAddress=8g",
224 "-Xmx128m",
225 "-Xlog:gc+metaspace=trace",
226 "-Xshare:off",
227 "-Xlog:cds=trace",
228 "-XX:+VerifyBeforeGC", "-version");
229 OutputAnalyzer output = new OutputAnalyzer(pb.start());
230 if (!isCCSReservedAnywhere(output) && !usesCompactObjectHeaders(output)) {
231 output.shouldContain("Narrow klass base: 0x0000000000000000");
232 }
233 output.shouldHaveExitValue(0);
234 }
235
236 public static void smallHeapTestWith1GNoCoop() throws Exception {
237 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
238 "-XX:-UseCompressedOops",
239 "-XX:+UseCompressedClassPointers",
240 "-XX:+UnlockDiagnosticVMOptions",
241 "-XX:CompressedClassSpaceSize=1g",
242 "-Xmx128m",
243 "-Xlog:gc+metaspace=trace",
244 "-Xshare:off",
245 "-Xlog:cds=trace",
246 "-XX:+VerifyBeforeGC", "-version");
247 OutputAnalyzer output = new OutputAnalyzer(pb.start());
248 if (!isCCSReservedAnywhere(output) && !usesCompactObjectHeaders(output)) {
249 output.shouldContain("Narrow klass base: 0x0000000000000000");
250 }
251 if (!Platform.isAArch64() && !usesCompactObjectHeaders(output) && !Platform.isPPC()) {
252 // Currently relax this test for Aarch64 and ppc.
253 output.shouldContain("Narrow klass shift: 0");
254 }
255 output.shouldHaveExitValue(0);
256 }
257
258 public static void largeHeapTestNoCoop() throws Exception {
259 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
260 "-XX:-UseCompressedOops",
261 "-XX:+UseCompressedClassPointers",
262 "-XX:+UnlockDiagnosticVMOptions",
263 "-XX:+UnlockExperimentalVMOptions",
264 "-Xmx30g",
265 "-Xlog:gc+metaspace=trace",
266 "-Xshare:off",
267 "-Xlog:cds=trace",
268 "-XX:+VerifyBeforeGC", "-version");
269 OutputAnalyzer output = new OutputAnalyzer(pb.start());
270 if (!isCCSReservedAnywhere(output) && !usesCompactObjectHeaders(output)) {
271 output.shouldContain("Narrow klass base: 0x0000000000000000");
272 }
273 if (!Platform.isAArch64() && !usesCompactObjectHeaders(output) && !Platform.isPPC()) {
274 // Currently relax this test for Aarch64 and ppc.
275 output.shouldContain("Narrow klass shift: 0");
276 }
277 output.shouldHaveExitValue(0);
278 }
279
280 public static void largePagesTestNoCoop() throws Exception {
281 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
282 "-XX:-UseCompressedOops",
283 "-XX:+UseCompressedClassPointers",
284 "-XX:+UnlockDiagnosticVMOptions",
285 "-Xmx128m",
286 "-XX:+UseLargePages",
287 "-Xlog:gc+metaspace=trace",
288 "-XX:+VerifyBeforeGC", "-version");
289 OutputAnalyzer output = new OutputAnalyzer(pb.start());
290 output.shouldContain("Narrow klass base:");
291 output.shouldHaveExitValue(0);
292 }
293
|