Skip to content

Thread-level events explode due to empty stack #3835

@headius

Description

@headius

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions