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: 2499589318ad
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c307409c0644
Choose a head ref
  • 3 commits
  • 12 files changed
  • 1 contributor

Commits on Oct 13, 2014

  1. Copy the full SHA
    f458e0c View commit details
  2. Copy the full SHA
    375d9ce View commit details
  3. Copy the full SHA
    c307409 View commit details
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.ir.*;
import org.jruby.ir.operands.InterpreterContext;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.runtime.IRRuntimeHelpers;
@@ -139,8 +140,8 @@ public void ensureInstrsReady() {
// SSS FIXME: Move this out of here to some other place?
// Prepare method if not yet done so we know if the method has an explicit/implicit call protocol
if (method.getInstrsForInterpretation() == null) {
method.prepareForInterpretation(false);
this.pushScope = !method.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
InterpreterContext context = method.prepareForInterpretation(false);
this.pushScope = !context.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
}
}

34 changes: 18 additions & 16 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -108,7 +108,8 @@ public abstract class IRScope implements ParseResult {
/** What passes have been run on this scope? */
private List<CompilerPass> executedPasses;

private Instr[] linearizedInstrArray;
/** What the interpreter depends on to interpret this IRScope */
private InterpreterContext interpreterContext;
private List<BasicBlock> linearizedBBList;
protected int temporaryVariableIndex;
protected int floatVariableIndex;
@@ -155,7 +156,7 @@ protected IRScope(IRScope s, IRScope lexicalParent) {
this.dfProbs = new HashMap<String, DataFlowProblem>();
this.nextVarIndex = new HashMap<String, Integer>(); // SSS FIXME: clone!
this.cfg = null;
this.linearizedInstrArray = null;
this.interpreterContext = null;
this.linearizedBBList = null;

this.flagsComputed = s.flagsComputed;
@@ -187,7 +188,7 @@ public IRScope(IRManager manager, IRScope lexicalParent, String name,
this.dfProbs = new HashMap<String, DataFlowProblem>();
this.nextVarIndex = new HashMap<String, Integer>();
this.cfg = null;
this.linearizedInstrArray = null;
this.interpreterContext = null;
this.linearizedBBList = null;
this.flagsComputed = false;
flags.remove(CAN_RECEIVE_BREAKS);
@@ -466,10 +467,10 @@ public CFG getCFG() {
return cfg;
}

private synchronized Instr[] prepareInstructions() {
private synchronized InterpreterContext prepareInstructions() {
checkRelinearization();

if (linearizedInstrArray != null) return linearizedInstrArray; // Already prepared
if (interpreterContext != null) return interpreterContext; // Already prepared

setupLinearization();

@@ -520,7 +521,7 @@ private synchronized Instr[] prepareInstructions() {
// System.out.println("SCOPE: " + getName());
// System.out.println("INSTRS: " + cfg().toStringInstrs());

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

// Pass 2: Use ipc info from previous to mark all linearized instrs rpc
ipc = 0;
@@ -537,7 +538,10 @@ private synchronized Instr[] prepareInstructions() {
}
}

return linearizedInstrArray;
interpreterContext = new InterpreterContext(getTemporaryVariablesCount(), getBooleanVariablesCount(),
getFixnumVariablesCount(), getFloatVariablesCount(),getFlags().clone(), linearizedInstrArray);

return interpreterContext;
}

private boolean isUnsafeScope() {
@@ -636,13 +640,11 @@ private void initScope(boolean isLambda, boolean jitMode) {
}

/** Run any necessary passes to get the IR ready for interpretation */
public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
public synchronized InterpreterContext prepareForInterpretation(boolean isLambda) {
initScope(isLambda, false);

checkRelinearization();

if (linearizedInstrArray != null) return linearizedInstrArray;

// System.out.println("-- passes run for: " + this + " = " + java.util.Arrays.toString(executedPasses.toArray()));

// Linearize CFG, etc.
@@ -1062,15 +1064,15 @@ public List<Instr> getInstrs() {
return instrList;
}

public Instr[] getInstrsForInterpretation() {
return linearizedInstrArray;
public InterpreterContext getInstrsForInterpretation() {
return interpreterContext;
}

public Instr[] getInstrsForInterpretation(boolean isLambda) {
if (linearizedInstrArray == null) {
public InterpreterContext getInstrsForInterpretation(boolean isLambda) {
if (interpreterContext == null) {
prepareForInterpretation(isLambda);
}
return linearizedInstrArray;
return interpreterContext;
}

public void resetLinearizationData() {
@@ -1113,7 +1115,7 @@ public CFG cfg() {

public void resetState() {
relinearizeCFG = true;
linearizedInstrArray = null;
interpreterContext = null;
cfg.resetState();

// reset flags

This file was deleted.

Original file line number Diff line number Diff line change
@@ -25,10 +25,6 @@ public String toString() {
return super.toString() + "{1F}";
}

public Operand getReceiver() {
return receiver;
}

public long getFixnumArg() {
return fixNum;
}
Original file line number Diff line number Diff line change
@@ -19,10 +19,6 @@ public String toString() {
return super.toString() + "{1OB}";
}

public Operand getReceiver() {
return receiver;
}

public Operand getArg1() {
return getCallArgs()[0];
}
Original file line number Diff line number Diff line change
@@ -18,10 +18,6 @@ public String toString() {
return super.toString() + "{1O}";
}

public Operand getReceiver() {
return receiver;
}

public Operand getArg1() {
return getCallArgs()[0];
}
Original file line number Diff line number Diff line change
@@ -18,10 +18,6 @@ public String toString() {
return super.toString() + "{1O}";
}

public Operand getReceiver() {
return receiver;
}

public Operand getArg1() {
return getCallArgs()[0];
}
Original file line number Diff line number Diff line change
@@ -18,10 +18,6 @@ public String toString() {
return super.toString() + "{0O}";
}

public Operand getReceiver() {
return receiver;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -525,12 +525,13 @@ private static DynamicScope getNewDynScope(ThreadContext context, IRScope scope,

private static IRubyObject interpret(ThreadContext context, IRubyObject self,
IRScope scope, Visibility visibility, RubyModule implClass, String name, IRubyObject[] args, Block block, Block.Type blockType) {
Instr[] instrs = scope.getInstrsForInterpretation(blockType == Block.Type.LAMBDA);
int numTempVars = scope.getTemporaryVariablesCount();
InterpreterContext interpreterContext = scope.getInstrsForInterpretation(blockType == Block.Type.LAMBDA);
Instr[] instrs = interpreterContext.getInstructions();
int numTempVars = interpreterContext.getTemporaryVariablecount();
Object[] temp = numTempVars > 0 ? new Object[numTempVars] : null;
int numFloatVars = scope.getFloatVariablesCount();
int numFixnumVars = scope.getFixnumVariablesCount();
int numBooleanVars = scope.getBooleanVariablesCount();
int numFloatVars = interpreterContext.getTemporaryFloatVariablecount();
int numFixnumVars = interpreterContext.getTemporaryFixnumVariablecount();
int numBooleanVars = interpreterContext.getTemporaryBooleanVariablecount();
double[] floats = numFloatVars > 0 ? new double[numFloatVars] : null;
long[] fixnums = numFixnumVars > 0 ? new long[numFixnumVars] : null;
boolean[] booleans = numBooleanVars > 0 ? new boolean[numBooleanVars] : null;
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/interpreter/Profiler.java
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ public int compare(IRCallSite a, IRCallSite b) {

IRScope tgtMethod = ircs.tgtM.getIRMethod();

Instr[] instrs = tgtMethod.getInstrsForInterpretation();
Instr[] instrs = tgtMethod.getInstrsForInterpretation().getInstructions();
// Dont inline large methods -- 500 is arbitrary
// Can be null if a previously inlined method hasn't been rebuilt
if ((instrs == null) || instrs.length > 500) {
@@ -228,8 +228,8 @@ public int compare(IRScope a, IRScope b) {
if (bden == 0) bden = 1;

// Use estimated instr count to order scopes -- rather than raw thread-poll count
float aCount = scopeThreadPollCounts.get(a).count * (1.0f * a.getInstrsForInterpretation().length/aden);
float bCount = scopeThreadPollCounts.get(b).count * (1.0f * b.getInstrsForInterpretation().length/bden);
float aCount = scopeThreadPollCounts.get(a).count * (1.0f * a.getInstrsForInterpretation().getInstructions().length/aden);
float bCount = scopeThreadPollCounts.get(b).count * (1.0f * b.getInstrsForInterpretation().getInstructions().length/bden);
if (aCount == bCount) return 0;
return (aCount < bCount) ? 1 : -1;
}
67 changes: 67 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/InterpreterContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jruby.ir.operands;

import java.util.EnumSet;
import java.util.List;
import org.jruby.ir.IRFlags;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.transformations.inlining.CloneInfo;

/**
*
*/
public class InterpreterContext extends Operand {
private int temporaryVariablecount;
private int temporaryBooleanVariablecount;
private int temporaryFixnumVariablecount;
private int temporaryFloatVariablecount;

private EnumSet<IRFlags> flags;

private Instr[] instructions;

public InterpreterContext(int temporaryVariablecount, int temporaryBooleanVariablecount,
int temporaryFixnumVariablecount, int temporaryFloatVariablecount,
EnumSet<IRFlags> flags, Instr[] instructions) {
super(null);

this.temporaryVariablecount = temporaryVariablecount;
this.temporaryBooleanVariablecount = temporaryBooleanVariablecount;
this.temporaryFixnumVariablecount = temporaryFixnumVariablecount;
this.temporaryFloatVariablecount = temporaryFloatVariablecount;
this.flags = flags;
this.instructions = instructions;
}

@Override
public void addUsedVariables(List<Variable> l) {}

@Override
public Operand cloneForInlining(CloneInfo ii) {
throw new IllegalStateException("Should not clone interp context");
}


public int getTemporaryVariablecount() {
return temporaryVariablecount;
}

public int getTemporaryBooleanVariablecount() {
return temporaryBooleanVariablecount;
}

public int getTemporaryFixnumVariablecount() {
return temporaryFixnumVariablecount;
}

public int getTemporaryFloatVariablecount() {
return temporaryFloatVariablecount;
}

public EnumSet<IRFlags> getFlags() {
return flags;
}

public Instr[] getInstructions() {
return instructions;
}
}
11 changes: 4 additions & 7 deletions core/src/main/java/org/jruby/runtime/InterpretedIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.jruby.runtime;

import org.jruby.EvalType;
import org.jruby.RubyModule;
import org.jruby.runtime.Block;
import org.jruby.runtime.Binding;
import org.jruby.runtime.ThreadContext;
import org.jruby.ir.operands.InterpreterContext;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRFlags;
import org.jruby.ir.interpreter.Interpreter;
@@ -31,9 +28,9 @@ public InterpretedIRBlockBody(IRClosure closure, Arity arity, int argumentType)
public void ensureInstrsReady(Block.Type blockType) {
// Prepare closure if not yet done so we know if the method requires a dynscope or not
if (closure.getInstrsForInterpretation() == null) {
closure.prepareForInterpretation(blockType == Block.Type.LAMBDA);
this.pushScope = !closure.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
this.reuseParentScope = closure.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE);
InterpreterContext context = closure.prepareForInterpretation(blockType == Block.Type.LAMBDA);
this.pushScope = !context.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED);
this.reuseParentScope = context.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE);
if (IRRuntimeHelpers.isDebug()) {
LOG.info("Executing '" + closure + "'");
// The base IR may not have been processed yet