1 /* 2 * Copyright (c) 2021, 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 /* 26 * @test 27 * @summary test -XX:+PrintSharedArchiveAndExit output for shared class. 28 * @comment the code is mostly copied from HelloCustom 29 * @requires vm.cds 30 * @requires vm.cds.custom.loaders 31 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 32 * @compile test-classes/HelloUnload.java test-classes/CustomLoadee.java 33 * @build sun.hotspot.WhiteBox jdk.test.lib.classloader.ClassUnloadCommon 34 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar HelloUnload 35 * jdk.test.lib.classloader.ClassUnloadCommon 36 * jdk.test.lib.classloader.ClassUnloadCommon$1 37 * jdk.test.lib.classloader.ClassUnloadCommon$TestFailure 38 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello_custom.jar CustomLoadee 39 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox 40 * @run driver PrintSharedArchiveAndExit 41 */ 42 43 import jdk.test.lib.process.OutputAnalyzer; 44 import jdk.test.lib.helpers.ClassFileInstaller; 45 import sun.hotspot.WhiteBox; 46 47 public class PrintSharedArchiveAndExit { 48 public static void main(String[] args) throws Exception { 49 run(); 50 } 51 public static void run(String... extra_runtime_args) throws Exception { 52 String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); 53 String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; 54 55 String appJar = ClassFileInstaller.getJarPath("hello.jar"); 56 String customJarPath = ClassFileInstaller.getJarPath("hello_custom.jar"); 57 58 // Dump the archive 59 String classlist[] = new String[] { 60 "HelloUnload", 61 "java/lang/Object id: 1", 62 "java/lang/IdentityObject id: 2", 63 "CustomLoadee id: 3 super: 1 interfaces: 2 source: " + customJarPath 64 }; 65 66 OutputAnalyzer output; 67 TestCommon.testDump(appJar, classlist, 68 // command-line arguments ... 69 use_whitebox_jar); 70 71 output = TestCommon.exec(appJar, 72 TestCommon.concat(extra_runtime_args, 73 // command-line arguments ... 74 use_whitebox_jar, 75 "-XX:+UnlockDiagnosticVMOptions", 76 "-XX:+WhiteBoxAPI", 77 "-XX:+PrintSharedArchiveAndExit", 78 "HelloUnload", customJarPath, "true", "true")); 79 output.shouldMatch(".* archive version \\d+") 80 .shouldContain("java.lang.Object boot_loader") 81 .shouldContain("HelloUnload app_loader") 82 .shouldContain("CustomLoadee unregistered_loader") 83 .shouldContain("Shared Builtin Dictionary") 84 .shouldContain("Shared Unregistered Dictionary") 85 .shouldMatch("Number of shared symbols: \\d+") 86 .shouldMatch("Number of shared strings: \\d+") 87 .shouldMatch("VM version: .*"); 88 } 89 }