Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 13, 2014
2 parents 12e8bb6 + 8d34a50 commit 32c248b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -26,18 +26,22 @@ public class IRClosure extends IRScope {

private int nestingDepth; // How many nesting levels within a method is this closure nested in?

private BlockBody body;

private boolean isBeginEndBlock;

// Block parameters
private List<Operand> blockArgs;

/** The parameter names, for Proc#parameters */
private String[] parameterList;

private Arity arity;
private int argumentType;
public boolean addedGEBForUncaughtBreaks;

/** Added for interp/JIT purposes */
private BlockBody body;

/** Added for JIT purposes */
private Handle handle;

// Used by other constructions and by IREvalScript as well
Expand Down Expand Up @@ -288,6 +292,8 @@ protected IRClosure cloneForInlining(CloneInfo ii, IRClosure clone) {
// FIXME: This is fragile. Untangle this state.
// Why is this being copied over to InterpretedIRBlockBody?
clone.setParameterList(this.parameterList);
clone.addedGEBForUncaughtBreaks = this.addedGEBForUncaughtBreaks;
clone.isBeginEndBlock = this.isBeginEndBlock;

SimpleCloneInfo clonedII = ii.cloneForCloningClosure(clone);

Expand Down
34 changes: 24 additions & 10 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -19,6 +19,7 @@
import org.jruby.ir.representations.BasicBlock;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.representations.CFGLinearizer;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CFGInliner;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
Expand Down Expand Up @@ -476,29 +477,42 @@ private synchronized Instr[] prepareInstructions() {
setupLinearization();

SimpleCloneInfo cloneInfo = new SimpleCloneInfo(this, false);
// Clear old set
initNestedClosures();

// FIXME: If CFG (or linearizedBBList) knew number of instrs we could end up allocing better

// Pass 1. Set up IPCs for labels and instruct and build linear instr list
// Pass 1. Set up IPCs for labels and instructions and build linear instr list
List<Instr> newInstrs = new ArrayList<Instr>();
int ipc = 0;
for (BasicBlock b: linearizedBBList) {
// All same-named labels must be same Java instance for this to work or we would need
// to examine all Label operands and update this as well which would be expensive.
b.getLabel().setTargetPC(ipc);
Label l = b.getLabel();
Label newL = cloneInfo.getRenamedLabel(l);
l.setTargetPC(ipc);
newL.setTargetPC(ipc);

List<Instr> bbInstrs = b.getInstrs();
int bbInstrsLength = bbInstrs.size();
for (int i = 0; i < bbInstrsLength; i++) {
Instr instr = bbInstrs.get(i);

if (instr instanceof Specializeable) {
instr = ((Specializeable) instr).specializeForInterpretation();
bbInstrs.set(i, instr);
}

if (!(instr instanceof ReceiveSelfInstr)) {
newInstrs.add(instr);
instr.setIPC(ipc);
Instr newInstr = instr.clone(cloneInfo);
// if (newInstr == instr) {
// System.out.println("Instruction " + instr.getOperation() + " returns itself on clone. Probably fragile!");
// }

if (newInstr instanceof Specializeable) {
newInstr = ((Specializeable) newInstr).specializeForInterpretation();
// Make sure debug CFG is identical to interpreted instr output
if (IRRuntimeHelpers.isDebug()) {
bbInstrs.set(i, ((Specializeable) instr).specializeForInterpretation());
}
}

newInstrs.add(newInstr);
newInstr.setIPC(ipc);
ipc++;
}
}
Expand Down
Expand Up @@ -16,23 +16,20 @@ public ClosureLocalVariable(IRClosure scope, String name, int scopeDepth, int lo
this.definingScope = scope;
}

@Override
public int hashCode() {
return name.hashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof ClosureLocalVariable)) return false;

return name.equals(((LocalVariable) obj).name);
return hashCode() == obj.hashCode();
}

public int compareTo(Object arg0) {
// ENEBO: what should compareTo when it is not comparable?
if (!(arg0 instanceof ClosureLocalVariable)) return 0;

return name.compareTo(((LocalVariable) arg0).name);
int a = hashCode();
int b = arg0.hashCode();
return a < b ? -1 : (a == b ? 0 : 1);
}

@Override
Expand Down
11 changes: 8 additions & 3 deletions core/src/main/java/org/jruby/ir/operands/LocalVariable.java
Expand Up @@ -19,6 +19,7 @@ public class LocalVariable extends Variable implements DepthCloneable {
protected final String name;
protected final int scopeDepth;
protected final int offset;
protected final int hcode;

// FIXME: We should resolve to an index into an array but localvariable has no allocator
public LocalVariable(String name, int scopeDepth, int location) {
Expand All @@ -30,6 +31,7 @@ protected LocalVariable(OperandType type, String name, int scopeDepth, int locat
this.name = name;
this.scopeDepth = scopeDepth;
this.offset = location;
this.hcode = (name + ":" + offset).hashCode();
}

public boolean isSameDepth(LocalVariable other) {
Expand Down Expand Up @@ -60,20 +62,23 @@ public String toString() {

@Override
public int hashCode() {
return name.hashCode();
return hcode;
}

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof LocalVariable)) return false;

return name.equals(((LocalVariable) obj).name);
return hashCode() == obj.hashCode();
}

public int compareTo(Object arg0) {
// ENEBO: what should compareTo when it is not comparable?
if (!(arg0 instanceof LocalVariable)) return 0;

return name.compareTo(((LocalVariable) arg0).name);
int a = hashCode();
int b = arg0.hashCode();
return a < b ? -1 : (a == b ? 0 : 1);
}

@Override
Expand Down

0 comments on commit 32c248b

Please sign in to comment.