1 /*
 2  * Copyright (c) 2021, 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 8274944 8276184
28  * @summary VM should not crash during CDS dump when a lambda proxy class
29  *          contains an old version of interface.
30  * @requires vm.cds
31  * @library /test/lib
32  * @compile test-classes/OldProvider.jasm
33  * @compile test-classes/LambdaContainsOldInfApp.java
34  * @run driver LambdaContainsOldInf
35  */
36 
37 import jdk.test.lib.cds.CDSOptions;
38 import jdk.test.lib.cds.CDSTestUtils;
39 import jdk.test.lib.process.OutputAnalyzer;
40 
41 public class LambdaContainsOldInf {
42 
43     public static void main(String[] args) throws Exception {
44         String mainClass = "LambdaContainsOldInfApp";
45         String namePrefix = "lambdacontainsoldinf";
46         JarBuilder.build(namePrefix, mainClass, "OldProvider");
47 
48         String appJar = TestCommon.getTestJar(namePrefix + ".jar");
49         String classList = namePrefix + ".list";
50         String archiveName = namePrefix + ".jsa";
51 
52         String[] mainArgs = { "dummy", "addLambda" };
53 
54         for (String mainArg : mainArgs) {
55             // dump class list
56             CDSTestUtils.dumpClassList(classList, "-cp", appJar, mainClass, mainArg);
57 
58             // create archive with the class list
59             CDSOptions opts = (new CDSOptions())
60                 .addPrefix("-XX:ExtraSharedClassListFile=" + classList,
61                            "-cp", appJar,
62                            "-Xlog:class+load,cds")
63                 .setArchiveName(archiveName);
64             OutputAnalyzer output = CDSTestUtils.createArchiveAndCheck(opts);
65             TestCommon.checkExecReturn(output, 0, true,
66                                        "Skipping OldProvider: Old class has been linked");
67             output.shouldMatch("Skipping.LambdaContainsOldInfApp[$][$]Lambda.*0x.*:.*Old.class.has.been.linked");
68 
69             // run with archive
70             CDSOptions runOpts = (new CDSOptions())
71                 .addPrefix("-cp", appJar, "-Xlog:class+load,cds=debug")
72                 .setArchiveName(archiveName)
73                 .setUseVersion(false)
74                 .addSuffix(mainClass)
75                 .addSuffix(mainArg);
76             output = CDSTestUtils.runWithArchive(runOpts);
77             TestCommon.checkExecReturn(output, 0, true,
78                 "[class,load] LambdaContainsOldInfApp source: shared objects file");
79             output.shouldMatch(".class.load. OldProvider.source:.*lambdacontainsoldinf.jar")
80                   .shouldMatch(".class.load. LambdaContainsOldInfApp[$][$]Lambda.*/0x.*source:.*LambdaContainsOldInf");
81        }
82     }
83 }