1 /*
 2  * Copyright (c) 2022, 2023, 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 8285914
28  * @summary A lambda proxy class should not be archived if its nest host implements an
29  *          old (with major version < JDK_6 (50)) interface which cannot be verified during dump time.
30  * @requires vm.cds
31  * @requires vm.cds.custom.loaders
32  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
33  * @compile ../test-classes/OldInf.jasm ../test-classes/ChildOldInf.java ../test-classes/NestHostOldInfApp.java
34  * @build jdk.test.whitebox.WhiteBox
35  * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar oldclassapp.jar NestHostOldInfApp OldInf ChildOldInf ChildOldInf$InnerChild
36  * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
37  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar NestHostOldInf
38  */
39 
40 import java.io.File;
41 import jdk.test.lib.cds.CDSTestUtils;
42 import jdk.test.lib.process.OutputAnalyzer;
43 import jdk.test.lib.helpers.ClassFileInstaller;
44 
45 public class NestHostOldInf extends DynamicArchiveTestBase {
46     private static final String ARCHIVE_NAME = CDSTestUtils.getOutputFileName("oldclass-top.jsa");
47     private static String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
48     private static String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
49     private static String appJar = ClassFileInstaller.getJarPath("oldclassapp.jar");
50     private static String mainAppClass = "NestHostOldInfApp";
51 
52     public static void main(String[] args) throws Exception {
53         runTest(NestHostOldInf::doTest);
54     }
55 
56     private static void doTest() throws Exception {
57         dump(ARCHIVE_NAME,
58              use_whitebox_jar,
59              "-XX:+UnlockDiagnosticVMOptions",
60              "-XX:+WhiteBoxAPI",
61              "-Xlog:cds",
62              "-Xlog:cds+dynamic=debug",
63              "-cp", appJar,
64              mainAppClass)
65              .assertNormalExit(output -> {
66                  output.shouldContain("Written dynamic archive 0x")
67                        .shouldContain("Skipping ChildOldInf: Old class has been linked")
68                        .shouldContain("Skipping OldInf: Old class has been linked")
69                        .shouldHaveExitValue(0);
70                  });
71 
72         run(ARCHIVE_NAME,
73             use_whitebox_jar,
74             "-XX:+UnlockDiagnosticVMOptions",
75             "-XX:+WhiteBoxAPI",
76             "-Xlog:class+load",
77             "-Xlog:cds=debug",
78             "-Xlog:cds+dynamic=info",
79             "-cp", appJar,
80             mainAppClass)
81             .assertNormalExit(output -> {
82                 output.shouldHaveExitValue(0)
83                       .shouldMatch(".class.load. OldInf source:.*oldclassapp.jar")
84                       .shouldMatch(".class.load. ChildOldInf source:.*oldclassapp.jar")
85                       .shouldContain("ChildOldInf$InnerChild source: shared objects file (top)")
86                       .shouldMatch(".class.load. ChildOldInf[$]InnerChild[$][$]Lambda.*/0x.*source:.ChildOldInf");
87                 });
88     }
89 }