Skip to content

Bind directly to all supported arities of native methods#8489

Merged
headius merged 8 commits intojruby:10-devfrom
headius:more_indy_binding
Feb 11, 2025
Merged

Bind directly to all supported arities of native methods#8489
headius merged 8 commits intojruby:10-devfrom
headius:more_indy_binding

Conversation

@headius
Copy link
Member

@headius headius commented Dec 6, 2024

Improvements for invokedynamic uses in JRuby.

  • Direct binding to all arities when available, regardless of DynamicMethod.getNativeCall "winner" signature.

With only a single getNativeCall on DynamicMethod, we have up to
now only been able to publish and bind to one native signature
at indy call sites. Because multiple-arity core methods are
bound to Ruby using Java reflection, the signature that wins is
not predictable and may not be the one most commonly used by
callers.

This patch attempts to bypass the one nativeCall and attempt to
directly bind arguments straight through every time, falling back
on the one lucky nativeCall logic if a direct binding is not
possible.
@headius headius added this to the JRuby 10.0.0.0 milestone Dec 6, 2024
Tried to put this elsewhere but with modules it's hard to have a
classpath class extend a module class and be accessible.
We could support more arities here, but it is difficult to predict
whether that might bind methods that should not be bound (e.g. if
a multiple-arity method had one common uber method with > 3 args it
would be bound, skipping the annotated arities). In order to land
this without introducing too much complexity, I'm limiting it to
arities <= 3.

There may be some overhead from trying and failing to acquire a
specific-arity target repeatedly. I will be refactoring the indy
binding logic to live close to (or inside) the DynamicMethod types
in order to let them slowly cache all arities with any handle
adaptations necessary. This will eliminate the extra overhead by
failing to find a given arity exactly once.
@headius headius changed the title Various invokedynamic improvements Bind directly to all supported arities of native methods Feb 11, 2025
@headius headius marked this pull request as ready for review February 11, 2025 02:35
@headius headius merged commit bedc5e6 into jruby:10-dev Feb 11, 2025
55 of 73 checks passed
@headius headius deleted the more_indy_binding branch February 11, 2025 02:35
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.

Indy call sites can directly bind to only one arity

1 participant