1 /* 2 * Copyright (c) 2013, 2014, 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 * @ignore 8055164 30 */ 31 32 import com.oracle.java.testlibrary.*; 33 34 public class CompressedClassPointers { 35 36 public static void smallHeapTest() throws Exception { 37 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 38 "-XX:+UnlockDiagnosticVMOptions", 39 "-XX:SharedBaseAddress=8g", 40 "-Xmx128m", 41 "-XX:+PrintCompressedOopsMode", 42 "-XX:+VerifyBeforeGC", "-version"); 43 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 44 output.shouldContain("Narrow klass base: 0x0000000000000000"); 45 output.shouldHaveExitValue(0); 46 } 47 48 public static void smallHeapTestWith3G() throws Exception { 49 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 50 "-XX:+UnlockDiagnosticVMOptions", 51 "-XX:CompressedClassSpaceSize=3g", 52 "-Xmx128m", 53 "-XX:+PrintCompressedOopsMode", 54 "-XX:+VerifyBeforeGC", "-version"); 55 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 56 output.shouldContain("Narrow klass base: 0x0000000000000000, Narrow klass shift: 3"); 57 output.shouldHaveExitValue(0); 58 } 59 60 public static void largeHeapTest() throws Exception { 61 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 62 "-XX:+UnlockDiagnosticVMOptions", 63 "-Xmx30g", 64 "-XX:+PrintCompressedOopsMode", 65 "-XX:+VerifyBeforeGC", "-version"); 66 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 67 output.shouldNotContain("Narrow klass base: 0x0000000000000000"); 68 output.shouldContain("Narrow klass shift: 0"); 69 output.shouldHaveExitValue(0); 70 } 71 72 public static void largePagesTest() throws Exception { 73 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 74 "-XX:+UnlockDiagnosticVMOptions", 75 "-Xmx128m", 76 "-XX:+UseLargePages", 77 "-XX:+PrintCompressedOopsMode", 78 "-XX:+VerifyBeforeGC", "-version"); 79 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 80 output.shouldContain("Narrow klass base:"); 81 output.shouldHaveExitValue(0); 82 } 83 84 public static void heapBaseMinAddressTest() throws Exception { 85 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 86 "-XX:HeapBaseMinAddress=1m", 87 "-XX:+UnlockDiagnosticVMOptions", 88 "-XX:+PrintCompressedOopsMode", 89 "-version"); 90 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 91 output.shouldContain("HeapBaseMinAddress must be at least"); 92 output.shouldContain("HotSpot"); 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=./sample.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=./sample.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 }