Skip to content

Commit

Permalink
Add deopt recovery in interpreter if it is already running in interpr…
Browse files Browse the repository at this point in the history
…eter (-X-C optimized fallback to full)
  • Loading branch information
enebo committed Jan 26, 2017
1 parent 9f054d7 commit 02fe562
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -1262,4 +1262,10 @@ public boolean needsBinding() {
public boolean isDeoptimizable() {
return false; // optimizedInterpreterContext != null;
}

public void deoptimize() {
optimizedInterpreterContext = null;

// FIXME: full should also delete any data associated with backing off to it.
}
}
66 changes: 39 additions & 27 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
Expand Up @@ -5,6 +5,7 @@
import org.jruby.RubyFloat;
import org.jruby.compiler.Compilable;
import org.jruby.exceptions.Unrescuable;
import org.jruby.ir.IRScope;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.BreakInstr;
import org.jruby.ir.instructions.CallBase;
Expand Down Expand Up @@ -55,6 +56,7 @@
import org.jruby.ir.operands.UnboxedFixnum;
import org.jruby.ir.operands.UnboxedFloat;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRDeoptimization;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
Expand Down Expand Up @@ -155,39 +157,43 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block
return processReturnOp(context, block, instr, operation, currDynScope, temp, self, currScope);
case BRANCH_OP:
switch (operation) {
case JUMP: ipc = ((JumpInstr)instr).getJumpTarget().getTargetPC(); break;
default: ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc); break;
case JUMP:
ipc = ((JumpInstr) instr).getJumpTarget().getTargetPC();
break;
default:
ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc);
break;
}
break;
case BOOK_KEEPING_OP:
// IMPORTANT: Preserve these update to currDynScope, self, and args.
// They affect execution of all following instructions in this scope.
switch (operation) {
case PUSH_METHOD_BINDING:
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
break;
case PUSH_BLOCK_BINDING:
currDynScope = IRRuntimeHelpers.pushBlockDynamicScopeIfNeeded(context, block, interpreterContext.pushNewDynScope(), interpreterContext.reuseParentDynScope());
break;
case UPDATE_BLOCK_STATE:
self = IRRuntimeHelpers.updateBlockState(block, self);
break;
case PREPARE_NO_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareNoBlockArgs(context, block, args);
break;
case PREPARE_SINGLE_BLOCK_ARG:
args = IRRuntimeHelpers.prepareSingleBlockArgs(context, block, args);
break;
case PREPARE_FIXED_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareFixedBlockArgs(context, block, args);
break;
case PREPARE_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareBlockArgs(context, block, args, acceptsKeywordArgument);
break;
default:
processBookKeepingOp(interpreterContext, compilable, context, block, instr, operation, name, args, self, blockArg, currDynScope, temp, currScope);
break;
case PUSH_METHOD_BINDING:
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
break;
case PUSH_BLOCK_BINDING:
currDynScope = IRRuntimeHelpers.pushBlockDynamicScopeIfNeeded(context, block, interpreterContext.pushNewDynScope(), interpreterContext.reuseParentDynScope());
break;
case UPDATE_BLOCK_STATE:
self = IRRuntimeHelpers.updateBlockState(block, self);
break;
case PREPARE_NO_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareNoBlockArgs(context, block, args);
break;
case PREPARE_SINGLE_BLOCK_ARG:
args = IRRuntimeHelpers.prepareSingleBlockArgs(context, block, args);
break;
case PREPARE_FIXED_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareFixedBlockArgs(context, block, args);
break;
case PREPARE_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareBlockArgs(context, block, args, acceptsKeywordArgument);
break;
default:
processBookKeepingOp(interpreterContext, compilable, context, block, instr, operation, name, args, self, blockArg, currDynScope, temp, currScope);
break;
}
break;
case MOD_OP:
Expand All @@ -198,6 +204,12 @@ public IRubyObject interpret(ThreadContext context, Compilable compilable, Block
processOtherOp(context, block, instr, operation, currDynScope, currScope, temp, self, floats, fixnums, booleans);
break;
}
} catch (IRDeoptimization e) {
IRScope scope = interpreterContext.getScope();
scope.deoptimize();
instrs = scope.getFullInterpreterContext().getInstructions();
// FIXME: restore deleted
ipc = e.getIPC();
} catch (Throwable t) {
if (debug) extractToMethodToAvoidC2Crash(instr, t);

Expand Down

0 comments on commit 02fe562

Please sign in to comment.