Skip to content

Commit

Permalink
Use the same interp context that was used to determine canCallDirect()
Browse files Browse the repository at this point in the history
This prevents massaging the arg array twice -- once implicitly in
the JRuby runtime and another time explicitly in the IR instructions
after the call protocol instrs. have been added to the block's IR.
subbuss committed Dec 19, 2015
1 parent c6a03e4 commit ad8fb3f
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 8 additions & 4 deletions core/src/main/java/org/jruby/runtime/InterpretedIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ public class InterpretedIRBlockBody extends IRBlockBody implements Compilable<In
private boolean displayedCFG = false; // FIXME: Remove when we find nicer way of logging CFG
private int callCount = 0;
private InterpreterContext interpreterContext;
private InterpreterContext fullInterpreterContext;

public InterpretedIRBlockBody(IRClosure closure, Signature signature) {
super(closure, signature);
@@ -40,7 +41,7 @@ public void setCallCount(int callCount) {

@Override
public void completeBuild(InterpreterContext interpreterContext) {
this.interpreterContext = interpreterContext;
this.fullInterpreterContext = interpreterContext;
// This enables IR & CFG to be dumped in debug mode
// when this updated code starts executing.
this.displayedCFG = false;
@@ -65,6 +66,7 @@ public InterpreterContext ensureInstrsReady() {

if (interpreterContext == null) {
interpreterContext = closure.getInterpreterContext();
fullInterpreterContext = interpreterContext;
}
return interpreterContext;
}
@@ -81,7 +83,7 @@ public String getName() {

@Override
public boolean canCallDirect() {
return interpreterContext != null && interpreterContext.hasExplicitCallProtocol();
return fullInterpreterContext != null && fullInterpreterContext.hasExplicitCallProtocol();
}

@Override
@@ -102,8 +104,10 @@ protected IRubyObject commonYieldPath(ThreadContext context, Block block, Block.

InterpreterContext ic = ensureInstrsReady();

// double check since instructionContext is set up lazily
if (canCallDirect()) callOrYieldDirect(context, block, type, args, self, blockArg);
// Update interpreter context for next time this block is executed
// This ensures that if we had determined canCallDirect() is false
// based on the old IC, we continue to execute with it.
interpreterContext = fullInterpreterContext;

Binding binding = block.getBinding();
Visibility oldVis = binding.getFrame().getVisibility();
Original file line number Diff line number Diff line change
@@ -118,9 +118,6 @@ protected IRubyObject commonYieldPath(ThreadContext context, Block block, Block.

InterpreterContext ic = ensureInstrsReady();

// double check if full build completed
if (canCallDirect()) return callOrYieldDirect(context, block, type, args, self, blockArg);

Binding binding = block.getBinding();
Visibility oldVis = binding.getFrame().getVisibility();
Frame prevFrame = context.preYieldNoScope(binding);

0 comments on commit ad8fb3f

Please sign in to comment.