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 10, 2014
2 parents 9ac8dfa + 8ec4a4a commit 0e19718
Show file tree
Hide file tree
Showing 212 changed files with 1,298 additions and 1,384 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -206,6 +206,7 @@ public static void main(String[] args) {
// If a Truffle exception gets this far it's a hard failure - don't try and dress it up as a Ruby exception

if (main.config.getCompileMode() == RubyInstanceConfig.CompileMode.TRUFFLE) {
System.err.println("Truffle internal error: " + t);
t.printStackTrace(System.err);
} else {
// print out as a nice Ruby backtrace
Expand Down
39 changes: 20 additions & 19 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -804,33 +804,34 @@ public IRubyObject runScriptBody(Script script) {
}

public IRubyObject runInterpreter(ThreadContext context, ParseResult parseResult, IRubyObject self) {
try {
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert parseResult instanceof RootNode;
getTruffleBridge().execute(TranslatorDriver.ParserContext.TOP_LEVEL, getTruffleBridge().toTruffle(self), null, (RootNode) parseResult);
return getNil();
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert parseResult instanceof RootNode;
getTruffleBridge().execute(TranslatorDriver.ParserContext.TOP_LEVEL, getTruffleBridge().toTruffle(self), null, (RootNode) parseResult);
return getNil();
} else {
try {
return Interpreter.getInstance().execute(this, parseResult, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}

return Interpreter.getInstance().execute(this, parseResult, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
}

public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObject self) {
assert rootNode != null : "scriptNode is not null";

try {
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert rootNode instanceof RootNode;
getTruffleBridge().execute(TranslatorDriver.ParserContext.TOP_LEVEL, getTruffleBridge().toTruffle(self), null, (RootNode) rootNode);
return getNil();
}
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert rootNode instanceof RootNode;
getTruffleBridge().execute(TranslatorDriver.ParserContext.TOP_LEVEL, getTruffleBridge().toTruffle(self), null, (RootNode) rootNode);
return getNil();
} else {
try {

// FIXME: retrieve from IRManager unless lifus does it later
return Interpreter.getInstance().execute(this, rootNode, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
// FIXME: retrieve from IRManager unless lifus does it later
return Interpreter.getInstance().execute(this, rootNode, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -13,8 +13,7 @@
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.Float;
import org.jruby.ir.transformations.inlining.CloneMode;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.CallType;
Expand Down Expand Up @@ -221,7 +220,7 @@ public void emitBody(IRBuilder b, IRScope s) {
}

public void cloneIntoHostScope(IRBuilder b, IRScope s) {
InlinerInfo ii = new InlinerInfo(null, s, CloneMode.ENSURE_BLOCK_CLONE);
SimpleCloneInfo ii = new SimpleCloneInfo(s, true);

// Clone required labels.
// During normal cloning below, labels not found in the rename map
Expand All @@ -237,7 +236,7 @@ public void cloneIntoHostScope(IRBuilder b, IRScope s) {
b.addInstr(s, new LabelInstr(ii.getRenamedLabel(start)));
b.addInstr(s, new ExceptionRegionStartMarkerInstr(bodyRescuer));
for (Instr i: instrs) {
Instr clonedInstr = i.cloneForInlining(ii);
Instr clonedInstr = i.clone(ii);
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
Expand Down
50 changes: 26 additions & 24 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Expand Up @@ -4,7 +4,8 @@
import org.jruby.ir.operands.*;
import org.jruby.ir.representations.BasicBlock;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.BlockBody;
Expand Down Expand Up @@ -61,10 +62,11 @@ protected IRClosure(IRManager manager, IRScope lexicalParent, String fileName, i
}

/** Used by cloning code */
protected IRClosure(IRClosure c, IRScope lexicalParent, String prefix) {
/* Inlining generates a new name and id and basic cloning will reuse the originals name */
protected IRClosure(IRClosure c, IRScope lexicalParent, int closureId, String fullName) {
super(c, lexicalParent);
this.closureId = lexicalParent.getNextClosureId();
setName(prefix + closureId);
this.closureId = closureId;
super.setName(fullName);
this.startLabel = getNewLabel(getName() + "_START");
this.endLabel = getNewLabel(getName() + "_END");
if (getManager().isDryRun()) {
Expand Down Expand Up @@ -281,37 +283,38 @@ public int getNestingDepth() {
return nestingDepth;
}

protected IRClosure cloneForInlining(InlinerInfo ii, IRClosure clone) {
protected IRClosure cloneForInlining(CloneInfo ii, IRClosure clone) {
clone.nestingDepth = this.nestingDepth;
clone.parameterList = this.parameterList;

// Create a new inliner info object
InlinerInfo clonedII = ii.cloneForCloningClosure(clone);
SimpleCloneInfo clonedII = ii.cloneForCloningClosure(clone);

if (getCFG() != null) {
// Clone the cfg
CFG clonedCFG = new CFG(clone);
clone.setCFG(clonedCFG);
clonedCFG.cloneForCloningClosure(getCFG(), clone, clonedII);
clone.setCFG(getCFG().clone(clonedII, clone));
} else {
// Clone the instruction list
for (Instr i: getInstrs()) {
Instr clonedInstr = i.cloneForInlining(clonedII);
if (clonedInstr instanceof CallBase) {
CallBase call = (CallBase)clonedInstr;
Operand block = call.getClosureArg(null);
if (block instanceof WrappedIRClosure) clone.addClosure(((WrappedIRClosure)block).getClosure());
}
clone.addInstr(clonedInstr);
clone.addInstr(i.clone(clonedII));
}
}

return clone;
}

public IRClosure cloneForInlining(InlinerInfo ii) {
// FIXME: This is buggy! Is this not dependent on clone-mode??
IRClosure clonedClosure = new IRClosure(this, ii.getNewLexicalParentForClosure(), "_CLOSURE_CLONE_");
public IRClosure cloneForInlining(CloneInfo ii) {
IRClosure clonedClosure;
IRScope lexicalParent = ii.getScope();

if (ii instanceof SimpleCloneInfo && !((SimpleCloneInfo)ii).isEnsureBlockCloneMode()) {
clonedClosure = new IRClosure(this, lexicalParent, closureId, getName());
} else {
int id = lexicalParent.getNextClosureId();
String fullName = lexicalParent.getName() + "_CLOSURE_CLONE_" + id;
clonedClosure = new IRClosure(this, lexicalParent, id, fullName);
}

// WrappedIRClosure should always have a single unique IRClosure in them so we should
// not end up adding n copies of the same closure as distinct clones...
lexicalParent.addClosure(clonedClosure);

return cloneForInlining(ii, clonedClosure);
}
Expand Down Expand Up @@ -361,8 +364,7 @@ protected boolean addGEBForUncaughtBreaks() {
@Override
public void setName(String name) {
// We can distinguish closures only with parent scope name
String fullName = getLexicalParent().getName() + name;
super.setName(fullName);
super.setName(getLexicalParent().getName() + name);
}

public Arity getArity() {
Expand Down
22 changes: 16 additions & 6 deletions core/src/main/java/org/jruby/ir/IRFor.java
@@ -1,6 +1,7 @@
package org.jruby.ir;

import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.parser.StaticScopeFactory;
import org.jruby.runtime.Arity;
Expand All @@ -18,8 +19,8 @@ public IRFor(IRManager manager, IRScope lexicalParent, int lineNumber, StaticSco
}

/** Used by cloning code */
private IRFor(IRClosure c, IRScope lexicalParent) {
super(c, lexicalParent, "_FOR_LOOP_CLONE_");
private IRFor(IRClosure c, IRScope lexicalParent, int id, String fullName) {
super(c, lexicalParent, id, fullName);
}

@Override
Expand All @@ -28,9 +29,18 @@ public IRScopeType getScopeType() {
}

@Override
public IRClosure cloneForInlining(InlinerInfo ii) {
// FIXME: This is buggy! Is this not dependent on clone-mode??
IRClosure clonedClosure = new IRFor(this, ii.getNewLexicalParentForClosure());
public IRClosure cloneForInlining(CloneInfo ii) {
IRClosure clonedClosure;
IRScope lexicalParent = ii.getScope();

if (ii instanceof SimpleCloneInfo) {
clonedClosure = new IRFor(this, lexicalParent, closureId, getName());
} else {
int id = lexicalParent.getNextClosureId();
String fullName = lexicalParent.getName() + "_FOR_LOOP_CLONE_" + id;
clonedClosure = new IRFor(this, lexicalParent, id, fullName);
}

return cloneForInlining(ii, clonedClosure);
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRManager.java
Expand Up @@ -19,7 +19,7 @@
public class IRManager {
public static String SAFE_COMPILER_PASSES = "";
public static String DEFAULT_COMPILER_PASSES = "OptimizeTempVarsPass,LocalOptimizationPass";
public static String DEFAULT_JIT_PASSES = "AddLocalVarLoadStoreInstructions,AddCallProtocolInstructions,EnsureTempsAssigned";
public static String DEFAULT_JIT_PASSES = "DeadCodeElimination,AddLocalVarLoadStoreInstructions,OptimizeDynScopesPass,AddCallProtocolInstructions,EnsureTempsAssigned";
public static String DEFAULT_INLINING_COMPILER_PASSES = "LocalOptimizationPass";

private int dummyMetaClassCount = 0;
Expand Down
20 changes: 12 additions & 8 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -584,14 +584,15 @@ private void runCompilerPasses(List<CompilerPass> passes) {
private void optimizeSimpleScopes() {
// For safe scopes that don't require a dynamic scope,
// run DCE since the analysis is less likely to be
// stymied by escaped bindings.
// stymied by escaped bindings. We can also eliminate
// dynscopes for these scopes.
if (!isUnsafeScope() && !flags.contains(REQUIRES_DYNSCOPE)) {
(new DeadCodeElimination()).run(this);
(new OptimizeDynScopesPass()).run(this);
}
}

public void initScope(boolean isLambda) {
private void initScope(boolean isLambda, boolean jitMode) {
// Reset linearization, if any exists
resetLinearizationData();

Expand All @@ -611,17 +612,19 @@ public void initScope(boolean isLambda) {

runCompilerPasses(getManager().getCompilerPasses(this));

if (RubyInstanceConfig.IR_COMPILER_PASSES == null) {
// Run DCE and var load/store passes where applicable
// But, if we have been passed in a list of passes to run
// on the commandline, skip this opt.
if (!jitMode && RubyInstanceConfig.IR_COMPILER_PASSES == null) {
// Skip this if:
// * we are in JIT mode since they are being run as part
// of JIT passes in a way that minimizes LVA invalidations.
// * we have been passed in a list of passes to run on the
// commandline (so as to honor the commandline request).
optimizeSimpleScopes();
}
}

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

checkRelinearization();

Expand All @@ -643,7 +646,7 @@ public synchronized List<BasicBlock> prepareForCompilation() {
// mark all closures lambdas always. But, check if there are
// other smarts available to us and eliminate adding
// this code to every closure there is.
initScope(this instanceof IRClosure);
initScope(this instanceof IRClosure, true);

runCompilerPasses(getManager().getJITPasses(this));

Expand Down Expand Up @@ -758,6 +761,7 @@ public void computeScopeFlags() {
|| flags.contains(HAS_NONLOCAL_RETURNS)
|| flags.contains(CAN_RECEIVE_NONLOCAL_RETURNS)
|| flags.contains(BINDING_HAS_ESCAPED)
|| flags.contains(USES_ZSUPER)
// SSS FIXME: checkArity for keyword args
// looks up a keyword arg in the static scope
// which currently requires a dynamic scope to
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
Expand Up @@ -6,7 +6,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -49,7 +49,7 @@ public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new AliasInstr(getNewName().cloneForInlining(ii), getOldName().cloneForInlining(ii));
}

Expand Down
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void updateResult(Variable v) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new ArgScopeDepthInstr(ii.getRenamedVariable(result));
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
import org.jruby.ir.instructions.specialized.OneArgOperandAttrAssignInstr;
import org.jruby.ir.operands.MethAddr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
Expand All @@ -22,7 +22,7 @@ public AttrAssignInstr(AttrAssignInstr instr) {
}

@Override
public Instr cloneForInlining(InlinerInfo ii) {
public Instr clone(CloneInfo ii) {
return new AttrAssignInstr(receiver.cloneForInlining(ii),
(MethAddr)getMethodAddr().cloneForInlining(ii), cloneCallArgs(ii));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BEQInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.*;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -25,7 +25,7 @@ protected BEQInstr(Operand v1, Operand v2, Label jmpTarget) {
}

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

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BFalseInstr.java
Expand Up @@ -4,7 +4,7 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.InlinerInfo;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -21,7 +21,7 @@ public BFalseInstr(Operand v, Label jmpTarget) {
}

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

Expand Down

0 comments on commit 0e19718

Please sign in to comment.