|
| 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 | + * @bug 8261860 |
| 28 | + * @summary VM should not crash if a lambda proxy class is created during |
| 29 | + * shutdown and its nest host is not linked. |
| 30 | + * @requires vm.cds |
| 31 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds |
| 32 | + * /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes |
| 33 | + * @build LambdaProxyDuringShutdownApp sun.hotspot.WhiteBox LambdaVerification |
| 34 | + * @run driver ClassFileInstaller -jar lambda_proxy_shutdown.jar LambdaVerification |
| 35 | + * LambdaProxyDuringShutdownApp MyShutdown Outer Outer$Inner |
| 36 | + * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox |
| 37 | + * @run driver ClassFileInstaller sun.hotspot.WhiteBox |
| 38 | + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. LambdaProxyDuringShutdown |
| 39 | + */ |
| 40 | + |
| 41 | +public class LambdaProxyDuringShutdown extends DynamicArchiveTestBase { |
| 42 | + public static void main(String[] args) throws Exception { |
| 43 | + runTest(LambdaProxyDuringShutdown::test); |
| 44 | + } |
| 45 | + |
| 46 | + static void test() throws Exception { |
| 47 | + String topArchiveName = getNewArchiveName(); |
| 48 | + String appJar = ClassFileInstaller.getJarPath("lambda_proxy_shutdown.jar"); |
| 49 | + String mainClass = "LambdaProxyDuringShutdownApp"; |
| 50 | + String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); |
| 51 | + String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; |
| 52 | + String appOutput = "Hello from Inner"; |
| 53 | + |
| 54 | + dump(topArchiveName, |
| 55 | + "-XX:+UnlockDiagnosticVMOptions", |
| 56 | + "-XX:+WhiteBoxAPI", |
| 57 | + "-Xlog:class+load=debug,cds=debug,cds+dynamic=info", |
| 58 | + use_whitebox_jar, |
| 59 | + "-cp", appJar, mainClass) |
| 60 | + .assertNormalExit(output -> { |
| 61 | + // Nest host should be skipped since it is not in the linked state. |
| 62 | + output.shouldContain("Skipping Outer: Not linked") |
| 63 | + // Lambda proxy is loaded normally. |
| 64 | + .shouldMatch("class.load.*Outer[$]Inner[$][$]Lambda[$].*0x.*source:.Outer") |
| 65 | + .shouldContain(appOutput) |
| 66 | + .shouldHaveExitValue(0); |
| 67 | + }); |
| 68 | + |
| 69 | + run(topArchiveName, |
| 70 | + "-XX:+UnlockDiagnosticVMOptions", |
| 71 | + "-XX:+WhiteBoxAPI", |
| 72 | + use_whitebox_jar, |
| 73 | + "-Xlog:class+load=debug", |
| 74 | + "-cp", appJar, mainClass, "run") |
| 75 | + .assertNormalExit(output -> { |
| 76 | + // Only the Inner class is loaded from the dynamic archive. |
| 77 | + // The nest host (Outer) and its lambda proxy are not loaded |
| 78 | + // from the dynamic archive. |
| 79 | + output.shouldMatch("class.load.*Outer.source:.*lambda_proxy_shutdown.jar") |
| 80 | + .shouldMatch("class.load.*Outer[$]Inner[$][$]Lambda[$].*0x.*source:.Outer") |
| 81 | + .shouldMatch("class.load. Outer[$]Inner.source:.*shared.*objects.*file.*(top)") |
| 82 | + .shouldContain(appOutput) |
| 83 | + .shouldHaveExitValue(0); |
| 84 | + }); |
| 85 | + } |
| 86 | +} |
0 commit comments