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

Thread-level events explode due to empty stack #3835

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

Thread-level events explode due to empty stack #3835

headius opened this issue Apr 28, 2016 · 2 comments

Comments

@headius
Copy link
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
Copy link
Member Author

headius commented Apr 28, 2016

This bug represents the 9k response to #3781.

headius added a commit that referenced this issue May 11, 2016
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
Copy link
Member Author

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
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

2 participants