Skip to content

Commit

Permalink
Push extra 'deopt' value which is the information the JIT will pass back
Browse files Browse the repository at this point in the history
to the full interpreter which can then reset the info and continue executing
at the deopt specified ipc.
enebo committed Jan 26, 2017
1 parent 02fe562 commit 026f2c6
Showing 8 changed files with 53 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ private IRubyObject INTERPRET_CLASS(InterpreterContext ic, Compilable compilable
private IRubyObject interpretWithBacktrace(InterpreterContext ic, Compilable compilable, ThreadContext context, IRubyObject self, String name, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());
return ic.getEngine().interpret(context, compilable, null, self, ic, name, block);
return ic.getEngine().interpret(context, compilable, null, self, ic, name, block, null);
} finally {
ThreadContext.popBacktrace(context);
}
Original file line number Diff line number Diff line change
@@ -109,11 +109,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block, null);
} else {
try {
pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block, null);
} finally {
post(ic, context);
}
@@ -147,11 +147,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block, null);
} else {
try {
pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block, null);
} finally {
post(ic, context);
}
@@ -183,11 +183,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block, null);
} else {
try {
pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block, null);
} finally {
post(ic, context);
}
@@ -219,11 +219,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block, null);
} else {
try {
pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block, null);
} finally {
post(ic, context);
}
@@ -255,11 +255,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block, null);
} else {
try {
pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block, null);
} finally {
post(ic, context);
}
Original file line number Diff line number Diff line change
@@ -106,11 +106,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block, null);
} else {
try {
this.pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, args, block, null);
} finally {
this.post(ic, context);
}
@@ -141,11 +141,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block, null);
} else {
try {
this.pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, block, null);
} finally {
this.post(ic, context);
}
@@ -176,11 +176,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block, null);
} else {
try {
this.pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, block, null);
} finally {
this.post(ic, context);
}
@@ -211,11 +211,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block, null);
} else {
try {
this.pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, block, null);
} finally {
this.post(ic, context);
}
@@ -246,11 +246,11 @@ private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext i
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

if (ic.hasExplicitCallProtocol()) {
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block, null);
} else {
try {
this.pre(ic, context, self, name, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block);
return ic.getEngine().interpret(context, this, null, self, ic, name, arg1, arg2, arg3, block, null);
} finally {
this.post(ic, context);
}
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
import java.util.List;
import org.jruby.EvalType;
import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.ast.RootNode;
@@ -111,7 +110,7 @@ public static IRubyObject INTERPRET_ROOT(ThreadContext context, IRubyObject self
Uncompilable compilable = new Uncompilable(clazz);
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());
return ic.getEngine().interpret(context, compilable, null, self, ic, name, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
return ic.getEngine().interpret(context, compilable, null, self, ic, name, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, null);
} finally {
ThreadContext.popBacktrace(context);
}
@@ -122,7 +121,7 @@ public static IRubyObject INTERPRET_EVAL(ThreadContext context, IRubyObject self
Uncompilable compilable = new Uncompilable(clazz);
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());
return ic.getEngine().interpret(context, compilable, null, self, ic, name, args, blockArg);
return ic.getEngine().interpret(context, compilable, null, self, ic, name, args, blockArg, null);
} finally {
ThreadContext.popBacktrace(context);
}
@@ -133,7 +132,7 @@ public static IRubyObject INTERPRET_BLOCK(ThreadContext context, Block block, IR
try {
Uncompilable compilable = new Uncompilable(null); // FIXME: we can pass real compilable through
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());
return ic.getEngine().interpret(context, compilable, block, self, ic, name, args, blockArg);
return ic.getEngine().interpret(context, compilable, block, self, ic, name, args, blockArg, null);
} finally {
ThreadContext.popBacktrace(context);
}
36 changes: 21 additions & 15 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
Original file line number Diff line number Diff line change
@@ -75,37 +75,37 @@
public class InterpreterEngine {

public IRubyObject interpret(ThreadContext context, Compilable method, Block block, IRubyObject self,
InterpreterContext interpreterContext, String name, Block blockArg) {
return interpret(context, method, block, self, interpreterContext, name, IRubyObject.NULL_ARRAY, blockArg);
InterpreterContext interpreterContext, String name, Block blockArg, IRDeoptimization deopt) {
return interpret(context, method, block, self, interpreterContext, name, IRubyObject.NULL_ARRAY, blockArg, deopt);
}

public IRubyObject interpret(ThreadContext context, Compilable method, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject arg1, Block blockArg) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1}, blockArg);
InterpreterContext interpreterContext, String name, IRubyObject arg1, Block blockArg,
IRDeoptimization deopt) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1}, blockArg, deopt);
}

public IRubyObject interpret(ThreadContext context, Compilable method, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject arg1, IRubyObject arg2, Block blockArg) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2}, blockArg);
InterpreterContext interpreterContext, String name, IRubyObject arg1, IRubyObject arg2,
Block blockArg, IRDeoptimization deopt) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2}, blockArg, deopt);
}

public IRubyObject interpret(ThreadContext context, Compilable method, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block blockArg) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2, arg3}, blockArg);
InterpreterContext interpreterContext, String name, IRubyObject arg1, IRubyObject arg2,
IRubyObject arg3, Block blockArg, IRDeoptimization deopt) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2, arg3}, blockArg, deopt);
}

public IRubyObject interpret(ThreadContext context, Compilable method, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, IRubyObject arg4, Block blockArg) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2, arg3, arg4}, blockArg);
InterpreterContext interpreterContext, String name, IRubyObject arg1, IRubyObject arg2,
IRubyObject arg3, IRubyObject arg4, Block blockArg, IRDeoptimization deopt) {
return interpret(context, method, block, self, interpreterContext, name, new IRubyObject[] {arg1, arg2, arg3, arg4}, blockArg, deopt);
}

public IRubyObject interpret(ThreadContext context, Compilable compilable, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject[] args, Block blockArg) {
String name, IRubyObject[] args, Block blockArg, IRDeoptimization deopt) {
Instr[] instrs = interpreterContext.getInstructions();
Object[] temp = interpreterContext.allocateTemporaryVariables();
double[] floats = interpreterContext.allocateTemporaryFloatVariables();
@@ -116,6 +116,12 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block
Object exception = null;
boolean acceptsKeywordArgument = interpreterContext.receivesKeywordArguments();

if (deopt != null) {
ipc = deopt.getIPC();
deopt.populateTempValues(temp);
// FIXME: Add deleted temp values
}

// Blocks with explicit call protocol shouldn't do this before args are prepared
if (acceptsKeywordArgument && (block == null || !interpreterContext.hasExplicitCallProtocol())) {
args = IRRuntimeHelpers.frobnicateKwargsArgument(context, args, interpreterContext.getRequiredArgsCount());
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.jruby.ir.instructions.JumpInstr;
import org.jruby.ir.instructions.RuntimeHelperCall;
import org.jruby.ir.instructions.SearchConstInstr;
import org.jruby.ir.runtime.IRDeoptimization;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
@@ -27,8 +28,8 @@
*/
public class StartupInterpreterEngine extends InterpreterEngine {
public IRubyObject interpret(ThreadContext context, Compilable compilable, Block block, IRubyObject self,
InterpreterContext interpreterContext,
String name, IRubyObject[] args, Block blockArg) {
InterpreterContext interpreterContext, String name, IRubyObject[] args, Block blockArg,
IRDeoptimization deopt) {
Instr[] instrs = interpreterContext.getInstructions();
Object[] temp = interpreterContext.allocateTemporaryVariables();
int n = instrs.length;
@@ -45,7 +46,6 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block

// Init profiling this scope
boolean debug = IRRuntimeHelpers.isDebug();
boolean profile = IRRuntimeHelpers.inProfileMode();

// Enter the looooop!
while (ipc < n) {
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRDeoptimization.java
Original file line number Diff line number Diff line change
@@ -23,4 +23,8 @@ public void setVars(Object[] vars, String descriptor) {
this.vars = vars;
this.varNames = descriptor.split(";");
}

public void populateTempValues(Object[] temps) {
// FIXME: use vars and their mappings to reset variable values.
}
}
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public String getMethodName() {
}

public void attemptInline(RubyClass selfType) {
callingScope.inlineMethod((Compilable) cache.method, selfType, cache.token, null, call, false);
callingScope.inlineMethod((Compilable) cache.method, cache.token, null, call, false);
}

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, long fixnum) {

0 comments on commit 026f2c6

Please sign in to comment.