Skip to content
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

Encode new and old name in aliased calls #7702

Merged
merged 6 commits into from
Mar 2, 2023

Conversation

headius
Copy link
Member

@headius headius commented Mar 2, 2023

JRuby only pushes the actual method name on the stack, since up until recently it was the only name needed. However the when the __callee__ method was added, the aliased name also became necessary.

Passing another argument along the dynamic call stack would take considerable work, which might happen along with making the call path flexible enough to handle allocation-free keyword arguments. For now, however this hack may be good enough.

The logic here encodes the aliased name and the original name in the same string passed along the call stack. Since this name is used in very few places – making super calls, setting up the interpreter backtrace, and the __method__ and __callee__ methods – only those locations need to be modified to receive the encoded string.

The format of the encoded string uses a leading null character, followed by the new name, another null character, and the old name. This allows an easy check for encoding using charAt(0), and the individual names can then be pulled out easily. The null character is also very unlikely to show up in any real method identifier (and may actually be illegal).

Because the two name are encoded into a single string, it is necessary to allocate a new string to extract either. However, the places where these names are used already have significant overhead, this allocation may not be a big concern.

This change is also hopefully temporary until we can better thread this data through the dynamic call stack.

Fixes #2305

@headius headius force-pushed the timmy_down_the_well branch 2 times, most recently from 71942d1 to 393c685 Compare March 2, 2023 06:26
JRuby only pushes the actual method name on the stack, since up
until recently it was the only name needed. However the when the
`__callee__` method was added, the aliased name also became
necessary.

Passing another argument along the dynamic call stack would take
considerable work, which might happen along with making the call
path flexible enough to handle allocation-free keyword arguments.
For now, however this hack may be good enough.

The logic here encodes the aliased name and the original name in
the same string passed along the call stack. Since this name is
used in very few places – making super calls, setting up the
interpreter backtrace, and the `__method__` and `__callee__`
methods – only those locations need to be modified to receive the
encoded string.

The format of the encoded string uses a leading null character,
followed by the new name, another null character, and the old
name. This allows an easy check for encoding using charAt(0), and
the individual names can then be pulled out easily. The null
character is also very unlikely to show up in any real method
identifier (and may actually be illegal).

Because the two name are encoded into a single string, it is
necessary to allocate a new string to extract either. However, the
places where these names are used already have significant
overhead, this allocation may not be a big concern.

This change is also hopefully temporary until we can better thread
this data through the dynamic call stack.

Fixes jruby#2305
With __callee__ working these modifications are no longer needed.
Any existing consumers of getFrameName would be expecting to get
the current method's name (as for super) so we should not break
that expectation. Places that need to pass through the composite
name, such as from frame to frame or binding, should use
getCompositeName and handle decoding the component names.
@headius headius added this to the JRuby 9.4.2.0 milestone Mar 2, 2023
@headius headius merged commit 1196f12 into jruby:master Mar 2, 2023
@headius headius deleted the timmy_down_the_well branch March 2, 2023 19:25
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.

__callee__ behaves differently from MRI
1 participant