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 /testlibrary /test/lib 33 * @modules java.base/jdk.internal.misc 34 * java.management 35 * @build SharedStringsWb SharedStrings ClassFileInstaller sun.hotspot.WhiteBox 36 * @run main ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox 37 * @run main SharedStrings 38 */ 39 import jdk.test.lib.*; 40 41 public class SharedStrings { 42 public static void main(String[] args) throws Exception { 43 boolean test_runtime = true; 44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 45 "-XX:+UnlockDiagnosticVMOptions", 46 "-XX:SharedArchiveFile=./SharedStrings.jsa", 47 "-XX:+UseG1GC", 48 "-XX:+UseCompressedOops", 49 "-XX:+PrintSharedSpaces", 50 // Needed for bootclasspath match, for CDS to work with WhiteBox API 51 "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), 52 "-Xshare:dump"); 53 54 OutputAnalyzer dumpOutput = new OutputAnalyzer(pb.start()); 55 try { 56 dumpOutput.shouldContain("Loading classes to share"); 57 dumpOutput.shouldContain("Shared string table stats"); 58 dumpOutput.shouldHaveExitValue(0); 59 } catch (RuntimeException e) { 60 if (dumpOutput.getOutput().indexOf("Shared strings are excluded") != -1 || 61 dumpOutput.getOutput().indexOf("Cannot dump shared archive") != -1) { 62 test_runtime = false; 63 } else { 64 throw new RuntimeException("Unexpected failure"); 65 } 66 } 67 68 if (test_runtime) { 69 pb = ProcessTools.createJavaProcessBuilder( 70 "-XX:+UnlockDiagnosticVMOptions", 71 "-XX:SharedArchiveFile=./SharedStrings.jsa", 72 // these are required modes for shared strings 73 "-XX:+UseCompressedOops", "-XX:+UseG1GC", 74 // needed for access to white box test API 75 "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), 76 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", 77 "-Xshare:on", "-showversion", "SharedStringsWb"); 78 79 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 80 81 try { 82 output.shouldContain("sharing"); 83 output.shouldHaveExitValue(0); 84 } catch (RuntimeException e) { 85 output.shouldContain("Unable to use shared archive"); 86 output.shouldHaveExitValue(1); 87 } 88 } 89 } 90 }