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  * @test
26  * @bug 8285914
27  * @summary A lambda proxy class should not be archived if its nest host implements an
28  *          old (with major version < JDK_6 (50)) interface which cannot be verified during dump time.
29  * @requires vm.cds
30  * @library /test/lib
31  * @compile test-classes/OldInf.jasm test-classes/ChildOldInf.java test-classes/NestHostOldInfApp.java
32  * @run driver NestHostOldInf
33  */
34 
35 import jdk.test.lib.cds.CDSTestUtils;
36 import jdk.test.lib.process.OutputAnalyzer;
37 
38 public class NestHostOldInf {
39 
40     public static void main(String[] args) throws Exception {
41         String mainClass = "NestHostOldInfApp";
42         String namePrefix = "oldsuperinf";
43         String appClasses[] = TestCommon.list("OldInf", "ChildOldInf", "ChildOldInf$InnerChild", mainClass);
44         JarBuilder.build(namePrefix, appClasses);
45 
46         String appJar = TestCommon.getTestJar(namePrefix + ".jar");
47         String archiveName = namePrefix + ".jsa";
48 
49         boolean dynamicMode = CDSTestUtils.DYNAMIC_DUMP;
50 
51         // create archive with class list
52         OutputAnalyzer output = TestCommon.dump(appJar, appClasses, "-Xlog:class+load,cds=debug,verification=trace",
53                                                 "-XX:-PreloadSharedClasses");
54         TestCommon.checkExecReturn(output, 0,
55                                    dynamicMode ? true : false,
56                                    "Skipping OldInf: Old class has been linked",
57                                    "Skipping ChildOldInf: Old class has been linked");
58 
59         // run with archive
60         TestCommon.run(
61             "-cp", appJar,
62             "-Xlog:class+load,cds=debug,verification=trace",
63             mainClass)
64           .assertNormalExit(out -> {
65               out.shouldContain("Verifying class OldInf with old format")
66                  .shouldContain("Verifying class ChildOldInf with new format")
67                  .shouldContain("ChildOldInf$InnerChild source: shared objects file")
68                  .shouldContain("Hello from InnerChild doTest");
69               if (!dynamicMode) {
70                   out.shouldContain("OldInf source: shared objects file")
71                      .shouldContain("ChildOldInf source: shared objects file");
72               } else {
73                   // Old classes were already linked before dynamic dump happened,
74                   // so they couldn't be archived.
75                   out.shouldMatch(".class.load.*OldInf source:.*oldsuperinf.jar")
76                      .shouldMatch(".class.load.*ChildOldInf source:.*oldsuperinf.jar");
77               }
78           });
79     }
80 }