Skip to content

Commit

Permalink
Showing 5 changed files with 56 additions and 45 deletions.
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Original file line number Diff line number Diff line change
@@ -113,11 +113,7 @@ public InterpreterContext prepareInterpreterContext(Operand self) {

initScope(false);

Instr[] linearizedInstrArray = prepareInstructions();

interpreterContext = new ClosureInterpreterContext(getStaticScope(), getTemporaryVariablesCount(), getBooleanVariablesCount(),
getFixnumVariablesCount(), getFloatVariablesCount(), getFlags(), linearizedInstrArray,
self, getStaticScope(), getBlockBody());
interpreterContext = new ClosureInterpreterContext(this, prepareInstructions(), self, getBlockBody());

return interpreterContext;
}
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -619,12 +619,7 @@ public synchronized InterpreterContext prepareForInterpretation() {

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

// Linearize CFG, etc.
Instr[] linearizedInstrArray = prepareInstructions();

interpreterContext = new InterpreterContext(staticScope, this instanceof IRMetaClassBody,
getTemporaryVariablesCount(), getBooleanVariablesCount(),
getFixnumVariablesCount(), getFloatVariablesCount(), getFlags(), linearizedInstrArray);
interpreterContext = new InterpreterContext(this, prepareInstructions());

return interpreterContext;
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -529,7 +529,7 @@ private static IRubyObject interpret(ThreadContext context, IRubyObject self,
// Init profiling this scope
boolean debug = IRRuntimeHelpers.isDebug();
boolean profile = IRRuntimeHelpers.inProfileMode();
Integer scopeVersion = profile ? Profiler.initProfiling(scope) : 0;
//Integer scopeVersion = profile ? Profiler.initProfiling(scope) : 0;
boolean acceptsKeywordArgument = interpreterContext.receivesKeywordArguments();

// Enter the looooop!
@@ -557,7 +557,7 @@ private static IRubyObject interpret(ThreadContext context, IRubyObject self,
receiveArg(context, instr, operation, args, acceptsKeywordArgument, currDynScope, temp, exception, block);
break;
case CALL_OP:
if (profile) Profiler.updateCallSite(instr, scope, scopeVersion);
//if (profile) Profiler.updateCallSite(instr, scope, scopeVersion);
processCall(context, instr, operation, currDynScope, currScope, temp, self);
break;
case RET_OP:
@@ -582,7 +582,7 @@ private static IRubyObject interpret(ThreadContext context, IRubyObject self,
} catch (Throwable t) {
extractToMethodToAvoidC2Crash(context, instr, t);

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

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.jruby.ir.operands;

import java.util.EnumSet;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRClosure;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
@@ -13,27 +11,20 @@
import org.jruby.runtime.builtin.IRubyObject;

/**
* Created by enebo on 10/14/14.
* Interpreter knowledge needed to interpret a closure.
*/
public class ClosureInterpreterContext extends InterpreterContext {
private Operand self;
private StaticScope staticScope;
private BlockBody body;

public ClosureInterpreterContext(StaticScope scope, int temporaryVariablecount, int temporaryBooleanVariablecount,
int temporaryFixnumVariablecount, int temporaryFloatVariablecount,
EnumSet<IRFlags> flags, Instr[] instructions,
Operand self, StaticScope staticScope, BlockBody body) {
super(scope, false, temporaryVariablecount, temporaryBooleanVariablecount, temporaryFixnumVariablecount,
temporaryFloatVariablecount, flags, instructions);
public ClosureInterpreterContext(IRClosure scope, Instr[] instructions,
Operand self, BlockBody body) {
super(scope, instructions);

this.self = self;
this.staticScope = staticScope;
this.body = body;
}

public StaticScope getStaticScope() { return staticScope; }

/**
* Blocks have more complicated logic for pushing a dynamic scope (see InterpretedIRBlockBody).
* We throw an error in case somehow we mistakenly try and push a binding.
@@ -45,7 +36,7 @@ public DynamicScope newDynamicScope(ThreadContext context) {

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
staticScope.determineModule();
getStaticScope().determineModule();

// In non-inlining scenarios, this.self will always be %self.
// However, in inlined scenarios, this.self will be the self in the original scope where the closure
61 changes: 45 additions & 16 deletions core/src/main/java/org/jruby/ir/operands/InterpreterContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.jruby.ir.operands;

import java.util.EnumSet;
import java.util.List;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRMetaClassBody;
import org.jruby.ir.IRScope;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
@@ -16,7 +18,11 @@ public class InterpreterContext extends Operand {
private final int temporaryFixnumVariablecount;
private final int temporaryFloatVariablecount;

private StaticScope staticScope;

private final String name;
private final String fileName;
private final int lineNumber;
private final StaticScope staticScope;
private final Instr[] instructions;

// Cached computed fields
@@ -27,24 +33,31 @@ public class InterpreterContext extends Operand {
private final boolean receivesKeywordArguments;
private final boolean metaClassBodyScope;

public InterpreterContext(StaticScope staticScope, boolean metaClassBodyScope,
int temporaryVariablecount, int temporaryBooleanVariablecount,
int temporaryFixnumVariablecount, int temporaryFloatVariablecount,
EnumSet<IRFlags> flags, Instr[] instructions) {
// FIXME: Hack this should be a clone eventually since JIT might change this. Comment for it reflects what it should be.
// View of CFG at time of creating this context.
private CFG cfg = null;

public InterpreterContext(IRScope scope, Instr[] instructions) {
super(null);

this.staticScope = staticScope;
this.metaClassBodyScope = metaClassBodyScope; // IRMetaClassBody
this.temporaryVariablecount = temporaryVariablecount;
this.temporaryBooleanVariablecount = temporaryBooleanVariablecount;
this.temporaryFixnumVariablecount = temporaryFixnumVariablecount;
this.temporaryFloatVariablecount = temporaryFloatVariablecount;
//FIXME: Remove once we conditionally plug in CFG on debug-only
this.cfg = scope.getCFG();

this.name = scope.getName();
this.fileName = scope.getFileName();
this.lineNumber = scope.getLineNumber();
this.staticScope = scope.getStaticScope();
this.metaClassBodyScope = scope instanceof IRMetaClassBody;
this.temporaryVariablecount = scope.getTemporaryVariablesCount();
this.temporaryBooleanVariablecount = scope.getBooleanVariablesCount();
this.temporaryFixnumVariablecount = scope.getFixnumVariablesCount();
this.temporaryFloatVariablecount = scope.getFloatVariablesCount();
this.instructions = instructions;
this.hasExplicitCallProtocol = flags.contains(IRFlags.HAS_EXPLICIT_CALL_PROTOCOL);
this.reuseParentDynScope = flags.contains(IRFlags.REUSE_PARENT_DYNSCOPE);
this.pushNewDynScope = !flags.contains(IRFlags.DYNSCOPE_ELIMINATED) && !this.reuseParentDynScope;
this.hasExplicitCallProtocol = scope.getFlags().contains(IRFlags.HAS_EXPLICIT_CALL_PROTOCOL);
this.reuseParentDynScope = scope.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE);
this.pushNewDynScope = !scope.getFlags().contains(IRFlags.DYNSCOPE_ELIMINATED) && !this.reuseParentDynScope;
this.popDynScope = this.pushNewDynScope || this.reuseParentDynScope;
this.receivesKeywordArguments = flags.contains(IRFlags.RECEIVES_KEYWORD_ARGS);
this.receivesKeywordArguments = scope.getFlags().contains(IRFlags.RECEIVES_KEYWORD_ARGS);
}

@Override
@@ -55,6 +68,10 @@ public Operand cloneForInlining(CloneInfo info) {
throw new IllegalStateException("Should not clone interp context");
}

public String getFileName() {
return fileName;
}

public StaticScope getStaticScope() {
return staticScope;
}
@@ -114,4 +131,16 @@ public boolean receivesKeywordArguments() {
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return super.retrieve(context, self, currScope, currDynScope, temp);
}

@Override
public String toString() {
StringBuilder buf = new StringBuilder();

buf.append(fileName).append(':').append(lineNumber);
if (name != null) buf.append(' ').append(name);

buf.append("\nCFG:\n").append(cfg);

return buf.toString();
}
}

0 comments on commit e71749f

Please sign in to comment.