|
| 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 Hello World test for dynamic archive with custom loader |
| 28 | + * @requires vm.cds |
| 29 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes |
| 30 | + * @build HelloUnload CustomLoadee jdk.test.lib.classloader.ClassUnloadCommon |
| 31 | + * @build sun.hotspot.WhiteBox |
| 32 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello.jar HelloUnload |
| 33 | + * jdk.test.lib.classloader.ClassUnloadCommon |
| 34 | + * jdk.test.lib.classloader.ClassUnloadCommon$1 |
| 35 | + * jdk.test.lib.classloader.ClassUnloadCommon$TestFailure |
| 36 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar hello_custom.jar CustomLoadee |
| 37 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox |
| 38 | + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar PrintSharedArchiveAndExit |
| 39 | + */ |
| 40 | + |
| 41 | +import java.io.File; |
| 42 | +import jdk.test.lib.cds.CDSTestUtils; |
| 43 | +import jdk.test.lib.process.OutputAnalyzer; |
| 44 | +import jdk.test.lib.helpers.ClassFileInstaller; |
| 45 | + |
| 46 | +public class PrintSharedArchiveAndExit extends DynamicArchiveTestBase { |
| 47 | + private static final String ARCHIVE_NAME = CDSTestUtils.getOutputFileName("top.jsa"); |
| 48 | + |
| 49 | + public static void main(String... args) throws Exception { |
| 50 | + runTest(PrintSharedArchiveAndExit::testPrtNExit); |
| 51 | + } |
| 52 | + |
| 53 | + public static void testPrtNExit() throws Exception { |
| 54 | + String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); |
| 55 | + String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; |
| 56 | + String appJar = ClassFileInstaller.getJarPath("hello.jar"); |
| 57 | + String customJarPath = ClassFileInstaller.getJarPath("hello_custom.jar"); |
| 58 | + String mainAppClass = "HelloUnload"; |
| 59 | + |
| 60 | + dump(ARCHIVE_NAME, |
| 61 | + use_whitebox_jar, |
| 62 | + "-XX:+UnlockDiagnosticVMOptions", |
| 63 | + "-XX:+WhiteBoxAPI", |
| 64 | + "-Xlog:cds", |
| 65 | + "-Xlog:cds+dynamic=debug", |
| 66 | + "-cp", appJar, |
| 67 | + mainAppClass, customJarPath, "false", "false") |
| 68 | + .assertNormalExit(output -> { |
| 69 | + output.shouldContain("Written dynamic archive 0x") |
| 70 | + .shouldNotContain("klasses.*=.*CustomLoadee") |
| 71 | + .shouldHaveExitValue(0); |
| 72 | + }); |
| 73 | + |
| 74 | + run(ARCHIVE_NAME, |
| 75 | + use_whitebox_jar, |
| 76 | + "-XX:+UnlockDiagnosticVMOptions", |
| 77 | + "-XX:+WhiteBoxAPI", |
| 78 | + "-Xlog:class+load", |
| 79 | + "-Xlog:cds=debug", |
| 80 | + "-Xlog:cds+dynamic=info", |
| 81 | + "-cp", appJar, |
| 82 | + "-XX:+PrintSharedArchiveAndExit", |
| 83 | + mainAppClass, customJarPath, "false", "true") |
| 84 | + .assertNormalExit(output -> { |
| 85 | + output.shouldHaveExitValue(0) |
| 86 | + .shouldMatch("Base archive name: .*.jsa") // given name ends with .jsa, maynot default name. |
| 87 | + .shouldMatch("Dynamic archive name: .*" + ARCHIVE_NAME) |
| 88 | + .shouldMatch("Base archive version \\d+") |
| 89 | + .shouldContain("java.lang.Object boot_loader") |
| 90 | + .shouldContain("HelloUnload app_loader") |
| 91 | + .shouldContain("CustomLoadee unregistered_loader") |
| 92 | + .shouldContain("Shared Builtin Dictionary") |
| 93 | + .shouldContain("Shared Unregistered Dictionary") |
| 94 | + .shouldMatch("Number of shared symbols: \\d+") |
| 95 | + .shouldMatch("Number of shared strings: \\d+") |
| 96 | + .shouldMatch("VM version: .*"); |
| 97 | + }); |
| 98 | + } |
| 99 | +} |
0 commit comments