Skip to content

Commit

Permalink
startupInterp rescuePCs stack is built on demand per scope:
Browse files Browse the repository at this point in the history
- Uses less memory for scopes with no exception handling
- Is a little faster because we are not constantly alloc'ing a stack.

Secondly base interpreter engine does not pass this stack as an argument
into processBookkeeping.  It has been moved entirely into startup
interpreter engine.
enebo committed Sep 29, 2015
1 parent 09cfe9b commit 6bd67c2
Showing 4 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings;
import org.jruby.ir.IRScope;
import org.jruby.ir.OpClass;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CopyInstr;
@@ -15,13 +14,8 @@
import org.jruby.ir.instructions.ReturnBase;
import org.jruby.ir.instructions.RuntimeHelperCall;
import org.jruby.ir.instructions.SearchConstInstr;
import org.jruby.ir.instructions.TraceInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockNoResultCallInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.TemporaryFixnumVariable;
import org.jruby.ir.operands.TemporaryFloatVariable;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
@@ -34,7 +28,7 @@
import org.jruby.runtime.opto.ConstantCache;

/**
* Created by enebo on 2/5/15.
* An interpreter which puts common subset of instrs in main switch.
*/
public class BodyInterpreterEngine extends InterpreterEngine {
@Override
Original file line number Diff line number Diff line change
@@ -170,7 +170,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, null);
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass);
}
break;
case OTHER_OP:
@@ -327,16 +327,10 @@ protected static void processCall(ThreadContext context, Instr instr, Operation

protected static void processBookKeepingOp(ThreadContext context, Instr instr, Operation operation,
String name, IRubyObject[] args, IRubyObject self, Block block,
Block.Type blockType, RubyModule implClass, Stack<Integer> rescuePCs) {
Block.Type blockType, RubyModule implClass) {
switch(operation) {
case LABEL:
break;
case EXC_REGION_START:
rescuePCs.push(((ExceptionRegionStartMarkerInstr) instr).getFirstRescueBlockLabel().getTargetPC());
break;
case EXC_REGION_END:
rescuePCs.pop();
break;
case PUSH_FRAME:
context.preMethodFrameOnly(implClass, name, self, block);
// Only the top-level script scope has PRIVATE visibility.
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings;
import org.jruby.ir.IRScope;
import org.jruby.ir.OpClass;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CopyInstr;
@@ -34,7 +33,7 @@
import org.jruby.runtime.opto.ConstantCache;

/**
* Created by enebo on 2/7/15.
* An attempt at a minimal subset of instrs for small simple methods.
*/
public class SimpleMethodInterpreterEngine extends InterpreterEngine {
public static Map<Operation, Boolean> OPERATIONS = new HashMap() {{
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
import java.util.Stack;
import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings;
import org.jruby.ir.IRScope;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.BreakInstr;
import org.jruby.ir.instructions.CheckForLJEInstr;
import org.jruby.ir.instructions.CopyInstr;
import org.jruby.ir.instructions.ExceptionRegionStartMarkerInstr;
import org.jruby.ir.instructions.GetFieldInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.JumpInstr;
@@ -45,7 +45,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
DynamicScope currDynScope = context.getCurrentScope();
boolean acceptsKeywordArgument = interpreterContext.receivesKeywordArguments();

Stack<Integer> rescuePCs = new Stack<>();
Stack<Integer> rescuePCs = null;

// Init profiling this scope
boolean debug = IRRuntimeHelpers.isDebug();
@@ -93,14 +93,22 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
}
break;
case BOOK_KEEPING_OP:
if (operation == Operation.PUSH_BINDING) {
// IMPORTANT: Preserve this update of currDynScope.
// This affects execution of all instructions in this scope
// which will now use the updated value of currDynScope.
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else {
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass, rescuePCs);
switch (operation) {
case PUSH_BINDING:
// IMPORTANT: Preserve this update of currDynScope.
// This affects execution of all instructions in this scope
// which will now use the updated value of currDynScope.
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
case EXC_REGION_START:
if (rescuePCs == null) rescuePCs = new Stack<>();
rescuePCs.push(((ExceptionRegionStartMarkerInstr) instr).getFirstRescueBlockLabel().getTargetPC());
break;
case EXC_REGION_END:
rescuePCs.pop();
break;
default:
processBookKeepingOp(context, instr, operation, name, args, self, block, blockType, implClass);
}
break;
case OTHER_OP:
@@ -110,7 +118,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self,
} catch (Throwable t) {
if (debug) extractToMethodToAvoidC2Crash(instr, t);

if (rescuePCs.empty() || (t instanceof IRBreakJump && instr instanceof BreakInstr) ||
if (rescuePCs == null || rescuePCs.empty() || (t instanceof IRBreakJump && instr instanceof BreakInstr) ||
(t instanceof IRReturnJump && instr instanceof NonlocalReturnInstr)) {
ipc = -1;
} else {

0 comments on commit 6bd67c2

Please sign in to comment.