Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 01deae8d94b1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f0f2acc32bfe
Choose a head ref
  • 2 commits
  • 12 files changed
  • 1 contributor

Commits on Mar 12, 2015

  1. Copy the full SHA
    dc73005 View commit details
  2. Reverse order of constructors for b* instrs to match internal orderin…

    …g so decode can use in-order
    
    decoding.  I have internally rearranged their order so that operands[0] would be a label for all
    branch types a month or two ago.  This unfortunately meant if I left constructors as-is I would
    need to decode out of order to match our constructors...
    
    Add decode.decodeLabel to not have to cast everywhere.
    enebo committed Mar 12, 2015
    Copy the full SHA
    f0f2acc View commit details
Original file line number Diff line number Diff line change
@@ -498,9 +498,9 @@ private void boxRequiredVars(Instr i, UnboxState state, Map<Variable, TemporaryL
if (ua == a) {
newInstrs.add(i);
} else if (op == Operation.B_TRUE) {
newInstrs.add(new BTrueInstr(Operation.B_TRUE, ua, bi.getJumpTarget()));
newInstrs.add(new BTrueInstr(bi.getJumpTarget(), ua));
} else {
newInstrs.add(new BFalseInstr(Operation.B_FALSE, ua, bi.getJumpTarget()));
newInstrs.add(new BFalseInstr(bi.getJumpTarget(), ua));
}
} else {
newInstrs.add(i);
19 changes: 13 additions & 6 deletions core/src/main/java/org/jruby/ir/instructions/BEQInstr.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.*;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
@@ -13,20 +14,26 @@
public class BEQInstr extends TwoOperandBranchInstr implements FixedArityInstr {
public static BranchInstr create(Operand v1, Operand v2, Label jmpTarget) {
if (v2 instanceof Boolean) {
return ((Boolean) v2).isTrue() ? new BTrueInstr(v1, jmpTarget) : new BFalseInstr(v1, jmpTarget);
return ((Boolean) v2).isTrue() ? new BTrueInstr(jmpTarget, v1) : new BFalseInstr(jmpTarget, v1);
}
if (v2 instanceof Nil) return new BNilInstr(v1, jmpTarget);
if (v2 == UndefinedValue.UNDEFINED) return new BUndefInstr(v1, jmpTarget);
return new BEQInstr(v1, v2, jmpTarget);
if (v2 instanceof Nil) return new BNilInstr(jmpTarget, v1);
if (v2 == UndefinedValue.UNDEFINED) return new BUndefInstr(jmpTarget, v1);

return new BEQInstr(jmpTarget, v1, v2);
}

protected BEQInstr(Operand v1, Operand v2, Label jmpTarget) {
protected BEQInstr(Label jmpTarget, Operand v1, Operand v2) {
super(Operation.BEQ, v1, v2, jmpTarget);
}

@Override
public Instr clone(CloneInfo ii) {
return new BEQInstr(getArg1().cloneForInlining(ii), getArg2().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BEQInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii), getArg2().cloneForInlining(ii));
}


public static BEQInstr decode(IRReaderDecoder d) {
return new BEQInstr(d.decodeLabel(), d.decodeOperand(), d.decodeOperand());
}

@Override
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/ir/instructions/BFalseInstr.java
Original file line number Diff line number Diff line change
@@ -4,25 +4,25 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class BFalseInstr extends OneOperandBranchInstr implements FixedArityInstr {
// Public only for persistence reloading
public BFalseInstr(Operation op, Operand v, Label jmpTarget) {
super(op, new Operand[] {jmpTarget, v});
}

public BFalseInstr(Operand v, Label jmpTarget) {
public BFalseInstr(Label jmpTarget, Operand v) {
super(Operation.B_FALSE, new Operand[] {jmpTarget, v});
}

@Override
public Instr clone(CloneInfo ii) {
return new BFalseInstr(getOperation(), getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BFalseInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii));
}

public static BFalseInstr decode(IRReaderDecoder d) {
return new BFalseInstr(d.decodeLabel(), d.decodeOperand());
}

@Override
14 changes: 9 additions & 5 deletions core/src/main/java/org/jruby/ir/instructions/BNEInstr.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
@@ -15,19 +16,22 @@
public class BNEInstr extends TwoOperandBranchInstr implements FixedArityInstr {
public static BranchInstr create(Operand v1, Operand v2, Label jmpTarget) {
if (v2 instanceof Boolean) {
return ((Boolean) v2).isFalse() ? new BTrueInstr(v1, jmpTarget) : new BFalseInstr(v1, jmpTarget);
return ((Boolean) v2).isFalse() ? new BTrueInstr(jmpTarget, v1) : new BFalseInstr(jmpTarget, v1);
}
return new BNEInstr(v1, v2, jmpTarget);
return new BNEInstr(jmpTarget, v1, v2);
}

public BNEInstr(Operand v1, Operand v2, Label jmpTarget) {
public BNEInstr(Label jmpTarget, Operand v1, Operand v2) {
super(Operation.BNE, v1, v2, jmpTarget);
}

@Override
public Instr clone(CloneInfo ii) {
return new BNEInstr(getArg1().cloneForInlining(ii),
getArg2().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BNEInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii), getArg2().cloneForInlining(ii));
}

public static BNEInstr decode(IRReaderDecoder d) {
return new BNEInstr(d.decodeLabel(), d.decodeOperand(), d.decodeOperand());
}

@Override
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BNilInstr.java
Original file line number Diff line number Diff line change
@@ -4,20 +4,25 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class BNilInstr extends OneOperandBranchInstr implements FixedArityInstr {
public BNilInstr(Operand v, Label jmpTarget) {
public BNilInstr(Label jmpTarget, Operand v) {
super(Operation.B_NIL, new Operand[] {jmpTarget, v});
}

@Override
public Instr clone(CloneInfo ii) {
return new BNilInstr(getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BNilInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii));
}

public static BNilInstr decode(IRReaderDecoder d) {
return new BNilInstr(d.decodeLabel(), d.decodeOperand());
}

@Override
15 changes: 8 additions & 7 deletions core/src/main/java/org/jruby/ir/instructions/BTrueInstr.java
Original file line number Diff line number Diff line change
@@ -4,24 +4,25 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class BTrueInstr extends OneOperandBranchInstr implements FixedArityInstr {
public BTrueInstr(Operation op, Operand v, Label jmpTarget) {
super(op, new Operand[] {jmpTarget, v});
}

public BTrueInstr(Operand v, Label jmpTarget) {
this(Operation.B_TRUE, v, jmpTarget);
public BTrueInstr(Label jmpTarget, Operand v) {
super(Operation.B_TRUE, new Operand[] { jmpTarget, v });
}

@Override
public Instr clone(CloneInfo ii) {
return new BTrueInstr(getOperation(), getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BTrueInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii));
}

public static BTrueInstr decode(IRReaderDecoder d) {
return new BTrueInstr(d.decodeLabel(), d.decodeOperand());
}

@Override
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BUndefInstr.java
Original file line number Diff line number Diff line change
@@ -5,20 +5,25 @@
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class BUndefInstr extends OneOperandBranchInstr implements FixedArityInstr {
public BUndefInstr(Operand v, Label jmpTarget) {
public BUndefInstr(Label jmpTarget, Operand v) {
super(Operation.B_UNDEF, new Operand[] {jmpTarget, v});
}

@Override
public Instr clone(CloneInfo ii) {
return new BUndefInstr(getArg1().cloneForInlining(ii), ii.getRenamedLabel(getJumpTarget()));
return new BUndefInstr(ii.getRenamedLabel(getJumpTarget()), getArg1().cloneForInlining(ii));
}

public static BUndefInstr decode(IRReaderDecoder d) {
return new BUndefInstr(d.decodeLabel(), d.decodeOperand());
}

@Override
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Fixnum;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
@@ -58,6 +57,11 @@ public void encode(IRWriterEncoder e) {
e.encode(opt);
e.encode(rest);
e.encode(receivesKeywords);
e.encode(restKey);
}

public static CheckArityInstr decode(IRReaderDecoder d) {
return new CheckArityInstr(d.decodeInt(), d.decodeInt(), d.decodeInt(), d.decodeBoolean(), d.decodeInt());
}

public void checkArity(ThreadContext context, Object[] args) {
24 changes: 16 additions & 8 deletions core/src/main/java/org/jruby/ir/persistence/IRReader.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jruby.util.KeyValuePair;

/**
*
@@ -35,15 +36,23 @@ public static IRScope load(IRManager manager, IRReaderDecoder file) throws IOExc
int scopesToRead = file.decodeInt();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("scopes to read = " + scopesToRead);

IRScope script = decodeScopeHeader(manager, file);
for (int i = 1; i < scopesToRead; i++) {
decodeScopeHeader(manager, file);
KeyValuePair<IRScope, Integer>[] scopes = new KeyValuePair[scopesToRead];
for (int i = 0; i < scopesToRead; i++) {
scopes[i] = decodeScopeHeader(manager, file);
}

return script;
// Lifecycle woes. All IRScopes need to exist before we can decodeInstrs.
for (KeyValuePair<IRScope, Integer> pair: scopes) {
IRScope scope = pair.getKey();
int instructionsOffset = pair.getValue();

scope.allocateInterpreterContext(file.decodeInstructionsAt(scope, instructionsOffset));
}

return scopes[0].getKey(); // topmost scope;
}

private static IRScope decodeScopeHeader(IRManager manager, IRReaderDecoder decoder) {
private static KeyValuePair<IRScope, Integer> decodeScopeHeader(IRManager manager, IRReaderDecoder decoder) {
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("DECODING SCOPE HEADER");
IRScopeType type = decoder.decodeIRScopeType();
if (RubyInstanceConfig.IR_READING_DEBUG) System.out.println("IRScopeType = " + type);
@@ -80,9 +89,8 @@ private static IRScope decodeScopeHeader(IRManager manager, IRReaderDecoder deco
decoder.addScope(scope);

int instructionsOffset = decoder.decodeInt();
decoder.decodeInstructionsAt(scope, instructionsOffset);

return scope;
return new KeyValuePair<>(scope, instructionsOffset);
}

private static Map<String, LocalVariable> decodeScopeLocalVariables(IRReaderDecoder decoder, IRScope scope) {
@@ -143,6 +151,6 @@ public static IRScope createScope(IRManager manager, IRScopeType type, String na
return new IREvalScript(manager, lexicalParent, lexicalParent.getFileName(), line, staticScope, EvalType.NONE);
}

return null;
throw new RuntimeException("No such scope type: " + type);
}
}
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.ir.operands.TemporaryVariableType;
@@ -47,6 +48,7 @@ public interface IRReaderDecoder {
public long decodeLong();
public double decodeDouble();
public float decodeFloat();
public Label decodeLabel();

public Variable decodeVariable();

10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/ir/persistence/IRReaderFile.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.ir.operands.TemporaryVariableType;
@@ -59,7 +60,7 @@ public IRReaderFile(IRManager manager, File file) {

}

instrDecoderMap = new InstrDecoderMap(manager, this);
instrDecoderMap = new InstrDecoderMap(this);
operandDecoderMap = new OperandDecoderMap(manager, this);
}

@@ -81,6 +82,11 @@ public Encoding decodeEncoding() {
return EncodingDB.getEncodings().get(decodeByteArray()).getEncoding();
}

@Override
public Label decodeLabel() {
return (Label) decodeOperand();
}

@Override
public String decodeString() {
int strLength = decodeInt();
@@ -124,7 +130,7 @@ public Map<String, Operand> getVars() {
@Override
public List<Instr> decodeInstructionsAt(IRScope scope, int offset) {
currentScope = scope;
vars = new HashMap<String, Operand>();
vars = new HashMap<>();
buf.position(offset);

int numberOfInstructions = decodeInt();
Loading