Skip to content

Commit

Permalink
Stick a fork in rescueMap's eye...add rpc field to instr to eliminate…
Browse files Browse the repository at this point in the history
… need for map since all instrs need rpc anyways
  • Loading branch information
enebo committed Oct 10, 2014
1 parent 2d6bff1 commit 583bc54
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
34 changes: 8 additions & 26 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -112,7 +112,6 @@ public abstract class IRScope implements ParseResult {

private Instr[] linearizedInstrArray;
private List<BasicBlock> linearizedBBList;
private Map<Integer, Integer> rescueMap;
protected int temporaryVariableIndex;
protected int floatVariableIndex;
protected int fixnumVariableIndex;
Expand Down Expand Up @@ -476,7 +475,7 @@ private synchronized Instr[] prepareInstructions() {

setupLinearization();

// Set up IPCs
// Pass 1. Set up IPCs for labels and instruct and build linear instr list
List<Instr> newInstrs = new ArrayList<Instr>();
HashMap<Label, Integer> labelIPCMap = new HashMap<Label, Integer>();
int ipc = 0;
Expand Down Expand Up @@ -504,34 +503,22 @@ private synchronized Instr[] prepareInstructions() {
}
}

cfg().getExitBB().getLabel().setTargetPC(ipc + 1); // Exit BB ipc

// System.out.println("SCOPE: " + getName());
// System.out.println("INSTRS: " + cfg().toStringInstrs());

// Exit BB ipc
cfg().getExitBB().getLabel().setTargetPC(ipc + 1);

//System.out.println("CFG.original");
//System.out.println(cfg().toStringInstrs());

//System.out.println("CFG.new");
//System.out.println(cfg().clone(new SimpleCloneInfo(this, false), this).toStringInstrs());

// Set up rescue map
setupRescueMap();

linearizedInstrArray = newInstrs.toArray(new Instr[newInstrs.size()]);
return linearizedInstrArray;
}

public void setupRescueMap() {
this.rescueMap = new HashMap<Integer, Integer>();
// Pass 2: Use ipc info from before to mark all instrs rpc
for (BasicBlock b : linearizedBBList) {
BasicBlock rescuerBB = cfg().getRescuerBBFor(b);
int rescuerPC = (rescuerBB == null) ? -1 : rescuerBB.getLabel().getTargetPC();
for (Instr i : b.getInstrs()) {
rescueMap.put(i.getIPC(), rescuerPC);
i.setRPC(rescuerPC);
}
}

linearizedInstrArray = newInstrs.toArray(new Instr[newInstrs.size()]);
return linearizedInstrArray;
}

private boolean isUnsafeScope() {
Expand Down Expand Up @@ -1086,10 +1073,6 @@ public List<BasicBlock> buildLinearization() {
return linearizedBBList;
}

public Map<Integer, Integer> getRescueMap() {
return this.rescueMap;
}

public List<BasicBlock> linearization() {
depends(cfg());

Expand Down Expand Up @@ -1125,7 +1108,6 @@ public void resetState() {
flags.remove(HAS_NONLOCAL_RETURNS);
flags.remove(CAN_RECEIVE_BREAKS);
flags.remove(CAN_RECEIVE_NONLOCAL_RETURNS);
rescueMap = null;

// Invalidate compiler pass state.
//
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ir/instructions/Instr.java
Expand Up @@ -33,7 +33,8 @@
public abstract class Instr {
public static final Operand[] EMPTY_OPERANDS = new Operand[] {};

private int ipc;
private int ipc; // Interpreter-only: instruction pointer
private int rpc; // Interpreter-only: rescue pointer
private final Operation operation;
// Is this instruction live or dead? During optimization passes, if this instruction
// causes no side-effects and the result of the instruction is not needed by anyone else,
Expand All @@ -43,6 +44,7 @@ public abstract class Instr {

public Instr(Operation operation) {
this.ipc = -1;
this.rpc = -1;
this.operation = operation;
}

Expand All @@ -60,6 +62,10 @@ public Operation getOperation() {

public void setIPC(int ipc) { this.ipc = ipc; }

public int getRPC() { return rpc; }

public void setRPC(int rpc) { this.rpc = rpc; }

// Does this instruction have side effects as a result of its operation
// This information is used in optimization phases to impact dead code elimination
// and other optimization passes
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Expand Up @@ -510,11 +510,8 @@ private static void processOtherOp(ThreadContext context, Instr instr, Operation
}

private static IRubyObject interpret(ThreadContext context, IRubyObject self,
IRScope scope, Visibility visibility, RubyModule implClass, String name, IRubyObject[] args, Block block, Block.Type blockType)
{
IRScope scope, Visibility visibility, RubyModule implClass, String name, IRubyObject[] args, Block block, Block.Type blockType) {
Instr[] instrs = scope.getInstrsForInterpretation(blockType == Block.Type.LAMBDA);
Map<Integer, Integer> rescueMap = scope.getRescueMap();

int numTempVars = scope.getTemporaryVariablesCount();
Object[] temp = numTempVars > 0 ? new Object[numTempVars] : null;
int numFloatVars = scope.getFloatVariablesCount();
Expand Down Expand Up @@ -598,7 +595,7 @@ private static IRubyObject interpret(ThreadContext context, IRubyObject self,
extractToMethodToAvoidC2Crash(context, instr, t);

if (debug) LOG.info("in scope: " + scope + ", caught Java throwable: " + t + "; excepting instr: " + instr);
ipc = rescueMap.get(instr.getIPC());
ipc = instr.getRPC();
if (debug) LOG.info("ipc for rescuer: " + ipc);

if (ipc == -1) {
Expand Down
Expand Up @@ -177,6 +177,7 @@ public void cloneInstrs(SimpleCloneInfo ii) {
for (Instr i: oldInstrs) {
Instr clonedInstr = i.clone(ii);
clonedInstr.setIPC(i.getIPC());
clonedInstr.setRPC(i.getRPC());
instrs.add(clonedInstr);
}
}
Expand Down

0 comments on commit 583bc54

Please sign in to comment.