TracePoint thread_begin and thread_end events are broken #1321

Closed
headius opened this Issue Dec 10, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@headius
Member

headius commented Dec 10, 2013

The thread_begin and thread_end events used by TracePoint (2.0 feature) do not work properly because they expect execution frames to be available on ThreadContext. For example:

 $ jruby --debug -e "t = TracePoint.new(:thread_begin) {|*a| p a }; t.enable; Thread.new { }.join"
Exception in thread "RubyThread-2: -e:1" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.jruby.runtime.ThreadContext.popFrame(ThreadContext.java:428)
    at org.jruby.runtime.ThreadContext.postTrace(ThreadContext.java:1184)
    at org.jruby.ext.tracepoint.TracePoint$2.eventHandler(TracePoint.java:105)
    at org.jruby.runtime.EventHook.event(EventHook.java:30)
    at org.jruby.Ruby.callEventHooks(Ruby.java:2899)
    at org.jruby.runtime.ThreadContext.trace(ThreadContext.java:648)
    at org.jruby.runtime.ThreadContext.trace(ThreadContext.java:644)
    at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:98)
    at java.lang.Thread.run(Thread.java:744)

I'm not exactly sure how to properly fire these trace events since they need to happen outside the thread's block, but at that point not all ThreadContext structures necessary for execution have been prepared.

Note also that it fails on the postTrace side, which is strange.

This was discovered while fixing #1318.

@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015

@enebo enebo added this to the JRuby 9.1.8.0 milestone Feb 17, 2017

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Feb 17, 2017

Member

Drive-by test and we appear to be sending tracepoints for threads now. The output is not quite the same as MRI but they seem to be happening:

jruby --debug -e 't2 = TracePoint.new(:thread_begin) { |a| puts "START: #{a}"}; t = TracePoint.new(:thread_end) {|a| puts "END: #{a}" }; t2.enable; t.enable; 10.times { Thread.new { } }; sleep 4'

Any other changes needed for output or missing state can become a new issue.

Member

enebo commented Feb 17, 2017

Drive-by test and we appear to be sending tracepoints for threads now. The output is not quite the same as MRI but they seem to be happening:

jruby --debug -e 't2 = TracePoint.new(:thread_begin) { |a| puts "START: #{a}"}; t = TracePoint.new(:thread_end) {|a| puts "END: #{a}" }; t2.enable; t.enable; 10.times { Thread.new { } }; sleep 4'

Any other changes needed for output or missing state can become a new issue.

@enebo enebo closed this Feb 17, 2017

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