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