aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 8024927 aoqi@0: * @summary Testing address of compressed class pointer space as best as possible. aoqi@0: * @library /testlibrary aoqi@0: */ aoqi@0: aoqi@0: import com.oracle.java.testlibrary.*; aoqi@0: aoqi@0: public class CompressedClassPointers { aoqi@0: aoqi@0: public static void smallHeapTest() throws Exception { aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-XX:SharedBaseAddress=8g", aoqi@0: "-Xmx128m", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-XX:+VerifyBeforeGC", "-version"); aoqi@0: OutputAnalyzer output = new OutputAnalyzer(pb.start()); aoqi@0: output.shouldContain("Narrow klass base: 0x0000000000000000"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: } aoqi@0: aoqi@0: public static void smallHeapTestWith3G() throws Exception { aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-XX:CompressedClassSpaceSize=3g", aoqi@0: "-Xmx128m", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-XX:+VerifyBeforeGC", "-version"); aoqi@0: OutputAnalyzer output = new OutputAnalyzer(pb.start()); aoqi@0: output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: } aoqi@0: aoqi@0: public static void largeHeapTest() throws Exception { aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-Xmx30g", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-XX:+VerifyBeforeGC", "-version"); aoqi@0: OutputAnalyzer output = new OutputAnalyzer(pb.start()); aoqi@0: output.shouldNotContain("Narrow klass base: 0x0000000000000000"); aoqi@0: output.shouldContain("Narrow klass shift: 0"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: } aoqi@0: aoqi@0: public static void largePagesTest() throws Exception { aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-Xmx128m", aoqi@0: "-XX:+UseLargePages", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-XX:+VerifyBeforeGC", "-version"); aoqi@0: OutputAnalyzer output = new OutputAnalyzer(pb.start()); aoqi@0: output.shouldContain("Narrow klass base:"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: } aoqi@0: aoqi@0: public static void sharingTest() throws Exception { aoqi@0: // Test small heaps aoqi@0: ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-XX:SharedArchiveFile=./sample.jsa", aoqi@0: "-Xmx128m", aoqi@0: "-XX:SharedBaseAddress=8g", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-XX:+VerifyBeforeGC", aoqi@0: "-Xshare:dump"); aoqi@0: OutputAnalyzer output = new OutputAnalyzer(pb.start()); aoqi@0: try { aoqi@0: output.shouldContain("Loading classes to share"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: aoqi@0: pb = ProcessTools.createJavaProcessBuilder( aoqi@0: "-XX:+UnlockDiagnosticVMOptions", aoqi@0: "-XX:SharedArchiveFile=./sample.jsa", aoqi@0: "-Xmx128m", aoqi@0: "-XX:SharedBaseAddress=8g", aoqi@0: "-XX:+PrintCompressedOopsMode", aoqi@0: "-Xshare:on", aoqi@0: "-version"); aoqi@0: output = new OutputAnalyzer(pb.start()); aoqi@0: output.shouldContain("sharing"); aoqi@0: output.shouldHaveExitValue(0); aoqi@0: aoqi@0: } catch (RuntimeException e) { aoqi@0: output.shouldContain("Unable to use shared archive"); aoqi@0: output.shouldHaveExitValue(1); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void main(String[] args) throws Exception { aoqi@0: if (!Platform.is64bit()) { aoqi@0: // Can't test this on 32 bit, just pass aoqi@0: System.out.println("Skipping test on 32bit"); aoqi@0: return; aoqi@0: } aoqi@0: // Solaris 10 can't mmap compressed oops space without a base aoqi@0: if (Platform.isSolaris()) { aoqi@0: String name = System.getProperty("os.version"); aoqi@0: if (name.equals("5.10")) { aoqi@0: System.out.println("Skipping test on Solaris 10"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: smallHeapTest(); aoqi@0: smallHeapTestWith3G(); aoqi@0: largeHeapTest(); aoqi@0: largePagesTest(); aoqi@0: sharingTest(); aoqi@0: } aoqi@0: }