SharedStrings.java revision 11833:1cbffa2beba6
1/* 2 * Copyright (c) 2015, 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 * @summary Check to make sure that shared strings in the bootstrap CDS archive 27 * are actually shared 28 * Feature support: G1GC only, compressed oops/kptrs, 64-bit os, not on windows 29 * @requires (sun.arch.data.model != "32") & (os.family != "windows") 30 * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true) 31 * @requires vm.gc.G1 32 * @library /test/lib 33 * @modules java.base/jdk.internal.misc 34 * java.management 35 * @build SharedStringsWb sun.hotspot.WhiteBox 36 * @run main ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox 37 * @run main SharedStrings 38 */ 39import jdk.test.lib.process.ProcessTools; 40import jdk.test.lib.process.OutputAnalyzer; 41 42public class SharedStrings { 43 public static void main(String[] args) throws Exception { 44 boolean test_runtime = true; 45 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 46 "-XX:+UnlockDiagnosticVMOptions", 47 "-XX:SharedArchiveFile=./SharedStrings.jsa", 48 "-XX:+UseG1GC", 49 "-XX:+UseCompressedOops", 50 "-XX:+PrintSharedSpaces", 51 // Needed for bootclasspath match, for CDS to work with WhiteBox API 52 "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), 53 "-Xshare:dump"); 54 55 OutputAnalyzer dumpOutput = new OutputAnalyzer(pb.start()); 56 try { 57 dumpOutput.shouldContain("Loading classes to share"); 58 dumpOutput.shouldContain("Shared string table stats"); 59 dumpOutput.shouldHaveExitValue(0); 60 } catch (RuntimeException e) { 61 if (dumpOutput.getOutput().indexOf("Shared strings are excluded") != -1 || 62 dumpOutput.getOutput().indexOf("Cannot dump shared archive") != -1) { 63 test_runtime = false; 64 } else { 65 throw new RuntimeException("Unexpected failure"); 66 } 67 } 68 69 if (test_runtime) { 70 pb = ProcessTools.createJavaProcessBuilder( 71 "-XX:+UnlockDiagnosticVMOptions", 72 "-XX:SharedArchiveFile=./SharedStrings.jsa", 73 // these are required modes for shared strings 74 "-XX:+UseCompressedOops", "-XX:+UseG1GC", 75 // needed for access to white box test API 76 "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), 77 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", 78 "-Xshare:on", "-showversion", "SharedStringsWb"); 79 80 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 81 82 try { 83 output.shouldContain("sharing"); 84 output.shouldHaveExitValue(0); 85 } catch (RuntimeException e) { 86 output.shouldContain("Unable to use shared archive"); 87 output.shouldHaveExitValue(1); 88 } 89 } 90 } 91} 92