Thread-level events explode due to empty stack #3835

Closed
headius opened this Issue Apr 28, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@headius
Member

headius commented Apr 28, 2016

Environment

I believe this affects all JRuby 9k versions that support Thread begin/end trace events (probably all released versions) up through 9.1).

Expected Behavior

MRI in 2.1 or 2.2 added the ability to trace the begin and end of thread life via both set_trace_func and the TracePoint API.

Actual Behavior

On JRuby, the thread begin/end events currently error out, because at least in the case of set_trace_func it is not possible to acquire a thread for the necessary binding:

[--dev] ~/projects/jruby $ jruby --debug -e "set_trace_func(proc {|*a| p a}); Thread.new { return }"
["c-call", "-e", 1, :new, #<Binding:0x8e24743>, #<Class:Thread>]
["c-call", "-e", 1, :initialize, #<Binding:0x23fe1d71>, Thread]
["c-return", "-e", 1, :initialize, #<Binding:0x1d371b2d>, Thread]
["c-return", "-e", 1, :new, #<Binding:0x13eb8acf>, #<Class:Thread>]
Exception in thread "Ruby-0-Thread-1: -e:1" java.lang.ArrayIndexOutOfBoundsException: -1
    at org.jruby.runtime.ThreadContext.getCurrentFrame(ThreadContext.java:465)
    at org.jruby.runtime.ThreadContext.currentBinding(ThreadContext.java:984)
    at org.jruby.Ruby$CallTraceFuncHook.eventHandler(Ruby.java:3133)
    at org.jruby.runtime.EventHook.event(EventHook.java:30)
    at org.jruby.Ruby.callEventHooks(Ruby.java:3214)
    at org.jruby.runtime.ThreadContext.trace(ThreadContext.java:641)
    at org.jruby.runtime.ThreadContext.trace(ThreadContext.java:637)
    at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:98)
    at java.lang.Thread.run(Thread.java:745)

This affects set_trace_func for sure, since it always tries to acquire a binding. It may not affect TracePoint.

This is a regression because 1.7 did not have these top-level thread events, and on 9k they prevent even simple set_trace_func from working properly.

@headius headius added this to the JRuby 9.1.1.0 milestone Apr 28, 2016

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Apr 28, 2016

Member

This bug represents the 9k response to #3781.

Member

headius commented Apr 28, 2016

This bug represents the 9k response to #3781.

headius added a commit that referenced this issue Apr 29, 2016

headius added a commit that referenced this issue May 11, 2016

set_trace_func does not receive all events.
Partial fix for #3835. TracePoint monitoring of thread events
still blows up.

@headius headius modified the milestones: JRuby 9.1.2.0, JRuby 9.1.1.0 May 11, 2016

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 11, 2016

Member

Ok, set_trace_func is working properly again in the presence of thread begin/end. It turns out we never modified it to only receive the events Ruby 1.8 sent to it, so it was receiving all the new events like :thread_begin. Since it always tries to acquire a binding, it blew up if this event ever fired.

We still need to fix TracePoint, however. I thought it might escape this bug, since it doesn't normally acquire a binding, but it must still be accessing the frame stack somewhere along the way:

$ jruby --debug -e "tp = TracePoint.new(:thread_begin) {|*a| p a}; tp.enable; Thread.new { return }"
Exception in thread "Ruby-0-Thread-1: -e:1" java.lang.ArrayIndexOutOfBoundsException: -1
...
Member

headius commented May 11, 2016

Ok, set_trace_func is working properly again in the presence of thread begin/end. It turns out we never modified it to only receive the events Ruby 1.8 sent to it, so it was receiving all the new events like :thread_begin. Since it always tries to acquire a binding, it blew up if this event ever fired.

We still need to fix TracePoint, however. I thought it might escape this bug, since it doesn't normally acquire a binding, but it must still be accessing the frame stack somewhere along the way:

$ jruby --debug -e "tp = TracePoint.new(:thread_begin) {|*a| p a}; tp.enable; Thread.new { return }"
Exception in thread "Ruby-0-Thread-1: -e:1" java.lang.ArrayIndexOutOfBoundsException: -1
...

@enebo enebo modified the milestones: JRuby 9.1.2.0, JRuby 9.1.3.0 May 23, 2016

@headius headius closed this in d6e2e81 Aug 22, 2016

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