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.
  • Loading branch information
enebo committed Jan 26, 2017
1 parent 02fe562 commit 026f2c6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 44 deletions.
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
36 changes: 21 additions & 15 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRDeoptimization.java
Expand Up @@ -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.
}
}
Expand Up @@ -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) {
Expand Down

0 comments on commit 026f2c6

Please sign in to comment.