1 /*
 2  * Copyright (c) 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 8293336
28  * @summary Test for archiving resolved invokedynamic call sites (with JavaC)
29  * @requires vm.cds.write.archived.java.heap
30  * @modules java.base/sun.invoke.util java.logging
31  * @library /test/jdk/lib/testlibrary /test/lib
32  *          /test/hotspot/jtreg/runtime/cds/appcds
33  *          /test/hotspot/jtreg/runtime/cds/appcds/test-classes
34  * @build IndyAndJavac
35  * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar Dummy
36  * @run driver IndyAndJavac
37  */
38 
39 
40 import java.io.FileWriter;
41 
42 import jdk.test.lib.helpers.ClassFileInstaller;
43 
44 public class IndyAndJavac extends IndyTestBase {
45     static final String appJar = ClassFileInstaller.getJarPath("app.jar");
46     static final String mainClass_javac = "com.sun.tools.javac.Main";
47 
48     // Force some tests to be disabled during development.
49     static String forceSkip = null;
50 
51     public static void main(String[] args) throws Exception {
52         setup(forceSkip, appJar);
53         testJavaC();
54     }
55 
56     static void testJavaC() throws Exception {
57         String sourceFile = "Test.java";
58         try (FileWriter fw = new FileWriter(sourceFile)) {
59             fw.write("public class Test {\n");
60             for (int i = 0; i < 3000; i++) {
61                 fw.write("    private static final int arr_" + i + "[] = {1, 2, 3};\n");
62                 fw.write("    private static int method_" + i + "() { return arr_" + i + "[1];}\n");
63             }
64             fw.write("}\n");
65         }
66         test("Use javac with archived MethodTypes and LambdaForms", mainClass_javac, sourceFile, sourceFile,
67              RUN_STATIC |
68            //RUN_BENCH |
69              RUN_AOT
70              );
71         checkExec(null, /*lambdaFormsMustBeArchived*/false); // Some lambda forms are generated because we don't cache invokedynamic for lambda proxies yet
72     }
73 }
74 
75 class Dummy {
76 
77 }