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 /testlibrary 29 * @modules java.base/jdk.internal.misc 30 * java.management 31 */ 32 33 import jdk.test.lib.*; 34 35 public 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 "-Xlog:gc+heap+coops=debug", 89 "-version"); 90 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 91 output.shouldContain("HeapBaseMinAddress must be at least"); 92 output.shouldHaveExitValue(0); 93 } 94 95 public static void sharingTest() throws Exception { 96 // Test small heaps 97 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 98 "-XX:+UnlockDiagnosticVMOptions", 99 "-XX:SharedArchiveFile=./CompressedClassPointers.jsa", 100 "-Xmx128m", 101 "-XX:SharedBaseAddress=8g", 102 "-XX:+PrintCompressedOopsMode", 103 "-XX:+VerifyBeforeGC", 104 "-Xshare:dump"); 105 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 106 try { 107 output.shouldContain("Loading classes to share"); 108 output.shouldHaveExitValue(0); 109 110 pb = ProcessTools.createJavaProcessBuilder( 111 "-XX:+UnlockDiagnosticVMOptions", 112 "-XX:SharedArchiveFile=./CompressedClassPointers.jsa", 113 "-Xmx128m", 114 "-XX:SharedBaseAddress=8g", 115 "-XX:+PrintCompressedOopsMode", 116 "-Xshare:on", 117 "-version"); 118 output = new OutputAnalyzer(pb.start()); 119 output.shouldContain("sharing"); 120 output.shouldHaveExitValue(0); 121 122 } catch (RuntimeException e) { 123 output.shouldContain("Unable to use shared archive"); 124 output.shouldHaveExitValue(1); 125 } 126 } 127 128 public static void main(String[] args) throws Exception { 129 if (!Platform.is64bit()) { 130 // Can't test this on 32 bit, just pass 131 System.out.println("Skipping test on 32bit"); 132 return; 133 } 134 // Solaris 10 can't mmap compressed oops space without a base 135 if (Platform.isSolaris()) { 136 String name = System.getProperty("os.version"); 137 if (name.equals("5.10")) { 138 System.out.println("Skipping test on Solaris 10"); 139 return; 140 } 141 } 142 smallHeapTest(); 143 smallHeapTestWith3G(); 144 largeHeapTest(); 145 largePagesTest(); 146 heapBaseMinAddressTest(); 147 sharingTest(); 148 } 149 }