1 /* 2 * Copyright (c) 2023, 2024, 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 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 OldInf 35 * @build IndyMiscTests 36 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar 37 * LambdaWithOldIntf OldInf 38 * LambdaWithClinitInf ClinitInf 39 * @run driver IndyMiscTests 40 */ 41 42 43 // NOTE: to run a subset of the tests, use something like 44 // 45 // jtreg .... -vmoptions:-DIndyMiscTests.test.only='(1)|(2)' \ 46 // -vmoptions:-DIndyMiscTests.test.skip='2' IndyMiscTests.java 47 // 48 // A regexp can be specified in these two properties. Note that the specified regexp must be a full match. 49 // E.g., -DIndyMiscTests.test.only='1.*' matches "1" and "12", but does NOT match "21". 50 // (Search for ")$" in the code below) 51 // 52 // Also, some tests may be forced to be skipped. To run them, edit the variable forceSkip below. 53 54 import jdk.test.lib.helpers.ClassFileInstaller; 55 56 public class IndyMiscTests extends IndyTestBase { 57 static final String appJar = ClassFileInstaller.getJarPath("app.jar"); 58 static final String mainClass_LambdaWithOldIntf = LambdaWithOldIntf.class.getName(); 59 static final String mainClass_LambdaWithClinitInf = LambdaWithClinitInf.class.getName(); 60 61 // Edit the following to disable some tests during development. 62 static String forceSkip = null; 63 64 public static void main(String[] args) throws Exception { 65 setup(forceSkip, appJar); 66 67 // ------------------------------------------------------------ 68 test("LambdaWithOldIntf", mainClass_LambdaWithOldIntf, ""); 69 checkExec("xxMy StringXX"); 70 71 // ------------------------------------------------------------ 72 test("LambdaWithClinitInf", mainClass_LambdaWithClinitInf, ""); 73 checkExec("xxMy String2XX"); 74 staticDumpOutput.shouldContain("Cannot aot-resolve Lambda proxy of interface type ClinitInf (has <cilint>)"); 75 } 76 } 77 78 79 class LambdaWithOldIntf { 80 public static void main(String args[]) throws Exception { 81 test(() -> "My String"); 82 } 83 84 static void test(OldInf i) { 85 System.out.print("OUTPUT = xx"); 86 System.out.print(i.doit()); 87 System.out.println("XX"); 88 } 89 } 90 91 interface ClinitInf { 92 String bar = LambdaWithClinitInf.foo; 93 public String doit(); 94 } 95 96 class LambdaWithClinitInf { 97 static String foo = "1"; 98 99 public static void main(String args[]) throws Exception { 100 foo = "2"; 101 test(() -> "My String"); 102 } 103 104 static void test(ClinitInf i) { 105 System.out.print("OUTPUT = xx"); 106 System.out.print(i.doit()); 107 System.out.print(ClinitInf.bar); 108 System.out.println("XX"); 109 } 110 }