|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 The base archive used for dynamic dump is not the same as the one |
| 28 | + * used during run time. With -Xshare:on, VM will exit with en error message. |
| 29 | + * @requires vm.cds |
| 30 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes |
| 31 | + * @build Hello |
| 32 | + * @build sun.hotspot.WhiteBox |
| 33 | + * @run driver ClassFileInstaller -jar hello.jar Hello |
| 34 | + * @run driver ClassFileInstaller sun.hotspot.WhiteBox |
| 35 | + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MismatchedBaseArchive |
| 36 | + */ |
| 37 | + |
| 38 | +public class MismatchedBaseArchive extends DynamicArchiveTestBase { |
| 39 | + public static void main(String[] args) throws Exception { |
| 40 | + createBaseArchive(); |
| 41 | + runTest(MismatchedBaseArchive::testDefaultBase); |
| 42 | + runTest(MismatchedBaseArchive::testCustomBase); |
| 43 | + } |
| 44 | + |
| 45 | + static String helloBaseArchive = getNewArchiveName("base-with-hello"); |
| 46 | + static String appJar = ClassFileInstaller.getJarPath("hello.jar"); |
| 47 | + static String mainClass = "Hello"; |
| 48 | + |
| 49 | + static void createBaseArchive() throws Exception { |
| 50 | + TestCommon.dumpBaseArchive(helloBaseArchive, |
| 51 | + "-Xlog:cds", |
| 52 | + "-cp", appJar, mainClass); |
| 53 | + } |
| 54 | + |
| 55 | + // (1) Test with default base archive + top archive |
| 56 | + static void testDefaultBase() throws Exception { |
| 57 | + String topArchiveName = getNewArchiveName("top"); |
| 58 | + doTest(null, topArchiveName); |
| 59 | + } |
| 60 | + |
| 61 | + // (2) Test with custom base archive + top archive |
| 62 | + static void testCustomBase() throws Exception { |
| 63 | + String topArchiveName = getNewArchiveName("top2"); |
| 64 | + String baseArchiveName = getNewArchiveName("base"); |
| 65 | + TestCommon.dumpBaseArchive(baseArchiveName); |
| 66 | + doTest(baseArchiveName, topArchiveName); |
| 67 | + } |
| 68 | + |
| 69 | + private static void doTest(String baseArchiveName, String topArchiveName) throws Exception { |
| 70 | + dump2(baseArchiveName, topArchiveName, |
| 71 | + "-Xlog:cds", |
| 72 | + "-Xlog:cds+dynamic=debug", |
| 73 | + "-cp", appJar, mainClass) |
| 74 | + .assertNormalExit(output -> { |
| 75 | + output.shouldContain("Buffer-space to target-space delta") |
| 76 | + .shouldContain("Written dynamic archive 0x"); |
| 77 | + }); |
| 78 | + |
| 79 | + run2(helloBaseArchive, topArchiveName, |
| 80 | + "-Xlog:class+load", |
| 81 | + "-Xlog:cds+dynamic=debug,cds=debug", |
| 82 | + "-cp", appJar, mainClass) |
| 83 | + .assertAbnormalExit(output -> { |
| 84 | + output.shouldContain("Dynamic archive cannot be used: static archive header checksum verification failed.") |
| 85 | + .shouldHaveExitValue(1); |
| 86 | + }); |
| 87 | + |
| 88 | + } |
| 89 | +} |
0 commit comments