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: da56754e6695
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9003bdd06452
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Dec 22, 2014

  1. Implement correct semantics for record end block instruction

    * It shouldn't get registered with the top-level script scope in which
      the end-block is defined in since there can be multiple script
      scopes depending on requires. They should instead be registered
      with the runtime which already has code to handle this.
    
    * This automatically fixes (a) ordering issues (b) exception handling
      to match MRI semantics.
    
    * There are some other failures to work through, rip out existing code,
      and add JIT support.
    subbuss committed Dec 22, 2014
    Copy the full SHA
    40279f9 View commit details
  2. Copy the full SHA
    9003bdd View commit details
3 changes: 0 additions & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2917,9 +2917,6 @@ public Operand buildPostExe(PostExeNode postExeNode, IRScope s) {
closureBuilder.addInstr(endClosure, new CopyInstr(endClosure.getCurrentModuleVariable(), new ScopeModule(0)));
closureBuilder.build(postExeNode.getBodyNode(), endClosure);

// Record to IRScope so JIT can pre-compile all potentially activated END blocks.
topLevel.recordEndBlock(endClosure);

// Add an instruction in 's' to record the end block in the 'topLevel' scope.
// SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes
// might be broken currently. We could either fix it or consider dropping support
15 changes: 1 addition & 14 deletions core/src/main/java/org/jruby/ir/IREvalScript.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@

public class IREvalScript extends IRClosure {
private List<IRClosure> beginBlocks;
private List<IRClosure> endBlocks;
private EvalType evalType;

public IREvalScript(IRManager manager, IRScope lexicalParent, String fileName,
@@ -68,22 +67,10 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
beginBlocks.add(beginBlockClosure);
}

/* Record an end block -- not all scope implementations can handle them */
@Override
public void recordEndBlock(IRClosure endBlockClosure) {
if (endBlocks == null) endBlocks = new ArrayList<>();
endBlockClosure.setBeginEndBlock();
endBlocks.add(endBlockClosure);
}

public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}

public List<IRClosure> getEndBlocks() {
return endBlocks;
}

@Override
public LocalVariable getNewFlipStateVariable() {
String flipVarName = "%flip_" + allocateNextPrefixedName("%flip");
@@ -101,4 +88,4 @@ public boolean isScriptScope() {
public boolean isFlipScope() {
return true;
}
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -1108,11 +1108,6 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
throw new RuntimeException("BEGIN blocks cannot be added to: " + this.getClass().getName());
}

/* Record an end block. Only eval and script body scopes support this */
public void recordEndBlock(IRClosure endBlockClosure) {
throw new RuntimeException("END blocks cannot be added to: " + this.getClass().getName());
}

public List<IRClosure> getBeginBlocks() {
return null;
}
14 changes: 0 additions & 14 deletions core/src/main/java/org/jruby/ir/IRScriptBody.java
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

public class IRScriptBody extends IRScope {
private List<IRClosure> beginBlocks;
private List<IRClosure> endBlocks;
private DynamicScope toplevelScope;

public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScope) {
@@ -59,24 +58,11 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
beginBlocks.add(beginBlockClosure);
}

/* Record an end block -- not all scope implementations can handle them */
@Override
public void recordEndBlock(IRClosure endBlockClosure) {
if (endBlocks == null) endBlocks = new ArrayList<IRClosure>();
endBlockClosure.setBeginEndBlock();
endBlocks.add(endBlockClosure);
}

@Override
public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}

@Override
public List<IRClosure> getEndBlocks() {
return endBlocks;
}

@Override
public boolean isScriptScope() {
return true;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public enum Operation {
MASGN_REST(0),
RAISE_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
RAISE_REQUIRED_KEYWORD_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
RECORD_END_BLOCK(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
RECORD_END_BLOCK(OpFlags.f_has_side_effect),
RESCUE_EQQ(OpFlags.f_can_raise_exception), // a === call used in rescue
RUNTIME_HELPER(OpFlags.f_has_side_effect | OpFlags.f_can_raise_exception),
SET_CAPTURED_VAR(OpFlags.f_can_raise_exception),
Original file line number Diff line number Diff line change
@@ -5,6 +5,11 @@
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class RecordEndBlockInstr extends Instr implements FixedArityInstr {
private final IRScope declaringScope;
@@ -47,8 +52,11 @@ public Instr clone(CloneInfo ii) {
return new RecordEndBlockInstr(declaringScope, (WrappedIRClosure) endBlockClosure.cloneForInlining(ii));
}

public void interpret() {
((BeginEndInterpreterContext) declaringScope.getTopLevelScope().getInterpreterContext()).recordEndBlock(endBlockClosure);
@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
Block blk = (Block) endBlockClosure.retrieve(context, self, currScope, context.getCurrentScope(), temp);
context.runtime.pushExitBlock(context.runtime.newProc(Block.Type.LAMBDA, blk));
return null;
}

@Override
Original file line number Diff line number Diff line change
@@ -13,25 +13,14 @@
*/
public class BeginEndInterpreterContext extends InterpreterContext {
private List<IRClosure> beginBlocks;
private List<WrappedIRClosure> endBlocks = null;

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

beginBlocks = scope.getBeginBlocks();
}

public void recordEndBlock(WrappedIRClosure block) {
if (endBlocks == null) endBlocks = new ArrayList<>();

if (!endBlocks.contains(block)) endBlocks.add(block);
}

public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}

public List<WrappedIRClosure> getEndBlocks() {
return endBlocks;
}
}
17 changes: 0 additions & 17 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -66,18 +66,6 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
}
}

public static void runEndBlocks(List<WrappedIRClosure> blocks, ThreadContext context, IRubyObject self, StaticScope currScope, Object[] temp) {
if (blocks == null) return;

for (WrappedIRClosure block: blocks) {
try {
((Block) block.retrieve(context, self, currScope, context.getCurrentScope(), temp)).yield(context, null);
} catch (Exception e) {
System.err.println(e);
}
}
}

@Override
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.prepareForInterpretation();
@@ -113,7 +101,6 @@ protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject se
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} finally {
runEndBlocks(ic.getEndBlocks(), context, self, scope, null);
dumpStats();
context.popScope();
}
@@ -355,9 +342,6 @@ private static void processBookKeepingOp(ThreadContext context, Instr instr, Ope
case LINE_NUM:
context.setLine(((LineNumberInstr)instr).lineNumber);
break;
case RECORD_END_BLOCK:
((RecordEndBlockInstr)instr).interpret();
break;
case TRACE: {
if (context.runtime.hasEventHooks()) {
TraceInstr trace = (TraceInstr) instr;
@@ -696,7 +680,6 @@ private static IRubyObject evalCommon(ThreadContext context, DynamicScope evalSc

return Interpreter.INTERPRET_EVAL(context, self, ic, ic.getStaticScope().getModule(), EMPTY_ARGS, name, block, null);
} finally {
runEndBlocks(ic.getEndBlocks(), context, self, ss, null);
evalScope.clearEvalType();
context.popScope();
}