Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthewhall2
Copy link
Contributor

@matthewhall2 matthewhall2 commented Apr 25, 2025

When an error is thrown during resolveInvokeDynamic, we return a special error-throwing MethodHandle. This MH has no parameters, which can cause problems for OSR Bookkeeping since no arguments will be popped off the stack, causing the assertion failure in ILGen "cannot create a pending push temporary that exceeds that number of slots for this method" since we are trying to push the return value onto the stack when it is already full.

This commit tests arguments are popped and that the assertion does not occur.

@matthewhall2 matthewhall2 force-pushed the test_makeConat_resolve_recursive branch from fbd3a9c to b5191c5 Compare April 25, 2025 16:24
@0xdaryl
Copy link
Contributor

0xdaryl commented May 4, 2025

This test appears to be designed to recurse without limit, which it will until the stack overflows. However, your method lookup for recurse() isn't correct and produces a NoSuchMethodException (which is caught and quietly suppressed), so there is no recursion. To look up a method without parameters, you need to omit the parameter list from getMethod("recurse").

After correcting the method lookup, the test runs but ultimately crashes on the pending push assert and the test fails. This is JDK 21. Is this the behaviour you are expecting? Please clarify what you hope to demonstrate with this test.

Depending on a stack overflow in a test is often dubious as it may not always occur when you expect it to, leading to intermittent behaviour in the test.

@0xdaryl
Copy link
Contributor

0xdaryl commented May 4, 2025

General comment: please make sure the indentation and spacing is consistent throughout.

Comment on lines 428 to 476
} catch (NoSuchMethodException e) {
// ...
} catch (IllegalAccessException e) {
// ...
} catch (java.lang.reflect.InvocationTargetException e) {
// ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of these exceptions should be handled as test failures.

Comment on lines 447 to 496
try {
Thread.sleep(30000); // let thread run for 30s
tester.stop();
thread.join();
} catch (InterruptedException e) {}
System.out.println("Ran with no errors");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct the indentation here (only use tabs).

@matthewhall2 matthewhall2 force-pushed the test_makeConat_resolve_recursive branch 2 times, most recently from 623104e to 5406db6 Compare May 13, 2025 13:08
@matthewhall2 matthewhall2 changed the title Add test for string concatention resolution in deep recursion Add test for BSM resolution on error throw May 13, 2025
@matthewhall2 matthewhall2 force-pushed the test_makeConat_resolve_recursive branch 3 times, most recently from 26e7ba9 to 85d8646 Compare May 13, 2025 13:39
@matthewhall2 matthewhall2 requested a review from keithc-ca May 13, 2025 13:40
When an error is thrown during resolveInvokeDynamic, we return a special
error-throwing MethodHandle. This MH has no paramters, which can cause
problems for OSR Bookkeeping since no arguments will be popped off the
stack, causing the assertion failure in ILGen "cannot create a pending
push temporary that exceeds that number of slots for this method" since
we are trying to push the return value onto the stack when it is already
full

This commit tests arguments are popped and that the assertion does not
occur.

Signed-off-by: Matthew Hall <matthew.hall3@outlook.com>
@matthewhall2 matthewhall2 force-pushed the test_makeConat_resolve_recursive branch from 85d8646 to 496f378 Compare May 13, 2025 13:40
@matthewhall2
Copy link
Contributor Author

Made some significant changes. Since this assertion fail can happen any time an error is thrown during resolveInvokeDynamic, changed the test to use a custom bootstrap method that throws a given error instead of trying to produce a stack overflow.

@@ -65,6 +65,7 @@
<include name="**/indyn/Helper.java" />
<include name="**/indyn/SimpleIndyGenerator.java" />
<include name="**/CrossPackageHelper.java"/>
<include name="**/indy/IndyOSRTest.java"/>
Copy link
Contributor

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.

@@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Comment on lines +126 to +130
<test name="jsr292_InDyn_OSRTest">
<classes>
<class name="com.ibm.j9.jsr292.indyn.IndyOSRTest"/>
</classes>
</test>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this repeated?

</classes>
</test>

</suite>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the final newline.

@@ -0,0 +1,150 @@
/*
* Copyright IBM Corp. and others 2001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The year should be 2025 for a new file.

// attempt once in the interpreter
try {
if (t == null){
Assert.assertTrue(cls.getMethod("dummy").invoke(null).equals("bootstrap1,2,3,4"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assertEquals() (also line 136).

Comment on lines +126 to +128
if (t == null) {
Assert.fail("Bootsrap method should not throw error when parameter t is null");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assertNotNull()

			Assert.assertNotNull(t, "Bootsrap method should not throw error when parameter t is null");

Also line 146.

} else {
cls.getMethod("dummy").invoke(null);
}
} catch(IllegalAccessException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after each catch.


// attempt once in the interpreter
try {
if (t == null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before {.

Comment on lines +148 to +149
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent only with tabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants