|
| 1 | +/* |
| 2 | + * Copyright (c) 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 8323950 |
| 28 | + * @summary Transforming an interface of an archived lambda proxy class should not |
| 29 | + * crash the VM. The lambda proxy class should be regenerated during runtime. |
| 30 | + * @requires vm.cds |
| 31 | + * @requires vm.jvmti |
| 32 | + * @requires vm.flagless |
| 33 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes |
| 34 | + * @compile test-classes/SimpleTest.java |
| 35 | + * @compile test-classes/TransformBootClass.java |
| 36 | + * @run driver TransformInterfaceOfLambda |
| 37 | + */ |
| 38 | + |
| 39 | +import jdk.test.lib.process.OutputAnalyzer; |
| 40 | +import jdk.test.lib.process.ProcessTools; |
| 41 | +import jdk.test.lib.helpers.ClassFileInstaller; |
| 42 | + |
| 43 | +public class TransformInterfaceOfLambda { |
| 44 | + |
| 45 | + public static String agentClasses[] = { |
| 46 | + TransformBootClass.class.getName(), |
| 47 | + }; |
| 48 | + |
| 49 | + public static void main(String[] args) throws Exception { |
| 50 | + String mainClass = SimpleTest.class.getName(); |
| 51 | + String namePrefix = "transform-interface-of-lambda"; |
| 52 | + JarBuilder.build(namePrefix, mainClass); |
| 53 | + |
| 54 | + String appJar = TestCommon.getTestJar(namePrefix + ".jar"); |
| 55 | + |
| 56 | + String agentJar = |
| 57 | + ClassFileInstaller.writeJar("TransformBootClass.jar", |
| 58 | + ClassFileInstaller.Manifest.fromSourceFile("test-classes/TransformBootClass.mf"), |
| 59 | + agentClasses); |
| 60 | + String useJavaAgent = "-javaagent:" + agentJar + "=java/util/function/IntFunction"; |
| 61 | + |
| 62 | + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( |
| 63 | + "-cp", appJar, "-Xlog:class+load,cds=debug", |
| 64 | + "-XX:+UnlockDiagnosticVMOptions", |
| 65 | + "-XX:+AllowArchivingWithJavaAgent", |
| 66 | + useJavaAgent, |
| 67 | + mainClass); |
| 68 | + OutputAnalyzer out = new OutputAnalyzer(pb.start()); |
| 69 | + System.out.println(out.getStdout()); |
| 70 | + out.shouldHaveExitValue(0) |
| 71 | + // the class loaded by the SimpleTest should be from the archive |
| 72 | + .shouldContain("[class,load] java.text.SimpleDateFormat source: shared objects file") |
| 73 | + // the IntFunction is the interface which is being transformed. The |
| 74 | + // interface is a super type of the following lambda proxy class. |
| 75 | + .shouldContain("Transforming class java/util/function/IntFunction") |
| 76 | + // the lambda proxy class should be regenerated |
| 77 | + .shouldMatch(".class.load.*sun.util.locale.provider.LocaleProviderAdapter[$][$]Lambda/0x.*source:.*sun.util.locale.provider.LocaleProviderAdapter"); |
| 78 | + } |
| 79 | +} |
0 commit comments