Fix super chaining on Ruby subclasses of Java classes#6820
Merged
headius merged 6 commits intojruby:masterfrom Sep 13, 2021
Merged
Fix super chaining on Ruby subclasses of Java classes#6820headius merged 6 commits intojruby:masterfrom
headius merged 6 commits intojruby:masterfrom
Conversation
Super method invocations from JRuby must use the generated super shims in order to invoke the override at the correct level in the class hierarchy. The previous logic fell back on standard reflective invocation, which always starts at the bottom. This led to the issues in jruby#6718 where the super call chain would get stuck in a recursive loop and eventually blow the call stack. This change moves the invocation logic closer to the Ruby super logic, allowing us to retrieve the appropriate super shim method when performing the invocation. Fixes jruby#6718
enebo
approved these changes
Sep 10, 2021
byteit101
reviewed
Sep 10, 2021
Every combination of three descendants with and without overrides.
byteit101
approved these changes
Sep 10, 2021
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.
The issue here was that we super calls would sometimes fall back on reflective invocation when more than one subclass was involved. This had the effect of restarting the invocation chain back at the bottom of the hierarchy (from the self object's class) due to the nature of reflective invocation (it always calls the lowest override).
The fix here pulls the super invocation logic back from within the Java integration guts and into the Ruby-level super logic, so we can look up an appropriate super shim method to invoke at the proper level.
This fix will need to be refined in the future, using some of the following ideas:
definingModulefrom which the super call should originate. This was not possible using the standardDynamicMethodcall paths, but enhancement may be possible.Includes simple test cases for the examples in #6718.
Fixes #6718.