< prev index next >

test/hotspot/jtreg/runtime/CompressedOops/CompressedClassPointers.java

Print this page

 37 import jdk.test.lib.process.ProcessTools;
 38 import jdk.test.lib.process.OutputAnalyzer;
 39 import jtreg.SkippedException;
 40 
 41 public class CompressedClassPointers {
 42 
 43     static final String logging_option = "-Xlog:gc+metaspace=trace,cds=trace";
 44 
 45     // Returns true if we are to test the narrow klass base; we only do this on
 46     // platforms where we can be reasonably shure that we get reproducable placement).
 47     static boolean testNarrowKlassBase() {
 48         if (Platform.isWindows()) {
 49             return false;
 50         }
 51         return true;
 52 
 53     }
 54 
 55     // CDS off, small heap, ccs size default (1G)
 56     // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.



 57     public static void smallHeapTest() throws Exception {
 58         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 59             "-XX:+UnlockDiagnosticVMOptions",
 60             "-XX:SharedBaseAddress=8g",
 61             "-Xmx128m",
 62             logging_option,
 63             "-Xshare:off",
 64             "-XX:+VerifyBeforeGC", "-version");
 65         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 66         if (testNarrowKlassBase()) {
 67             output.shouldContain("Narrow klass base: 0x0000000000000000");
 68         }
 69         output.shouldHaveExitValue(0);
 70     }

 71 
 72     // CDS off, small heap, ccs size explicitely set to 1G
 73     // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.

 74     public static void smallHeapTestWith1G() throws Exception {
 75         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 76             "-XX:+UnlockDiagnosticVMOptions",
 77             "-XX:CompressedClassSpaceSize=1g",
 78             "-Xmx128m",
 79             logging_option,
 80             "-Xshare:off",
 81             "-XX:+VerifyBeforeGC", "-version");
 82         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 83         if (testNarrowKlassBase()) {
 84             output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3");
 85         }
 86         output.shouldHaveExitValue(0);
 87     }

 88 
 89     // CDS off, a very large heap, ccs size left to 1G default.
 90     // We expect the ccs to be mapped somewhere far beyond the heap, such that it is not possible
 91     // to use zero based encoding.


 92     public static void largeHeapTest() throws Exception {
 93         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 94             "-XX:+UnlockDiagnosticVMOptions",
 95             "-XX:+UnlockExperimentalVMOptions",
 96             "-Xmx30g",
 97             logging_option,
 98             "-Xshare:off",
 99             "-XX:+VerifyBeforeGC", "-version");
100         OutputAnalyzer output = new OutputAnalyzer(pb.start());
101         if (testNarrowKlassBase() && !Platform.isPPC() && !Platform.isOSX()) {
102             // PPC: in most cases the heap cannot be placed below 32g so there
103             // is room for ccs and narrow klass base will be 0x0. Exception:
104             // Linux 4.1.42 or earlier (see ELF_ET_DYN_BASE in JDK-8244847).
105             // For simplicity we exclude PPC.
106             // OSX: similar.
107             output.shouldNotContain("Narrow klass base: 0x0000000000000000");
108             output.shouldContain("Narrow klass shift: 0");
109         }
110         output.shouldHaveExitValue(0);
111     }

112 
113     // Settings as in largeHeapTest() except for max heap size. We make max heap
114     // size even larger such that it cannot fit into lower 32G but not too large
115     // for compressed oops.
116     // We expect a zerobased ccs.

117     public static void largeHeapAbove32GTest() throws Exception {
118         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
119             "-XX:+UnlockDiagnosticVMOptions",
120             "-XX:+UnlockExperimentalVMOptions",
121             "-Xmx31g",
122             logging_option,
123             "-Xshare:off",
124             "-XX:+VerifyBeforeGC", "-version");
125         OutputAnalyzer output = new OutputAnalyzer(pb.start());
126         if (testNarrowKlassBase()) {
127             if (!(Platform.isAArch64() && Platform.isOSX())) { // see JDK-8262895
128                 output.shouldContain("Narrow klass base: 0x0000000000000000");
129                 if (!Platform.isAArch64() && !Platform.isOSX()) {
130                     output.shouldContain("Narrow klass shift: 0");
131                 }
132             }
133         }
134         output.shouldHaveExitValue(0);
135     }

136 
137     // Using large paged heap, metaspace uses small pages.




138     public static void largePagesForHeapTest() throws Exception {
139         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
140                 "-XX:+UnlockDiagnosticVMOptions",
141                 "-Xmx128m",
142                 "-XX:+UseLargePages",
143                 logging_option,
144                 "-XX:+VerifyBeforeGC", "-version");
145         OutputAnalyzer output = new OutputAnalyzer(pb.start());
146         if (testNarrowKlassBase()) {
147             output.shouldContain("Narrow klass base:");
148         }
149         output.shouldHaveExitValue(0);
150     }
151 
152     public static void heapBaseMinAddressTest() throws Exception {
153         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
154             "-XX:HeapBaseMinAddress=1m",
155             "-Xlog:gc+heap+coops=debug",
156             "-version");
157         OutputAnalyzer output = new OutputAnalyzer(pb.start());

178           output.shouldHaveExitValue(0);
179 
180           pb = ProcessTools.createJavaProcessBuilder(
181             "-XX:+UnlockDiagnosticVMOptions",
182             "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
183             "-Xmx128m",
184             "-XX:SharedBaseAddress=8g",
185             "-Xlog:gc+heap+coops=debug",
186             "-Xshare:on",
187             "-version");
188           output = new OutputAnalyzer(pb.start());
189           output.shouldContain("sharing");
190           output.shouldHaveExitValue(0);
191 
192         } catch (RuntimeException e) {
193           output.shouldContain("Unable to use shared archive");
194           output.shouldHaveExitValue(1);
195         }
196     }
197 

198     public static void smallHeapTestNoCoop() throws Exception {
199         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
200             "-XX:-UseCompressedOops",
201             "-XX:+UseCompressedClassPointers",
202             "-XX:+UnlockDiagnosticVMOptions",
203             "-XX:SharedBaseAddress=8g",
204             "-Xmx128m",
205             "-Xlog:gc+metaspace=trace",
206             "-Xshare:off",
207             "-Xlog:cds=trace",
208             "-XX:+VerifyBeforeGC", "-version");
209         OutputAnalyzer output = new OutputAnalyzer(pb.start());
210         output.shouldContain("Narrow klass base: 0x0000000000000000");
211         output.shouldHaveExitValue(0);
212     }

213 

214     public static void smallHeapTestWith1GNoCoop() throws Exception {
215         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
216             "-XX:-UseCompressedOops",
217             "-XX:+UseCompressedClassPointers",
218             "-XX:+UnlockDiagnosticVMOptions",
219             "-XX:CompressedClassSpaceSize=1g",
220             "-Xmx128m",
221             "-Xlog:gc+metaspace=trace",
222             "-Xshare:off",
223             "-Xlog:cds=trace",
224             "-XX:+VerifyBeforeGC", "-version");
225         OutputAnalyzer output = new OutputAnalyzer(pb.start());
226         output.shouldContain("Narrow klass base: 0x0000000000000000");
227         if (!Platform.isAArch64()) {
228             // Currently relax this test for Aarch64.
229             output.shouldContain("Narrow klass shift: 0");
230         }
231         output.shouldHaveExitValue(0);
232     }

233 

234     public static void largeHeapTestNoCoop() throws Exception {
235         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
236             "-XX:-UseCompressedOops",
237             "-XX:+UseCompressedClassPointers",
238             "-XX:+UnlockDiagnosticVMOptions",
239             "-XX:+UnlockExperimentalVMOptions",
240             "-Xmx30g",
241             "-Xlog:gc+metaspace=trace",
242             "-Xshare:off",
243             "-Xlog:cds=trace",
244             "-XX:+VerifyBeforeGC", "-version");
245         OutputAnalyzer output = new OutputAnalyzer(pb.start());
246         output.shouldContain("Narrow klass base: 0x0000000000000000");
247         if (!Platform.isAArch64()) {
248             // Currently relax this test for Aarch64.
249             output.shouldContain("Narrow klass shift: 0");
250         }
251         output.shouldHaveExitValue(0);
252     }

253 
254     public static void largePagesTestNoCoop() throws Exception {
255         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
256             "-XX:-UseCompressedOops",
257             "-XX:+UseCompressedClassPointers",
258             "-XX:+UnlockDiagnosticVMOptions",
259             "-Xmx128m",
260             "-XX:+UseLargePages",
261             "-Xlog:gc+metaspace=trace",
262             "-XX:+VerifyBeforeGC", "-version");
263         OutputAnalyzer output = new OutputAnalyzer(pb.start());
264         output.shouldContain("Narrow klass base:");
265         output.shouldHaveExitValue(0);
266     }
267 
268     public static void heapBaseMinAddressTestNoCoop() throws Exception {
269         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
270             "-XX:-UseCompressedOops",
271             "-XX:+UseCompressedClassPointers",
272             "-XX:HeapBaseMinAddress=1m",

301             "-XX:-UseCompressedOops",
302             "-XX:+UseCompressedClassPointers",
303             "-XX:+UnlockDiagnosticVMOptions",
304             "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
305             "-Xmx128m",
306             "-XX:SharedBaseAddress=8g",
307             "-Xlog:gc+heap+coops=debug",
308             "-Xshare:on",
309             "-version");
310           output = new OutputAnalyzer(pb.start());
311           output.shouldContain("sharing");
312           output.shouldHaveExitValue(0);
313 
314         } catch (RuntimeException e) {
315           output.shouldContain("Unable to use shared archive");
316           output.shouldHaveExitValue(1);
317         }
318     }
319 
320     public static void main(String[] args) throws Exception {
321         smallHeapTest();
322         smallHeapTestWith1G();
323         largeHeapTest();
324         largeHeapAbove32GTest();
325         largePagesForHeapTest();
326         heapBaseMinAddressTest();
327         sharingTest();
328 
329         if (!Platform.isOSX()) {
330             // Testing compressed class pointers without compressed oops.
331             // This is only possible if the platform supports it. Notably,
332             // on macOS, when compressed oops is disabled and the heap is
333             // given an arbitrary address, that address occasionally collides
334             // with where we would ideally have placed the compressed class
335             // space. Therefore, macOS is omitted for now.
336             smallHeapTestNoCoop();
337             smallHeapTestWith1GNoCoop();
338             largeHeapTestNoCoop();
339             largePagesTestNoCoop();
340             heapBaseMinAddressTestNoCoop();
341             sharingTestNoCoop();
342         }
343     }
344 }

 37 import jdk.test.lib.process.ProcessTools;
 38 import jdk.test.lib.process.OutputAnalyzer;
 39 import jtreg.SkippedException;
 40 
 41 public class CompressedClassPointers {
 42 
 43     static final String logging_option = "-Xlog:gc+metaspace=trace,cds=trace";
 44 
 45     // Returns true if we are to test the narrow klass base; we only do this on
 46     // platforms where we can be reasonably shure that we get reproducable placement).
 47     static boolean testNarrowKlassBase() {
 48         if (Platform.isWindows()) {
 49             return false;
 50         }
 51         return true;
 52 
 53     }
 54 
 55     // CDS off, small heap, ccs size default (1G)
 56     // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.
 57     /* Lilliput: cannot work due to drastically reduced narrow klass pointer range (atm 2g and that may get
 58        smaller still). There is an argument for improving CDS/CCS reservation and make it more likely to run
 59        zero-based, but that logic has to be rethought.
 60     public static void smallHeapTest() throws Exception {
 61         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 62             "-XX:+UnlockDiagnosticVMOptions",
 63             "-XX:SharedBaseAddress=8g",
 64             "-Xmx128m",
 65             logging_option,
 66             "-Xshare:off",
 67             "-XX:+VerifyBeforeGC", "-version");
 68         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 69         if (testNarrowKlassBase()) {
 70             output.shouldContain("Narrow klass base: 0x0000000000000000");
 71         }
 72         output.shouldHaveExitValue(0);
 73     }
 74      */
 75 
 76     // CDS off, small heap, ccs size explicitely set to 1G
 77     // A small heap should allow us to place the ccs within the lower 32G and thus allow zero based encoding.
 78     /* Lilliput: See comment above.
 79     public static void smallHeapTestWith1G() throws Exception {
 80         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 81             "-XX:+UnlockDiagnosticVMOptions",
 82             "-XX:CompressedClassSpaceSize=1g",
 83             "-Xmx128m",
 84             logging_option,
 85             "-Xshare:off",
 86             "-XX:+VerifyBeforeGC", "-version");
 87         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 88         if (testNarrowKlassBase()) {
 89             output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3");
 90         }
 91         output.shouldHaveExitValue(0);
 92     }
 93     */
 94 
 95     // CDS off, a very large heap, ccs size left to 1G default.
 96     // We expect the ccs to be mapped somewhere far beyond the heap, such that it is not possible
 97     // to use zero based encoding.
 98     /* Lilliput: I am not sure what the point of this test CCS reservation is independent from
 99        heap. See below the desparate attempts to predict heap reservation on PPC. Why do we even care?
100     public static void largeHeapTest() throws Exception {
101         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
102             "-XX:+UnlockDiagnosticVMOptions",
103             "-XX:+UnlockExperimentalVMOptions",
104             "-Xmx30g",
105             logging_option,
106             "-Xshare:off",
107             "-XX:+VerifyBeforeGC", "-version");
108         OutputAnalyzer output = new OutputAnalyzer(pb.start());
109         if (testNarrowKlassBase() && !Platform.isPPC() && !Platform.isOSX()) {
110             // PPC: in most cases the heap cannot be placed below 32g so there
111             // is room for ccs and narrow klass base will be 0x0. Exception:
112             // Linux 4.1.42 or earlier (see ELF_ET_DYN_BASE in JDK-8244847).
113             // For simplicity we exclude PPC.
114             // OSX: similar.
115             output.shouldNotContain("Narrow klass base: 0x0000000000000000");
116             output.shouldContain("Narrow klass shift: 0");
117         }
118         output.shouldHaveExitValue(0);
119     }
120      */
121 
122     // Settings as in largeHeapTest() except for max heap size. We make max heap
123     // size even larger such that it cannot fit into lower 32G but not too large
124     // for compressed oops.
125     // We expect a zerobased ccs.
126     /* Lilliput: narrow klass pointer range drastically reduced. See comments under smallHeapTest().
127     public static void largeHeapAbove32GTest() throws Exception {
128         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
129             "-XX:+UnlockDiagnosticVMOptions",
130             "-XX:+UnlockExperimentalVMOptions",
131             "-Xmx31g",
132             logging_option,
133             "-Xshare:off",
134             "-XX:+VerifyBeforeGC", "-version");
135         OutputAnalyzer output = new OutputAnalyzer(pb.start());
136         if (testNarrowKlassBase()) {
137             if (!(Platform.isAArch64() && Platform.isOSX())) { // see JDK-8262895
138                 output.shouldContain("Narrow klass base: 0x0000000000000000");
139                 if (!Platform.isAArch64() && !Platform.isOSX()) {
140                     output.shouldContain("Narrow klass shift: 0");
141                 }
142             }
143         }
144         output.shouldHaveExitValue(0);
145     }
146     */
147 
148     // Using large paged heap, metaspace uses small pages.
149     /* Lilliput: not sure what the point of this test is. The ability to have a class space if heap uses
150        large pages? Why would that be a problem? Kept alive for now since it makes no problems even with
151        smaller class pointers.
152      */
153     public static void largePagesForHeapTest() throws Exception {
154         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
155                 "-XX:+UnlockDiagnosticVMOptions",
156                 "-Xmx128m",
157                 "-XX:+UseLargePages",
158                 logging_option,
159                 "-XX:+VerifyBeforeGC", "-version");
160         OutputAnalyzer output = new OutputAnalyzer(pb.start());
161         if (testNarrowKlassBase()) {
162             output.shouldContain("Narrow klass base:");
163         }
164         output.shouldHaveExitValue(0);
165     }
166 
167     public static void heapBaseMinAddressTest() throws Exception {
168         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
169             "-XX:HeapBaseMinAddress=1m",
170             "-Xlog:gc+heap+coops=debug",
171             "-version");
172         OutputAnalyzer output = new OutputAnalyzer(pb.start());

193           output.shouldHaveExitValue(0);
194 
195           pb = ProcessTools.createJavaProcessBuilder(
196             "-XX:+UnlockDiagnosticVMOptions",
197             "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
198             "-Xmx128m",
199             "-XX:SharedBaseAddress=8g",
200             "-Xlog:gc+heap+coops=debug",
201             "-Xshare:on",
202             "-version");
203           output = new OutputAnalyzer(pb.start());
204           output.shouldContain("sharing");
205           output.shouldHaveExitValue(0);
206 
207         } catch (RuntimeException e) {
208           output.shouldContain("Unable to use shared archive");
209           output.shouldHaveExitValue(1);
210         }
211     }
212 
213     /* Lilliput: narrow klass pointer range drastically reduced. See comments under smallHeapTest().
214     public static void smallHeapTestNoCoop() throws Exception {
215         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
216             "-XX:-UseCompressedOops",
217             "-XX:+UseCompressedClassPointers",
218             "-XX:+UnlockDiagnosticVMOptions",
219             "-XX:SharedBaseAddress=8g",
220             "-Xmx128m",
221             "-Xlog:gc+metaspace=trace",
222             "-Xshare:off",
223             "-Xlog:cds=trace",
224             "-XX:+VerifyBeforeGC", "-version");
225         OutputAnalyzer output = new OutputAnalyzer(pb.start());
226         output.shouldContain("Narrow klass base: 0x0000000000000000");
227         output.shouldHaveExitValue(0);
228     }
229     */
230 
231     /* Lilliput: narrow klass pointer range drastically reduced. See comments under smallHeapTest().
232     public static void smallHeapTestWith1GNoCoop() throws Exception {
233         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
234             "-XX:-UseCompressedOops",
235             "-XX:+UseCompressedClassPointers",
236             "-XX:+UnlockDiagnosticVMOptions",
237             "-XX:CompressedClassSpaceSize=1g",
238             "-Xmx128m",
239             "-Xlog:gc+metaspace=trace",
240             "-Xshare:off",
241             "-Xlog:cds=trace",
242             "-XX:+VerifyBeforeGC", "-version");
243         OutputAnalyzer output = new OutputAnalyzer(pb.start());
244         output.shouldContain("Narrow klass base: 0x0000000000000000");
245         if (!Platform.isAArch64()) {
246             // Currently relax this test for Aarch64.
247             output.shouldContain("Narrow klass shift: 0");
248         }
249         output.shouldHaveExitValue(0);
250     }
251     */
252 
253     /* Lilliput: narrow klass pointer range drastically reduced. See comments under smallHeapTest().
254     public static void largeHeapTestNoCoop() throws Exception {
255         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
256             "-XX:-UseCompressedOops",
257             "-XX:+UseCompressedClassPointers",
258             "-XX:+UnlockDiagnosticVMOptions",
259             "-XX:+UnlockExperimentalVMOptions",
260             "-Xmx30g",
261             "-Xlog:gc+metaspace=trace",
262             "-Xshare:off",
263             "-Xlog:cds=trace",
264             "-XX:+VerifyBeforeGC", "-version");
265         OutputAnalyzer output = new OutputAnalyzer(pb.start());
266         output.shouldContain("Narrow klass base: 0x0000000000000000");
267         if (!Platform.isAArch64()) {
268             // Currently relax this test for Aarch64.
269             output.shouldContain("Narrow klass shift: 0");
270         }
271         output.shouldHaveExitValue(0);
272     }
273     */
274 
275     public static void largePagesTestNoCoop() throws Exception {
276         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
277             "-XX:-UseCompressedOops",
278             "-XX:+UseCompressedClassPointers",
279             "-XX:+UnlockDiagnosticVMOptions",
280             "-Xmx128m",
281             "-XX:+UseLargePages",
282             "-Xlog:gc+metaspace=trace",
283             "-XX:+VerifyBeforeGC", "-version");
284         OutputAnalyzer output = new OutputAnalyzer(pb.start());
285         output.shouldContain("Narrow klass base:");
286         output.shouldHaveExitValue(0);
287     }
288 
289     public static void heapBaseMinAddressTestNoCoop() throws Exception {
290         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
291             "-XX:-UseCompressedOops",
292             "-XX:+UseCompressedClassPointers",
293             "-XX:HeapBaseMinAddress=1m",

322             "-XX:-UseCompressedOops",
323             "-XX:+UseCompressedClassPointers",
324             "-XX:+UnlockDiagnosticVMOptions",
325             "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
326             "-Xmx128m",
327             "-XX:SharedBaseAddress=8g",
328             "-Xlog:gc+heap+coops=debug",
329             "-Xshare:on",
330             "-version");
331           output = new OutputAnalyzer(pb.start());
332           output.shouldContain("sharing");
333           output.shouldHaveExitValue(0);
334 
335         } catch (RuntimeException e) {
336           output.shouldContain("Unable to use shared archive");
337           output.shouldHaveExitValue(1);
338         }
339     }
340 
341     public static void main(String[] args) throws Exception {
342         // smallHeapTest();
343         // smallHeapTestWith1G();
344         // largeHeapTest();
345         // largeHeapAbove32GTest();
346         largePagesForHeapTest();
347         heapBaseMinAddressTest();
348         sharingTest();
349 
350         if (!Platform.isOSX()) {
351             // Testing compressed class pointers without compressed oops.
352             // This is only possible if the platform supports it. Notably,
353             // on macOS, when compressed oops is disabled and the heap is
354             // given an arbitrary address, that address occasionally collides
355             // with where we would ideally have placed the compressed class
356             // space. Therefore, macOS is omitted for now.
357             // smallHeapTestNoCoop();
358             // smallHeapTestWith1GNoCoop();
359             // largeHeapTestNoCoop();
360             largePagesTestNoCoop();
361             heapBaseMinAddressTestNoCoop();
362             sharingTestNoCoop();
363         }
364     }
365 }
< prev index next >