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

Commits on Dec 17, 2015

  1. Copy the full SHA
    f424394 View commit details
  2. Copy the full SHA
    27e6a64 View commit details
  3. Copy the full SHA
    5a64d06 View commit details
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ private void error(Object object) {
public void PrepareBlockArgsInstr(PrepareBlockArgsInstr instr) { error(instr); }
public void PrepareFixedBlockArgsInstr(PrepareFixedBlockArgsInstr instr) { error(instr); }
public void PrepareSingleBlockArgInstr(PrepareSingleBlockArgInstr instr) { error(instr); }
public void PrepareNoBlockArgsInstr(PrepareNoBlockArgsInstr instr) { error(instr); }
public void ProcessModuleBodyInstr(ProcessModuleBodyInstr processmodulebodyinstr) { error(processmodulebodyinstr); }
public void PutClassVariableInstr(PutClassVariableInstr putclassvariableinstr) { error(putclassvariableinstr); }
public void PutConstInstr(PutConstInstr putconstinstr) { error(putconstinstr); }
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -219,7 +219,8 @@ public enum Operation {

PREPARE_BLOCK_ARGS(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PREPARE_SINGLE_BLOCK_ARG(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PREPARE_FIXED_BLOCK_ARGS(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect);
PREPARE_FIXED_BLOCK_ARGS(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PREPARE_NO_BLOCK_ARGS(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect);

public final OpClass opClass;
private int flags;
Original file line number Diff line number Diff line change
@@ -17,7 +17,9 @@
import org.jruby.runtime.builtin.IRubyObject;

public class PrepareBlockArgsInstr extends NoOperandInstr implements FixedArityInstr {
public PrepareBlockArgsInstr(Operation op) {
public static final PrepareBlockArgsInstr INSTANCE = new PrepareBlockArgsInstr(Operation.PREPARE_BLOCK_ARGS);

protected PrepareBlockArgsInstr(Operation op) {
super(op);
}

@@ -27,7 +29,7 @@ public Instr clone(CloneInfo ii) {
}

public static PrepareBlockArgsInstr decode(IRReaderDecoder d) {
return new PrepareBlockArgsInstr(Operation.PREPARE_BLOCK_ARGS);
return INSTANCE;
}

@Override
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
import org.jruby.runtime.builtin.IRubyObject;

public class PrepareFixedBlockArgsInstr extends PrepareBlockArgsInstr {
public PrepareFixedBlockArgsInstr() {
public static final PrepareFixedBlockArgsInstr INSTANCE = new PrepareFixedBlockArgsInstr();

private PrepareFixedBlockArgsInstr() {
super(Operation.PREPARE_FIXED_BLOCK_ARGS);
}

@@ -20,7 +22,7 @@ public Instr clone(CloneInfo ii) {
}

public static PrepareFixedBlockArgsInstr decode(IRReaderDecoder d) {
return new PrepareFixedBlockArgsInstr();
return INSTANCE;
}

@Override
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

public class PrepareNoBlockArgsInstr extends PrepareBlockArgsInstr {
public static final PrepareNoBlockArgsInstr INSTANCE = new PrepareNoBlockArgsInstr();

private PrepareNoBlockArgsInstr() {
super(Operation.PREPARE_NO_BLOCK_ARGS);
}

@Override
public Instr clone(CloneInfo ii) {
return ii instanceof SimpleCloneInfo ? new PrepareNoBlockArgsInstr() : NopInstr.NOP; // FIXME: Is this correct
}

public static PrepareNoBlockArgsInstr decode(IRReaderDecoder d) {
return INSTANCE;
}

@Override
public void visit(IRVisitor visitor) {
visitor.PrepareNoBlockArgsInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
import org.jruby.runtime.builtin.IRubyObject;

public class PrepareSingleBlockArgInstr extends PrepareBlockArgsInstr {
public PrepareSingleBlockArgInstr() {
public static final PrepareSingleBlockArgInstr INSTANCE = new PrepareSingleBlockArgInstr();

private PrepareSingleBlockArgInstr() {
super(Operation.PREPARE_SINGLE_BLOCK_ARG);
}

@@ -20,7 +22,7 @@ public Instr clone(CloneInfo ii) {
}

public static PrepareSingleBlockArgInstr decode(IRReaderDecoder d) {
return new PrepareSingleBlockArgInstr();
return INSTANCE;
}

@Override
Original file line number Diff line number Diff line change
@@ -181,6 +181,9 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
case UPDATE_BLOCK_STATE:
self = IRRuntimeHelpers.updateBlockState(block, self);
break;
case PREPARE_NO_BLOCK_ARGS:
args = IRRuntimeHelpers.prepareNoBlockArgs(context, block, args);
break;
case PREPARE_SINGLE_BLOCK_ARG:
args = IRRuntimeHelpers.prepareSingleBlockArgs(context, block, args);
break;
Original file line number Diff line number Diff line change
@@ -110,18 +110,19 @@ public Object execute(IRScope scope, Object... data) {

Signature sig = ((IRClosure)scope).getSignature();

// If it doesn't need any args, no arg preparation involved!
// Add the right kind of arg preparation instruction
int arityValue = sig.arityValue();
if (arityValue != 0) {
// Add the right kind of arg preparation instruction
if (arityValue == 0) {
entryBB.addInstr(PrepareNoBlockArgsInstr.INSTANCE);
} else {
if (sig.isFixed()) {
if (arityValue == 1) {
entryBB.addInstr(new PrepareSingleBlockArgInstr());
entryBB.addInstr(PrepareSingleBlockArgInstr.INSTANCE);
} else {
entryBB.addInstr(new PrepareFixedBlockArgsInstr());
entryBB.addInstr(PrepareFixedBlockArgsInstr.INSTANCE);
}
} else {
entryBB.addInstr(new PrepareBlockArgsInstr(Operation.PREPARE_BLOCK_ARGS));
entryBB.addInstr(PrepareBlockArgsInstr.INSTANCE);
}
}
} else {
41 changes: 30 additions & 11 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -1485,7 +1485,7 @@ public static RubyFixnum getArgScopeDepth(ThreadContext context, StaticScope cur
return context.runtime.newFixnum(i);
}

public static IRubyObject[] toAry(ThreadContext context, IRubyObject[] args) {
private static IRubyObject[] toAry(ThreadContext context, IRubyObject[] args) {
if (args.length == 1 && args[0].respondsTo("to_ary")) {
IRubyObject newAry = Helpers.aryToAry(args[0]);
if (newAry.isNil()) {
@@ -1499,7 +1499,7 @@ public static IRubyObject[] toAry(ThreadContext context, IRubyObject[] args) {
return args;
}

public static IRubyObject[] prepareProcArgs(ThreadContext context, Block b, IRubyObject[] args) {
private static IRubyObject[] prepareProcArgs(ThreadContext context, Block b, IRubyObject[] args) {
if (args.length == 1) {
int arityValue = b.getBody().getSignature().arityValue();
return IRRuntimeHelpers.convertValueIntoArgArray(context, args[0], arityValue, b.type == Block.Type.NORMAL && args[0] instanceof RubyArray);
@@ -1508,7 +1508,7 @@ public static IRubyObject[] prepareProcArgs(ThreadContext context, Block b, IRub
}
}

public static IRubyObject[] prepareBlockArgsInternal(ThreadContext context, Block block, IRubyObject[] args) {
private static IRubyObject[] prepareBlockArgsInternal(ThreadContext context, Block block, IRubyObject[] args) {
// This is the placeholder for scenarios
// not handled by specialized instructions.
if (args == null) {
@@ -1521,7 +1521,8 @@ public static IRubyObject[] prepareBlockArgsInternal(ThreadContext context, Bloc
}

boolean isLambda = block.type == Block.Type.LAMBDA;
if (isLambda && isProcCall) {
if (isLambda) {
block.getBody().getSignature().checkArity(context.runtime, args);
return args;
}

@@ -1573,6 +1574,25 @@ public static IRubyObject[] prepareBlockArgsInternal(ThreadContext context, Bloc
return args;
}

/**
* Check whether incoming args are zero length for a lambda, and no-op for non-lambda.
*
* This could probably be simplified to just an arity check with no return value, but returns the
* incoming args currently for consistency with the other prepares.
*
* @param context
* @param block
* @param args
* @return
*/
@Interp @JIT
public static IRubyObject[] prepareNoBlockArgs(ThreadContext context, Block block, IRubyObject[] args) {
if (block.type == Block.Type.LAMBDA) {
block.getSignature().checkArity(context.runtime, args);
}
return args;
}

@Interp @JIT
public static IRubyObject[] prepareBlockArgs(ThreadContext context, Block block, IRubyObject[] args, boolean usesKwArgs) {
args = prepareBlockArgsInternal(context, block, args);
@@ -1582,6 +1602,7 @@ public static IRubyObject[] prepareBlockArgs(ThreadContext context, Block block,
return args;
}

@Interp @JIT
public static IRubyObject[] prepareFixedBlockArgs(ThreadContext context, Block block, IRubyObject[] args) {
if (args == null) {
return IRubyObject.NULL_ARRAY;
@@ -1592,11 +1613,6 @@ public static IRubyObject[] prepareFixedBlockArgs(ThreadContext context, Block b
return IRRuntimeHelpers.prepareProcArgs(context, block, args);
}

boolean isLambda = block.type == Block.Type.LAMBDA;
if (isLambda && isProcCall) {
return args;
}

// SSS FIXME: This check here is not required as long as
// the single-instruction cases always uses PreapreSingleBlockArgInstr
// But, including this here for robustness for now.
@@ -1614,9 +1630,14 @@ public static IRubyObject[] prepareFixedBlockArgs(ThreadContext context, Block b
return args;
}

@Interp @JIT
public static IRubyObject[] prepareSingleBlockArgs(ThreadContext context, Block block, IRubyObject[] args) {
if (args == null) args = IRubyObject.NULL_ARRAY;

if (block.type == Block.Type.LAMBDA) {
block.getBody().getSignature().checkArity(context.runtime, args);
}

// Deal with proc calls
if (context.getCurrentBlockType() == Block.Type.PROC) {
if (args.length == 0) {
@@ -1628,8 +1649,6 @@ public static IRubyObject[] prepareSingleBlockArgs(ThreadContext context, Block
}
}

if (block.type == Block.Type.LAMBDA) block.getBody().getSignature().checkArity(context.runtime, args);

// Nothing more to do! Hurray!
// If there are insufficient args, ReceivePreReqdInstr will return nil
return args;
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -1441,6 +1441,15 @@ public void PrepareSingleBlockArgInstr(PrepareSingleBlockArgInstr instr) {
jvmMethod().storeArgs();
}

@Override
public void PrepareNoBlockArgsInstr(PrepareNoBlockArgsInstr instr) {
jvmMethod().loadContext();
jvmMethod().loadSelfBlock();
jvmMethod().loadArgs();
jvmMethod().invokeIRHelper("prepareNoBlockArgs", sig(IRubyObject[].class, ThreadContext.class, Block.class, IRubyObject[].class));
jvmMethod().storeArgs();
}

@Override
public void ProcessModuleBodyInstr(ProcessModuleBodyInstr processmodulebodyinstr) {
jvmMethod().loadContext();