Skip to content

Commit

Permalink
Make Trace and ThreadPoll have their own interpret methods.
Browse files Browse the repository at this point in the history
These are both rarely encountered in scope bodies so it would be nice to remove an
explicit impl from the in the body interpreter.
  • Loading branch information
enebo committed Feb 10, 2015
1 parent eadb23f commit 730c677
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/ThreadPollInstr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.interpreter.Profiler;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class ThreadPollInstr extends Instr implements FixedArityInstr {
public final boolean onBackEdge;
Expand All @@ -29,4 +35,11 @@ public Instr clone(CloneInfo ii) {
public void visit(IRVisitor visitor) {
visitor.ThreadPollInstr(this);
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
if (IRRuntimeHelpers.inProfileMode()) Profiler.clockTick();
context.callThreadPoll();
return null;
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/TraceInstr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import org.jruby.ir.Operation;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

// FIXME: When presistence is revisited this should strip these out of code streams on save and add them in if
// tracing is on for load.
Expand Down Expand Up @@ -49,4 +53,16 @@ public int getLinenumber() {
public String[] toStringNonOperandArgs() {
return new String[] {"ev: " + event, "name: " + name, "file: " + filename, "line: " + linenumber};
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
if (context.runtime.hasEventHooks()) {
// FIXME: Try and statically generate END linenumber instead of hacking it.
int linenumber = getLinenumber() == -1 ? context.getLine()+1 : getLinenumber();

context.trace(getEvent(), getName(), context.getFrameKlazz(), getFilename(), linenumber);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,6 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self, Interprete
setResult(temp, currDynScope, gfi.getResult(), result);
break;
}
case TRACE: {
if (context.runtime.hasEventHooks()) {
TraceInstr trace = (TraceInstr) instr;
// FIXME: Try and statically generate END linenumber instead of hacking it.
int linenumber = trace.getLinenumber() == -1 ? context.getLine()+1 : trace.getLinenumber();

context.trace(trace.getEvent(), trace.getName(), context.getFrameKlazz(),
trace.getFilename(), linenumber);
}
break;
}
case THREAD_POLL:
if (IRRuntimeHelpers.inProfileMode()) Profiler.clockTick();
context.callThreadPoll();
break;
default:
if (instr.getOperation().opClass == OpClass.BRANCH_OP) {
ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc);
Expand Down

0 comments on commit 730c677

Please sign in to comment.