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

reported ThreadContext file/line do not match (MRI) #3514

Open
kares opened this issue Dec 4, 2015 · 0 comments
Open

reported ThreadContext file/line do not match (MRI) #3514

kares opened this issue Dec 4, 2015 · 0 comments

Comments

@kares
Copy link
Member

kares commented Dec 4, 2015

while implementing (and trying to test) some Thread#name propagating into the Java thread name, I noticed reported file/line get a little wild on JRuby - e.g. test/unit messes them up (although even without the require 'test/unit' the line number is not correct) :

require 'test/unit'

@@inspect = nil

Thread.new do
  @@inspect = Thread.current.inspect
  if defined? JRUBY_VERSION
    @@inspect += ' ' + Thread.current.to_java.native_thread.name
  end
end.join

puts @@inspect

# MRI:
#   #<Thread:0x00000001c9f968@thread_location.rb:5 run>
# JRuby 1.7.22: with commented-out # require 'test/unit' :
#   #<Thread:0x6b281ec1 run> Ruby-0-Thread-2: thread_location.rb:3
# JRuby 9.0.4.0: with commented-out # require 'test/unit' :
#   #<Thread:0x11bdb67e run> Ruby-0-Thread-1: thread_location.rb:3
# JRuby 9.0.4.0: as is - uncommented require 'test/unit' :
#   #<Thread:0x23ab7871 run> Ruby-0-Thread-3: thread_location.rb:1
# JRuby 9K (ruby-2.3) as is - uncommented require 'test/unit' :
#   #<Thread:0x5c92a526@thread_location.rb:1 run> Ruby-0-Thread-1: thread_location.rb:1

class TestTest < Test::Unit::TestCase

  @@inspect = nil

  def test_thread
    Thread.new do
      @@inspect = Thread.current.inspect
        if defined? JRUBY_VERSION
          @@inspect += ' ' + Thread.current.to_java.native_thread.name
        end
    end.join
    puts @@inspect
  end

end

# MRI 2.2.3/2.3.0:
#   #<Thread:0x00000002146598@thread_location.rb:30 run>
# JRuby 9.0.4.0 / 9K (ruby-2.3):
#   #<Thread:0x2de0b137 run> Ruby-0-Thread-4: /opt/local/rvm/rubies/jruby-9.0.4.0/lib/ruby/stdlib/test/unit/testcase.rb:697
#   #<Thread:0x11911e61@/home/kares/workspace/oss/jruby/lib/ruby/stdlib/test/unit/testcase.rb:697 run> Ruby-0-Thread-2: /home/kares/workspace/oss/jruby/lib/ruby/stdlib/test/unit/testcase.rb:697

recall this is smt I've run into in the past as well ... Thread.new sometimes not having a correct line number when looking through VisualVM - although that is not that relevant, since it wasn't much visible. nowdays (since Ruby 2.2) Thread#inspect includes the Thread.new source location so it would be great to have it right.

p.s. also context.getFile gets "" (empty) and context.getLine == 0 when JIT-ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant