Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7873d3d4f392
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d6e2e8178e93
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 22, 2016

  1. Get RubyEvent by name.

    headius committed Aug 22, 2016
    Copy the full SHA
    b63b7de View commit details
  2. Restructure tracepoint logic. Fixes #3835.

    * Only do the yield within the try/finally, so we don't try to
      pop a frame that never got pushed (e.g. if binding construction
      triggered an error).
    * MRI passes nil binding for thread begin and end events. Do same.
    * Override the event method that takes RubyEvent rather than the
      string name, so we can check for thread events quickly.
    headius committed Aug 22, 2016
    Copy the full SHA
    d6e2e81 View commit details
Showing with 35 additions and 10 deletions.
  1. +21 −10 core/src/main/java/org/jruby/ext/tracepoint/TracePoint.java
  2. +14 −0 core/src/main/java/org/jruby/runtime/RubyEvent.java
31 changes: 21 additions & 10 deletions core/src/main/java/org/jruby/ext/tracepoint/TracePoint.java
Original file line number Diff line number Diff line change
@@ -86,21 +86,27 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] _events, fina
final EnumSet<RubyEvent> eventSet = _eventSet;
hook = new EventHook() {
@Override
public synchronized void eventHandler(ThreadContext context, String eventName, String file, int line, String name, IRubyObject type) {
public synchronized void event(ThreadContext context, RubyEvent event, String file, int line, String name, IRubyObject type) {
if (!enabled || context.isWithinTrace()) return;

inside = true;
try {
if (file == null) file = "(ruby)";
if (type == null) type = context.runtime.getFalse();

RubyBinding binding = RubyBinding.newBinding(context.runtime, context.currentBinding());
if (file == null) file = "(ruby)";
if (type == null) type = context.runtime.getFalse();

context.preTrace();

// FIXME: get return value
update(eventName, file, line, name, type, context.getErrorInfo(), context.nil, binding);

IRubyObject binding;
if (event == RubyEvent.THREAD_BEGIN || event == RubyEvent.THREAD_END) {
binding = context.nil;
} else {
binding = RubyBinding.newBinding(context.runtime, context.currentBinding());
}

context.preTrace();

// FIXME: get return value
update(eventName, file, line, name, type, context.getErrorInfo(), context.nil, binding);

try {
block.yieldSpecific(context, TracePoint.this);
} finally {
update(null, null, line, null, context.nil, context.nil, context.nil, context.nil);
@@ -109,6 +115,11 @@ public synchronized void eventHandler(ThreadContext context, String eventName, S
}
}

@Override
public void eventHandler(ThreadContext context, String eventName, String file, int line, String name, IRubyObject type) {
event(context, RubyEvent.fromName(eventName), file, line, name, type);
}

@Override
public boolean isInterestedInEvent(RubyEvent event) {
return eventSet.contains(event);
14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/runtime/RubyEvent.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
*/
package org.jruby.runtime;

import java.util.HashMap;
import java.util.Map;

public enum RubyEvent {
LINE ("line", 1),
CLASS ("class", 1),
@@ -28,6 +31,13 @@ public enum RubyEvent {
private final String event_name;
private final int line_number_offset;

private static final Map<String, RubyEvent> fromName = new HashMap<>();
static {
for (RubyEvent event : RubyEvent.values()) {
fromName.put(event.getName(), event);
}
}

RubyEvent(String event_name, int line_number_offset){
this.event_name = event_name;
this.line_number_offset = line_number_offset;
@@ -44,5 +54,9 @@ public String getName(){
public static RubyEvent fromOrdinal(int value) {
return value < 0 || value >= values().length ? null : values()[value];
}

public static RubyEvent fromName(String name) {
return fromName.get(name);
}
}