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

Fix Kernel#set_trace_func invocation after native Java EventHooks #2604

Conversation

gsamokovarov
Copy link
Contributor

Hello,

Currently, registering plain Ruby Kernel#set_trace_func after native
extensions EventHooks fails with:

bug.rb:2 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Ruby.java:3058:in `removeEventHook': java.lang.ArrayIndexOutOfBoundsException: 0
         from Ruby.java:3066:in `setTraceFunction'
         from RubyKernel.java:1206:in `set_trace_func'
         from RubyKernel$INVOKER$s$1$0$set_trace_func.gen:-1:in `call'
         from JavaMethod.java:364:in `call'
         from CachingCallSite.java:317:in `cacheAndCall'
         from CachingCallSite.java:167:in `call'
         from Interpreter.java:293:in `processCall'
         from Interpreter.java:550:in `interpret'
         from Interpreter.java:617:in `INTERPRET_ROOT'
         from Interpreter.java:112:in `execute'
         from Interpreter.java:28:in `execute'
         from IRTranslator.java:39:in `execute'
         from Ruby.java:855:in `runInterpreter'
         from Ruby.java:863:in `runInterpreter'
         from Ruby.java:759:in `runNormally'
         from Ruby.java:564:in `runFromMain'
         from Main.java:405:in `doRunFromMain'
         from Main.java:300:in `internalRun'
         from Main.java:227:in `run'
         from Main.java:199:in `main'

I have a small reproduction script, which uses Coverage's native
EventHook, however the problem is present in custom extensions that
implement EventHooks themselves as well.

Here is the script:

require 'coverage'
Coverage.start

set_trace_func proc { |*args| p args }

I'm not sure whether my current solution is good enough, since I don't
know if the bargain with removeEventHook is to always find the previous
eventHook before, however it does prevent the crash in my tests.

Hope it helps!

Hello,

Currently, registering plain Ruby `Kernel#set_trace_func` after native
extensions EventHooks fails with:

```
bug.rb:2 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Ruby.java:3058:in `removeEventHook': java.lang.ArrayIndexOutOfBoundsException: 0
         from Ruby.java:3066:in `setTraceFunction'
         from RubyKernel.java:1206:in `set_trace_func'
         from RubyKernel$INVOKER$s$1$0$set_trace_func.gen:-1:in `call'
         from JavaMethod.java:364:in `call'
         from CachingCallSite.java:317:in `cacheAndCall'
         from CachingCallSite.java:167:in `call'
         from Interpreter.java:293:in `processCall'
         from Interpreter.java:550:in `interpret'
         from Interpreter.java:617:in `INTERPRET_ROOT'
         from Interpreter.java:112:in `execute'
         from Interpreter.java:28:in `execute'
         from IRTranslator.java:39:in `execute'
         from Ruby.java:855:in `runInterpreter'
         from Ruby.java:863:in `runInterpreter'
         from Ruby.java:759:in `runNormally'
         from Ruby.java:564:in `runFromMain'
         from Main.java:405:in `doRunFromMain'
         from Main.java:300:in `internalRun'
         from Main.java:227:in `run'
         from Main.java:199:in `main'
```

I have a small reproduction script, which uses `Coverage`'s native
EventHook, however the problem is present in custom extensions that
implement EventHooks themselves as well.

Here is the script:

```ruby
require 'coverage'
Coverage.start

set_trace_func proc { |*args| p args }
```

I'm not sure whether my current solution is good enough, since I don't
know if the bargain with removeEventHook is to always find the previous
eventHook before, however it does prevent the crash in my tests.

Hope it helps!
@gsamokovarov gsamokovarov force-pushed the set-trace-func-after-java-event-hook branch from e8f6556 to 6eee5e4 Compare February 20, 2015 10:00
@enebo enebo added this to the Invalid or Duplicate milestone May 1, 2015
@enebo
Copy link
Member

enebo commented May 1, 2015

I totally rewrote this method because it had a second issue in addition to the AIIOB (see #2903).

@enebo enebo closed this May 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants