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 8259275
28  * @summary VM should not crash during CDS dump and run time when a lambda
29  *          expression references an old version of class.
30  * @requires vm.cds
31  * @library /test/lib
32  * @compile test-classes/OldClass.jasm
33  * @compile test-classes/LambdaWithOldClassApp.java
34  * @run driver LambdaWithOldClass
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 LambdaWithOldClass {
42 
43     public static void main(String[] args) throws Exception {
44         String mainClass = "LambdaWithOldClassApp";
45         String namePrefix = "lambdawitholdclass";
46         JarBuilder.build(namePrefix, mainClass, "OldClass", "TestInterface");
47 
48         String appJar = TestCommon.getTestJar(namePrefix + ".jar");
49         String classList = namePrefix + ".list";
50         String archiveName = namePrefix + ".jsa";
51 
52         // dump class list
53         CDSTestUtils.dumpClassList(classList, "-cp", appJar, mainClass);
54 
55         // create archive with the class list
56         CDSOptions opts = (new CDSOptions())
57             .addPrefix("-XX:ExtraSharedClassListFile=" + classList,
58                        "-cp", appJar,
59                        "-Xlog:class+load,cds")
60             .setArchiveName(archiveName);
61         CDSTestUtils.createArchiveAndCheck(opts);
62 
63         // run with archive
64         CDSOptions runOpts = (new CDSOptions())
65             .addPrefix("-cp", appJar, "-Xlog:class+load,cds=debug")
66             .setArchiveName(archiveName)
67             .setUseVersion(false)
68             .addSuffix(mainClass);
69         OutputAnalyzer output = CDSTestUtils.runWithArchive(runOpts);
70         output.shouldContain("[class,load] LambdaWithOldClassApp source: shared objects file")
71           // FIXME:leyden-premain : we disabled archived Lambda proxy classes due to JDK-8307468
72           //  .shouldMatch(".class.load. LambdaWithOldClassApp[$][$]Lambda.*/0x.*source:.*shared objects file")
73               .shouldHaveExitValue(0);
74     }
75 }