Bind directly to all supported arities of native methods#8489
Merged
headius merged 8 commits intojruby:10-devfrom Feb 11, 2025
Merged
Bind directly to all supported arities of native methods#8489headius merged 8 commits intojruby:10-devfrom
headius merged 8 commits intojruby:10-devfrom
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improvements for invokedynamic uses in JRuby.