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

When Thread::Backtrace::Location#base_label and #label are #== on MRI they are also #equal? #5163

ivoanjo opened this issue May 10, 2018 · 0 comments


Copy link

@ivoanjo ivoanjo commented May 10, 2018

Hello again!

I'm using Thread#backtrace_locations and noticed several differences between MRI and JRuby.

I'll report them separately because they may have different fixes, but feel free to mark any as duplicate if it makes sense to do so.


  • JRuby: jruby (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
  • Kernel: Linux u186024434db159d25c92 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Distro: Ubuntu 16.04.4 LTS

Expected Behavior

When looking at a Thread::Backtrace::Location, MRI provides both #base_label and #label.

For most methods, these are exactly the same, but for blocks it allows the caller to get the name of the method separate from the "block in" text without resorting to parsing the result.

An additional detail from MRI is that whenever #base_label and #label match, the underlying String is reused and thus both are #equal?. This allows a very fast check if a Location is a block or not, as we can use equal? instead of a heavier ==.



def test
  location = Thread.current.backtrace_locations[1]
  puts "#base_label '#{location.base_label}', #label '#{location.label}', equal? #{location.base_label.equal?(location.label)}"


Output on MRI:

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
#base_label 'test', #label 'test', equal? true

Actual Behavior

JRuby creates different Strings for both methods, so they end up not being equal?.

jruby (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
#base_label 'test', #label 'test', equal? false

If it would be helpful I can also submit a testcase to RubySpec.

@headius headius added this to the JRuby milestone May 14, 2018
enebo added a commit that referenced this issue Jun 14, 2018
…re #== on MRI they are also #equal?

Our desire for laziness was the cause of this issue.  In the future we will
migrate to using symbol for methodNames to fully support M17n and this fix
ickiness will be able to be deleted.  Largely we use basename for all cases
except blocks.  In either case we save off the string we make so the equality
property is preserved.

With symbols the strings we have will always end up as the same string and
equality will also be true.  The amount of API changes is a bit too much to
do the m17n work now.
@enebo enebo closed this in d23a619 Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants