CompressedClassPointers.java revision 11833:1cbffa2beba6
1/*
2 * Copyright (c) 2013, 2016, 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/*
25 * @test
26 * @bug 8024927
27 * @summary Testing address of compressed class pointer space as best as possible.
28 * @library /test/lib
29 * @modules java.base/jdk.internal.misc
30 *          java.management
31 */
32
33import jdk.test.lib.Platform;
34import jdk.test.lib.process.ProcessTools;
35import jdk.test.lib.process.OutputAnalyzer;
36
37public class CompressedClassPointers {
38
39    public static void smallHeapTest() throws Exception {
40        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
41            "-XX:+UnlockDiagnosticVMOptions",
42            "-XX:SharedBaseAddress=8g",
43            "-Xmx128m",
44            "-Xlog:gc+metaspace=trace",
45            "-XX:+VerifyBeforeGC", "-version");
46        OutputAnalyzer output = new OutputAnalyzer(pb.start());
47        output.shouldContain("Narrow klass base: 0x0000000000000000");
48        output.shouldHaveExitValue(0);
49    }
50
51    public static void smallHeapTestWith3G() throws Exception {
52        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
53            "-XX:+UnlockDiagnosticVMOptions",
54            "-XX:CompressedClassSpaceSize=3g",
55            "-Xmx128m",
56            "-Xlog:gc+metaspace=trace",
57            "-XX:+VerifyBeforeGC", "-version");
58        OutputAnalyzer output = new OutputAnalyzer(pb.start());
59        output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3");
60        output.shouldHaveExitValue(0);
61    }
62
63    public static void largeHeapTest() throws Exception {
64        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
65            "-XX:+UnlockDiagnosticVMOptions",
66            "-Xmx30g",
67            "-Xlog:gc+metaspace=trace",
68            "-XX:+VerifyBeforeGC", "-version");
69        OutputAnalyzer output = new OutputAnalyzer(pb.start());
70        output.shouldNotContain("Narrow klass base: 0x0000000000000000");
71        output.shouldContain("Narrow klass shift: 0");
72        output.shouldHaveExitValue(0);
73    }
74
75    public static void largePagesTest() throws Exception {
76        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
77            "-XX:+UnlockDiagnosticVMOptions",
78            "-Xmx128m",
79            "-XX:+UseLargePages",
80            "-Xlog:gc+metaspace=trace",
81            "-XX:+VerifyBeforeGC", "-version");
82        OutputAnalyzer output = new OutputAnalyzer(pb.start());
83        output.shouldContain("Narrow klass base:");
84        output.shouldHaveExitValue(0);
85    }
86
87    public static void heapBaseMinAddressTest() throws Exception {
88        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
89            "-XX:HeapBaseMinAddress=1m",
90            "-Xlog:gc+heap+coops=debug",
91            "-version");
92        OutputAnalyzer output = new OutputAnalyzer(pb.start());
93        output.shouldContain("HeapBaseMinAddress must be at least");
94        output.shouldHaveExitValue(0);
95    }
96
97    public static void sharingTest() throws Exception {
98        // Test small heaps
99        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
100            "-XX:+UnlockDiagnosticVMOptions",
101            "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
102            "-Xmx128m",
103            "-XX:SharedBaseAddress=8g",
104            "-XX:+PrintCompressedOopsMode",
105            "-XX:+VerifyBeforeGC",
106            "-Xshare:dump");
107        OutputAnalyzer output = new OutputAnalyzer(pb.start());
108        try {
109          output.shouldContain("Loading classes to share");
110          output.shouldHaveExitValue(0);
111
112          pb = ProcessTools.createJavaProcessBuilder(
113            "-XX:+UnlockDiagnosticVMOptions",
114            "-XX:SharedArchiveFile=./CompressedClassPointers.jsa",
115            "-Xmx128m",
116            "-XX:SharedBaseAddress=8g",
117            "-XX:+PrintCompressedOopsMode",
118            "-Xshare:on",
119            "-version");
120          output = new OutputAnalyzer(pb.start());
121          output.shouldContain("sharing");
122          output.shouldHaveExitValue(0);
123
124        } catch (RuntimeException e) {
125          output.shouldContain("Unable to use shared archive");
126          output.shouldHaveExitValue(1);
127        }
128    }
129
130    public static void main(String[] args) throws Exception {
131        if (!Platform.is64bit()) {
132            // Can't test this on 32 bit, just pass
133            System.out.println("Skipping test on 32bit");
134            return;
135        }
136        // Solaris 10 can't mmap compressed oops space without a base
137        if (Platform.isSolaris()) {
138             String name = System.getProperty("os.version");
139             if (name.equals("5.10")) {
140                 System.out.println("Skipping test on Solaris 10");
141                 return;
142             }
143        }
144        smallHeapTest();
145        smallHeapTestWith3G();
146        largeHeapTest();
147        largePagesTest();
148        heapBaseMinAddressTest();
149        sharingTest();
150    }
151}
152