Skip to content

Remove MemberName Object Ref from Stack in OpenJDK MethodHandle linkTo* INL Methods #22112

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 Jun 18, 2025

When calling the various linkTo methods (namely linkToStatic(), linkToSpecial(), linkToVirtual(), linkToInterface()), the JIT must pass in a MemberName object which linkTo*() expects to be at _sp[0]. The linkTo*() methods use the MN to find the target method, after which it is not needed. So, before running the target, we move the MN to _sp[methodArgCount], where methodArgCount is the argument count of the target method.

This creates problems on x86, where we pass arguments on the stack. For cases where the target is not compiled, we must transition into the VM to link using one of the linkTo*() methods (as opposed to running using dispatch*() directly from the JIT'ed code). But if the invocation in the VM triggers a recompilation, only the arguments of the target are popped before returning, and not the MN . This means the MN will still be on the stack upon return from the target, and eventually ends up in the pc since the arguments to the helper are assumed to have been cleaned up.

For the case where the target is still interpreted, we still only pop target's args before returning to the JIT and again the MN is still on the stack.

This PR changes the linkTo*() methods to pop the MN from the stack as it is not used by the target.

#18751

The JIT needs to pass in a MemberName object when calling the various
linkTo* INL methods in the OpenJDK MethodHandle implementation. The MN
is only used by the INL to extract the target method, and then is no
longer needed, so the INL moves the MN from _sp[0] to
_sp[methodArgCount] (the arg count of the target method).

This creates issues on x86 32bit when the target is compiled upon
invocation from linkTo*. If the target gets compiled, the call-cleanup
for j2iTransition will get skipped and we only remove the target
method's arguments and not the MN. So, the MN is still on the stack when
we return from the target, and eventuallly the MN address ends up in the
pc.

Fixes: eclipse-openj9#18751

This commit removes the MN from the stack before calling the target in
the linkTo* methods.

Signed-off-by: Matthew Hall <matthew.hall3@outlook.com>
@matthewhall2 matthewhall2 force-pushed the windows32_remove_MN branch from d4c7af6 to dbc1037 Compare June 19, 2025 13:56
@matthewhall2 matthewhall2 changed the title Remove java.lang.invoke.MemberName object ref from stack in OpenJDK MethodHandle linkTo* INL methods Remove MemberName object ref from stack in OpenJDK MethodHandle linkTo* INL methods Jun 19, 2025
@matthewhall2 matthewhall2 changed the title Remove MemberName object ref from stack in OpenJDK MethodHandle linkTo* INL methods Remove MemberName Object Ref from Stack in OpenJDK MethodHandle linkTo* INL Methods Jun 19, 2025
@matthewhall2 matthewhall2 marked this pull request as ready for review June 19, 2025 16:21
@matthewhall2
Copy link
Contributor Author

matthewhall2 commented Jun 19, 2025

tests seem to be passing. Can I get some reviews @jdmpapin @babsingh ?

cc @0xdaryl @hzongaro @vijaysun-omr

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

Successfully merging this pull request may close these issues.

1 participant