1 /*
 2  * Copyright (c) 2020, 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  * @summary Archive lambda proxy class is in the base archive. The lambda proxy
28  *          class should be loaded from the base archive during runtime.
29  *
30  * @requires vm.cds
31  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
32  * @build LambHello
33  * @build jdk.test.whitebox.WhiteBox
34  * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar lambhello.jar LambHello
35  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
36  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. LambdaInBaseArchive
37  */
38 
39 import jdk.test.lib.cds.CDSOptions;
40 import jdk.test.lib.cds.CDSTestUtils;
41 import jdk.test.lib.helpers.ClassFileInstaller;
42 
43 public class LambdaInBaseArchive extends DynamicArchiveTestBase {
44     public static void main(String[] args) throws Exception {
45         createBaseArchive();
46         runTest(LambdaInBaseArchive::testCustomBase);
47     }
48 
49     static String helloBaseArchive = getNewArchiveName("base-with-hello");
50     static String appJar = ClassFileInstaller.getJarPath("lambhello.jar");
51     static String mainClass = "LambHello";
52     static String classList = "lambhello.list";
53 
54     static void createBaseArchive() throws Exception {
55         // dump class list
56         CDSTestUtils.dumpClassList(classList, "-cp", appJar, mainClass);
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(helloBaseArchive);
64         CDSTestUtils.createArchiveAndCheck(opts);
65     }
66 
67     // Test with custom base archive + top archive
68     static void testCustomBase() throws Exception {
69         String topArchiveName = getNewArchiveName("top2");
70         doTest(helloBaseArchive, topArchiveName);
71     }
72 
73     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
74         dump2(baseArchiveName, topArchiveName,
75              "-Xlog:class+load,cds,cds+dynamic=debug",
76              "-cp", appJar, mainClass)
77             .assertNormalExit(output -> {
78                     output.shouldContain("Written dynamic archive 0x");
79                 });
80 
81         run2(baseArchiveName, topArchiveName,
82             "-Xlog:class+load,cds+dynamic=debug,cds=debug",
83             "-cp", appJar, mainClass)
84             .assertNormalExit(output -> {
85                 // FIXME:leyden-premain : we disabled archived Lambda proxy classes due to JDK-8307468
86                 // output.shouldContain("LambHello source: shared objects file")
87                    // .shouldMatch("class.load.*LambHello[$][$]Lambda.*0x.*source:.shared.objects.file")
88                    // .shouldNotMatch("class.load.*LambHello[$][$]Lambda.*0x.*source:.shared.objects.file.*(top)");
89                 });
90 
91     }
92 }