25 * @test
26 * @summary Testing that, faced with a given (possibly odd) mapping address of class space, the encoding
27 * scheme fits the address
28 * @requires vm.bits == 64 & !vm.graal.enabled & vm.debug == true
29 * @requires vm.flagless
30 * @library /test/lib
31 * @modules java.base/jdk.internal.misc
32 * java.management
33 * @run driver CompressedClassPointersEncodingScheme
34 */
35
36 import jdk.test.lib.Platform;
37 import jdk.test.lib.process.OutputAnalyzer;
38 import jdk.test.lib.process.ProcessTools;
39 import jtreg.SkippedException;
40
41 import java.io.IOException;
42
43 public class CompressedClassPointersEncodingScheme {
44
45 private static void test(long forceAddress, long classSpaceSize, long expectedEncodingBase, int expectedEncodingShift) throws IOException {
46 String forceAddressString = String.format("0x%016X", forceAddress).toLowerCase();
47 String expectedEncodingBaseString = String.format("0x%016X", expectedEncodingBase).toLowerCase();
48 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
49 "-Xshare:off", // to make CompressedClassSpaceBaseAddress work
50 "-XX:+UnlockDiagnosticVMOptions",
51 "-XX:-UseCompressedOops", // keep VM from optimizing heap location
52 "-XX:CompressedClassSpaceBaseAddress=" + forceAddress,
53 "-XX:CompressedClassSpaceSize=" + classSpaceSize,
54 "-Xmx128m",
55 "-Xlog:metaspace*",
56 "-version");
57 OutputAnalyzer output = new OutputAnalyzer(pb.start());
58
59 output.reportDiagnosticSummary();
60
61 // We ignore cases where we were not able to map at the force address
62 if (output.contains("reserving class space failed")) {
63 throw new SkippedException("Skipping because we cannot force ccs to " + forceAddressString);
64 }
65
66 output.shouldHaveExitValue(0);
67 output.shouldContain("Narrow klass base: " + expectedEncodingBaseString + ", Narrow klass shift: " + expectedEncodingShift);
68 }
69
70 final static long K = 1024;
71 final static long M = K * 1024;
72 final static long G = M * 1024;
73 public static void main(String[] args) throws Exception {
74 // Test ccs nestling right at the end of the 4G range
75 // Expecting base=0, shift=0
76 test(4 * G - 128 * M, 128 * M, 0, 0);
77
78 // add more...
79
80 }
81 }
|
25 * @test
26 * @summary Testing that, faced with a given (possibly odd) mapping address of class space, the encoding
27 * scheme fits the address
28 * @requires vm.bits == 64 & !vm.graal.enabled & vm.debug == true
29 * @requires vm.flagless
30 * @library /test/lib
31 * @modules java.base/jdk.internal.misc
32 * java.management
33 * @run driver CompressedClassPointersEncodingScheme
34 */
35
36 import jdk.test.lib.Platform;
37 import jdk.test.lib.process.OutputAnalyzer;
38 import jdk.test.lib.process.ProcessTools;
39 import jtreg.SkippedException;
40
41 import java.io.IOException;
42
43 public class CompressedClassPointersEncodingScheme {
44
45 private static void test(long forceAddress, boolean COH, long classSpaceSize, long expectedEncodingBase, int expectedEncodingShift) throws IOException {
46 String forceAddressString = String.format("0x%016X", forceAddress).toLowerCase();
47 String expectedEncodingBaseString = String.format("0x%016X", expectedEncodingBase).toLowerCase();
48 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
49 "-Xshare:off", // to make CompressedClassSpaceBaseAddress work
50 "-XX:+UnlockDiagnosticVMOptions",
51 "-XX:-UseCompressedOops", // keep VM from optimizing heap location
52 "-XX:+UnlockExperimentalVMOptions",
53 "-XX:" + (COH ? "+" : "-") + "UseCompactObjectHeaders",
54 "-XX:CompressedClassSpaceBaseAddress=" + forceAddress,
55 "-XX:CompressedClassSpaceSize=" + classSpaceSize,
56 "-Xmx128m",
57 "-Xlog:metaspace*",
58 "-version");
59 OutputAnalyzer output = new OutputAnalyzer(pb.start());
60
61 output.reportDiagnosticSummary();
62
63 // We ignore cases where we were not able to map at the force address
64 if (output.contains("reserving class space failed")) {
65 System.out.println("Skipping because we cannot force ccs to " + forceAddressString);
66 return;
67 }
68
69 output.shouldHaveExitValue(0);
70 output.shouldContain("Narrow klass base: " + expectedEncodingBaseString + ", Narrow klass shift: " + expectedEncodingShift);
71 }
72
73 final static long K = 1024;
74 final static long M = K * 1024;
75 final static long G = M * 1024;
76 public static void main(String[] args) throws Exception {
77 // Test ccs nestling right at the end of the 4G range
78 // Expecting base=0, shift=0
79 test(4 * G - 128 * M, false, 128 * M, 0, 0);
80
81 // Test ccs nestling right at the end of the 32G range
82 // Expecting:
83 // - non-aarch64: base=0, shift=3
84 // - aarch64: base to start of class range, shift 0
85 if (Platform.isAArch64()) {
86 // The best we can do on aarch64 is to be *near* the end of the 32g range, since a valid encoding base
87 // on aarch64 must be 4G aligned, and the max. class space size is 3G.
88 long forceAddress = 0x7_0000_0000L; // 28g, and also a valid EOR immediate
89 test(forceAddress, false, 3 * G, forceAddress, 0);
90 } else {
91 test(32 * G - 128 * M, false, 128 * M, 0, 3);
92 }
93
94 // Test ccs starting *below* 4G, but extending upwards beyond 4G. All platforms except aarch64 should pick
95 // zero based encoding.
96 if (Platform.isAArch64()) {
97 long forceAddress = 0xC000_0000L; // make sure we have a valid EOR immediate
98 test(forceAddress, false, G + (128 * M), forceAddress, 0);
99 } else {
100 test(4 * G - 128 * M, false, 2 * 128 * M, 0, 3);
101 }
102 // add more...
103
104 // Compact Object Header Mode with tiny classpointers
105 // On all platforms we expect the VM to chose the smallest possible shift value needed to cover the encoding range
106 long forceAddress = 30 * G;
107
108 long ccsSize = 128 * M;
109 int expectedShift = 6;
110 test(forceAddress, true, ccsSize, forceAddress, expectedShift);
111
112 ccsSize = 512 * M;
113 expectedShift = 8;
114 test(forceAddress, true, ccsSize, forceAddress, expectedShift);
115
116 ccsSize = G;
117 expectedShift = 9;
118 test(forceAddress, true, ccsSize, forceAddress, expectedShift);
119
120 ccsSize = 3 * G;
121 expectedShift = 10;
122 test(forceAddress, true, ccsSize, forceAddress, expectedShift);
123 }
124 }
|