1 /* 2 * Copyright (c) 2022, 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 8290417 28 * @summary CDS cannot archive lambda proxy with useImplMethodHandle 29 * @requires vm.cds 30 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes 31 * @build pkg1.BaseWithProtectedMethod 32 * @build pkg2.Child 33 * @build LambdaWithUseImplMethodHandleApp 34 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar test.jar pkg1.BaseWithProtectedMethod pkg2.Child LambdaWithUseImplMethodHandleApp 35 * @run driver LambdaWithUseImplMethodHandle 36 */ 37 38 import jdk.test.lib.cds.CDSOptions; 39 import jdk.test.lib.cds.CDSTestUtils; 40 import jdk.test.lib.helpers.ClassFileInstaller; 41 42 public class LambdaWithUseImplMethodHandle { 43 44 // See pkg2/Child.jcod for details about the condition that triggers JDK-8290417 45 public static void main(String[] args) throws Exception { 46 String appJar = ClassFileInstaller.getJarPath("test.jar"); 47 String mainClass = "LambdaWithUseImplMethodHandleApp"; 48 String expectedMsg = "Called BaseWithProtectedMethod::protectedMethod"; 49 String classList = "LambdaWithUseImplMethodHandle.list"; 50 String archiveName = TestCommon.getNewArchiveName(); 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 .setArchiveName(archiveName); 60 CDSTestUtils.createArchiveAndCheck(opts); 61 62 // run with archive 63 CDSOptions runOpts = (new CDSOptions()) 64 .addPrefix("-cp", appJar) 65 .setArchiveName(archiveName) 66 .setUseVersion(false) 67 .addSuffix(mainClass); 68 CDSTestUtils.run(runOpts) 69 .assertNormalExit(expectedMsg); 70 } 71 }