-
Notifications
You must be signed in to change notification settings - Fork 754
Add test for BSM resolution on error throw #21730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -447,6 +447,29 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex | |
<impl>ibm</impl> | ||
</impls> | ||
</test> | ||
<test> | ||
<testCaseName>jsr292_InDyn_OSRTest</testCaseName> | ||
<variations> | ||
<variation>-Xjit:"dontInline={*dummy*},limit={*dummy*},count=1,disableAsyncCompilation,initialOptLevel=warm,disableGuardedCountingRecompilation"</variation> | ||
</variations> | ||
<command>TR_EnableStartupNextGenHCRAtAllOpts=1 $(JAVA_COMMAND) $(JVM_OPTIONS) \ | ||
-cp $(Q)$(TEST_RESROOT)$(D)jsr292test.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(Q) \ | ||
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng$(XMLSUFFIX).xml$(Q) \ | ||
-testnames jsr292_InDyn_OSRTest \ | ||
-groups $(TEST_GROUP) \ | ||
-excludegroups $(DEFAULT_EXCLUDE); \ | ||
$(TEST_STATUS)</command> | ||
<levels> | ||
<level>extended</level> | ||
</levels> | ||
<groups> | ||
<group>functional</group> | ||
</groups> | ||
<impls> | ||
<impl>openj9</impl> | ||
<impl>ibm</impl> | ||
</impls> | ||
</test> | ||
<!-- | ||
TODO: The following test cases specific to Lookup are temporarily excluded in Java 14 | ||
as there is no backward compatibility of these APIs since Java 14 due to the new changes | ||
|
@@ -512,4 +535,4 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex | |
<impl>ibm</impl> | ||
</impls> | ||
</test> | ||
</playlist> | ||
</playlist> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore the final newline (every non-empty text file should end with one). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright IBM Corp. and others 2001 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The year should be 2025 for a new file. |
||
* | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which accompanies this | ||
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* or the Apache License, Version 2.0 which accompanies this distribution and | ||
* is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* This Source Code may also be made available under the following | ||
* Secondary Licenses when the conditions for such availability set | ||
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU | ||
* General Public License, version 2 with the GNU Classpath | ||
* Exception [1] and GNU General Public License, version 2 with the | ||
* OpenJDK Assembly Exception [2]. | ||
* | ||
* [1] https://www.gnu.org/software/classpath/license.html | ||
* [2] https://openjdk.org/legal/assembly-exception.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0 | ||
*/ | ||
package com.ibm.j9.jsr292.indyn; | ||
|
||
import org.openj9.test.util.VersionCheck; | ||
|
||
import org.testng.annotations.Test; | ||
import org.testng.annotations.DataProvider; | ||
|
||
import org.testng.Assert; | ||
import org.testng.AssertJUnit; | ||
import org.objectweb.asm.*; | ||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.ConstantCallSite; | ||
import java.lang.invoke.CallSite; | ||
import java.lang.invoke.MethodType; | ||
Comment on lines
+34
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please sort imports: import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; |
||
import java.lang.reflect.Method; | ||
|
||
public class IndyOSRTest { | ||
|
||
private static Throwable thrower = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the redundant initializer. |
||
private static String dummyClassPathName = "com/ibm/j9/jsr292/indyn/TestBSMError"; | ||
private static String dummyClassFullName = "com.ibm.j9.jsr292.indyn.TestBSMError"; | ||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These fields should be final. |
||
|
||
// generate method with invokedynamic bytecode that uses the BSM "bootstrap" below | ||
private static byte[] generate(int version) { | ||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); | ||
MethodVisitor mv; | ||
cw.visit(VersionCheck.major() + V1_8 - 8, ACC_PUBLIC, dummyClassPathName + version, null, "java/lang/Object", null); | ||
Comment on lines
+49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work in Java 25+ where |
||
|
||
mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "dummy", "()V", null, null); | ||
mv.visitCode(); | ||
|
||
Handle bsm = new Handle( | ||
H_INVOKESTATIC, | ||
"com/ibm/j9/jsr292/indyn/IndyOSRTest", | ||
"bootstrap", | ||
"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;", | ||
false | ||
); | ||
|
||
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); | ||
mv.visitLdcInsn(1L); | ||
mv.visitLdcInsn(2L); | ||
//mv.visitVarInsn(ILOAD, 0); | ||
mv.visitLdcInsn(3); | ||
mv.visitLdcInsn(4); | ||
mv.visitInvokeDynamicInsn("someName", "(JJII)Ljava/lang/String;", bsm); | ||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); | ||
mv.visitInsn(RETURN); | ||
mv.visitMaxs(6, 4); | ||
mv.visitEnd(); | ||
cw.visitEnd(); | ||
return cw.toByteArray(); | ||
} | ||
|
||
|
||
|
||
Comment on lines
+78
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One blank at a time, please. |
||
public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType mt) throws Throwable { | ||
if (thrower == null) { | ||
MethodHandle target = MethodHandles.lookup().findStatic(IndyTest.class, "sanity", MethodType.methodType(String.class, long.class, long.class, int.class, int.class)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you mean to refer to this class ( MethodHandle target = MethodHandles.lookup().findStatic(
IndyOSRTest.class,
"sanity",
MethodType.methodType(String.class, long.class, long.class, int.class, int.class)); |
||
return new ConstantCallSite(target); | ||
} | ||
System.out.println("Throwing"); | ||
throw thrower; | ||
} | ||
|
||
public static String sanity(long a, long b, int c, int d) { | ||
return "bootstrap" + a + "," + b + "," + c + "," + d; | ||
} | ||
|
||
private class ByteArrayClassLoader extends ClassLoader { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class should be |
||
public Class<?> getc(String name, byte[] b) { | ||
return defineClass(name,b,0,b.length); | ||
} | ||
} | ||
|
||
@DataProvider(name="throwableProvider") | ||
public static Object[][] throwableProvider() { | ||
return new Object[][] {{new NullPointerException(), 1}, {new StackOverflowError(), 2}, {new IllegalArgumentException(), 3}, | ||
{new ClassCastException(), 4}}; | ||
Comment on lines
+102
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please split: return new Object[][] {
{new NullPointerException(), 1},
{new StackOverflowError(), 2},
{new IllegalArgumentException(), 3},
{new ClassCastException(), 4}}; |
||
} | ||
|
||
@Test(groups = {"level.extended"}, dataProvider="throwableProvider", invocationCount=1) | ||
public void testBSMErrorThrow(Throwable t, int version) { | ||
thrower = t; | ||
ByteArrayClassLoader c = new ByteArrayClassLoader(); | ||
byte[] b = IndyOSRTest.generate(version); | ||
System.out.println(b.length); | ||
Class<?> cls = c.getc(dummyClassFullName + version, b); | ||
|
||
// attempt once in the interpreter | ||
try { | ||
if (t == null){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before |
||
Assert.assertTrue(cls.getMethod("dummy").invoke(null).equals("bootstrap1,2,3,4")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
} else { | ||
cls.getMethod("dummy").invoke(null); | ||
} | ||
} catch(IllegalAccessException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space after each |
||
Assert.fail("Cannot access dummy method"); | ||
} catch(NoSuchMethodException e) { | ||
Assert.fail("Cannot find dummy method"); | ||
} catch (java.lang.reflect.InvocationTargetException e) { | ||
if (t == null) { | ||
Assert.fail("Bootsrap method should not throw error when parameter t is null"); | ||
} | ||
Comment on lines
+126
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Assert.assertNotNull(t, "Bootsrap method should not throw error when parameter t is null"); Also line 146. |
||
} catch (Throwable t2) { | ||
System.out.println("Caught something"); | ||
} | ||
|
||
// run again after compilation | ||
try { | ||
if (t == null){ | ||
Assert.assertTrue(cls.getMethod("dummy").invoke(null).equals("bootstrap1,2,3,4")); | ||
} else { | ||
cls.getMethod("dummy").invoke(null); | ||
} | ||
} catch(IllegalAccessException e) { | ||
Assert.fail("Cannot access dummy method"); | ||
} catch(NoSuchMethodException e) { | ||
Assert.fail("Cannot find dummy method"); | ||
} catch (java.lang.reflect.InvocationTargetException e) { | ||
if (t == null) { | ||
Assert.fail("Bootsrap method should not throw error when parameter t is null"); | ||
} | ||
} | ||
} | ||
Comment on lines
+148
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please indent only with tabs. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,4 +116,17 @@ | |
<class name="com.ibm.j9.jsr292.indyn.ComplexIndyTest"/> | ||
</classes> | ||
</test> | ||
</suite> | ||
|
||
<test name="jsr292_InDyn_OSRTest"> | ||
<classes> | ||
<class name="com.ibm.j9.jsr292.indyn.IndyOSRTest"/> | ||
</classes> | ||
</test> | ||
|
||
<test name="jsr292_InDyn_OSRTest"> | ||
<classes> | ||
<class name="com.ibm.j9.jsr292.indyn.IndyOSRTest"/> | ||
</classes> | ||
</test> | ||
Comment on lines
+126
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this repeated? |
||
|
||
</suite> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore the final newline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the path and keep the elements sorted by name.