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

Commits on Dec 30, 2014

  1. Copy the full SHA
    756049d View commit details
  2. - Use primitive array instead of arraylist

    - null/empty args uses same instance for call arg list
    - simplify logic of buildCallArgs since it no longer needs attrassign logic in it
    enebo committed Dec 30, 2014
    Copy the full SHA
    8b84a83 View commit details
Showing with 45 additions and 64 deletions.
  1. +0 −4 core/src/main/java/org/jruby/ast/ArrayNode.java
  2. +45 −60 core/src/main/java/org/jruby/ir/IRBuilder.java
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ast/ArrayNode.java
Original file line number Diff line number Diff line change
@@ -40,10 +40,6 @@
* Represents an array. This could be an array literal, quoted words or some args stuff.
*/
public class ArrayNode extends ListNode implements ILiteralNode {
// This field is used during argument processing to avoid putting RubyArray
// instances that are purely for utility purposes into ObjectSpace.
private boolean lightweight = false;

public ArrayNode(ISourcePosition position, Node firstNode) {
super(position, firstNode);

105 changes: 45 additions & 60 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -587,53 +587,37 @@ protected Operand buildAttrAssignCallArgs(List<Operand> argsList, Node args, IRS
throw new NotCompilableException("Invalid node for attrassign call args: " + args.getClass().getSimpleName() + ":" + args.getPosition());
}

// Return the last argument in the list -- AttrAssign needs it
protected Operand buildCallArgs(List<Operand> argsList, Node args, IRScope s) {
protected Operand[] buildCallArgs(Node args, IRScope s) {
switch (args.getNodeType()) {
case ARGSCATNODE: {
ArgsCatNode argsCatNode = (ArgsCatNode)args;
Operand v1 = build(argsCatNode.getFirstNode(), s);
Operand v2 = build(argsCatNode.getSecondNode(), s);
Variable res = s.createTemporaryVariable();
addInstr(s, new BuildCompoundArrayInstr(res, v1, v2, false));
argsList.add(new Splat(res, true));
return v2;
}
case ARGSPUSHNODE: {
ArgsPushNode argsPushNode = (ArgsPushNode)args;
Operand v1 = build(argsPushNode.getFirstNode(), s);
Operand v2 = build(argsPushNode.getSecondNode(), s);
Variable res = s.createTemporaryVariable();
addInstr(s, new BuildCompoundArrayInstr(res, v1, v2, true));
argsList.add(new Splat(res, true));
return v2;
}
case ARGSCATNODE:
case ARGSPUSHNODE:
return new Operand[] { new Splat(build(args, s), true) };
case ARRAYNODE: {
ArrayNode arrayNode = (ArrayNode)args;
List<Node> children = arrayNode.childNodes();
// explode array, it's an internal "args" array
for (Node n: children) {
argsList.add(build(n, s));
List<Node> children = args.childNodes();
int numberOfArgs = children.size();
Operand[] builtArgs = new Operand[numberOfArgs];

for (int i = 0; i < numberOfArgs; i++) {
builtArgs[i] = build(children.get(i), s);
}
break;
}
case SPLATNODE: {
Splat splat = new Splat(build(((SplatNode)args).getValue(), s), true);
argsList.add(splat);
break;
}
default: {
throw new NotCompilableException("Invalid node for callArgs: " + args.getClass().getSimpleName() + ":" + args.getPosition());
return builtArgs;
}
case SPLATNODE:
return new Operand[] { new Splat(build(((SplatNode) args).getValue(), s), true) };
}

return argsList.isEmpty() ? manager.getNil() : argsList.get(argsList.size() - 1);
throw new NotCompilableException("Invalid node for call args: " + args.getClass().getSimpleName() + ":" + args.getPosition());
}

public Operand[] setupCallArgs(Node args, IRScope s) {
return args == null ? Operand.EMPTY_ARRAY : buildCallArgs(args, s);
}

public List<Operand> setupCallArgs(Node args, IRScope s) {
List<Operand> argsList = new ArrayList<>();
if (args != null) buildCallArgs(argsList, args, s);
return argsList;
public static Operand[] addArg(Operand[] args, Operand extraArg) {
Operand[] newArgs = new Operand[args.length + 1];
System.arraycopy(args, 0, newArgs, 0, args.length);
newArgs[args.length] = extraArg;
return newArgs;
}

// Non-arg masgn (actually a nested masgn)
@@ -859,9 +843,9 @@ private Operand buildAttrAssign(final AttrAssignNode attrAssignNode, IRScope s)
public Operand buildAttrAssignAssignment(Node node, IRScope s, Operand value) {
final AttrAssignNode attrAssignNode = (AttrAssignNode) node;
Operand obj = build(attrAssignNode.getReceiverNode(), s);
List<Operand> args = setupCallArgs(attrAssignNode.getArgsNode(), s);
args.add(value);
addInstr(s, new AttrAssignInstr(obj, attrAssignNode.getName(), args.toArray(new Operand[args.size()])));
Operand[] args = setupCallArgs(attrAssignNode.getArgsNode(), s);
args = addArg(args, value);
addInstr(s, new AttrAssignInstr(obj, attrAssignNode.getName(), args));
return value;
}

@@ -1006,10 +990,10 @@ public Operand buildCall(CallNode callNode, IRScope s) {
// that is incorrect IR because the receiver has to be built *before* call arguments are built
// to preserve expected code execution order
Operand receiver = build(receiverNode, s);
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand[] args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(callNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = (CallInstr)CallInstr.create(callResult, callNode.getName(), receiver, args.toArray(new Operand[args.size()]), block).specializeForInterpretation();
CallInstr callInstr = (CallInstr)CallInstr.create(callResult, callNode.getName(), receiver, args, block).specializeForInterpretation();

// This is to support the ugly Proc.new with no block, which must see caller's frame
if (
@@ -2223,10 +2207,10 @@ public Operand buildFalse() {

public Operand buildFCall(FCallNode fcallNode, IRScope s) {
Node callArgsNode = fcallNode.getArgsNode();
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand[] args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(fcallNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = (CallInstr)CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args.toArray(new Operand[args.size()]), block).specializeForInterpretation();
CallInstr callInstr = (CallInstr)CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args, block).specializeForInterpretation();
receiveBreakException(s, block, callInstr);
return callResult;
}
@@ -2844,12 +2828,12 @@ public Operand buildOpElementAsgnWithOr(OpElementAsgnNode opElementAsgnNode, IRS
Operand array = build(opElementAsgnNode.getReceiverNode(), s);
Label l = s.getNewLabel();
Variable elt = s.createTemporaryVariable();
List<Operand> argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
addInstr(s, CallInstr.create(elt, "[]", array, argList.toArray(new Operand[argList.size()]), null));
Operand[] argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
addInstr(s, CallInstr.create(elt, "[]", array, argList, null));
addInstr(s, BEQInstr.create(elt, manager.getTrue(), l));
Operand value = build(opElementAsgnNode.getValueNode(), s);
argList.add(value);
addInstr(s, CallInstr.create(elt, "[]=", array, argList.toArray(new Operand[argList.size()]), null));
argList = addArg(argList, value);
addInstr(s, CallInstr.create(elt, "[]=", array, argList, null));
addInstr(s, new CopyInstr(elt, value));
addInstr(s, new LabelInstr(l));
return elt;
@@ -2860,12 +2844,13 @@ public Operand buildOpElementAsgnWithAnd(OpElementAsgnNode opElementAsgnNode, IR
Operand array = build(opElementAsgnNode.getReceiverNode(), s);
Label l = s.getNewLabel();
Variable elt = s.createTemporaryVariable();
List<Operand> argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
addInstr(s, CallInstr.create(elt, "[]", array, argList.toArray(new Operand[argList.size()]), null));
Operand[] argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
addInstr(s, CallInstr.create(elt, "[]", array, argList, null));
addInstr(s, BEQInstr.create(elt, manager.getFalse(), l));
Operand value = build(opElementAsgnNode.getValueNode(), s);
argList.add(value);
addInstr(s, CallInstr.create(elt, "[]=", array, argList.toArray(new Operand[argList.size()]), null));

argList = addArg(argList, value);
addInstr(s, CallInstr.create(elt, "[]=", array, argList, null));
addInstr(s, new CopyInstr(elt, value));
addInstr(s, new LabelInstr(l));
return elt;
@@ -2880,17 +2865,17 @@ public Operand buildOpElementAsgnWithAnd(OpElementAsgnNode opElementAsgnNode, IR
// val = buildCall([]=, arr, arg, val)
public Operand buildOpElementAsgnWithMethod(OpElementAsgnNode opElementAsgnNode, IRScope s) {
Operand array = build(opElementAsgnNode.getReceiverNode(), s);
List<Operand> argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
Operand[] argList = setupCallArgs(opElementAsgnNode.getArgsNode(), s);
Variable elt = s.createTemporaryVariable();
addInstr(s, CallInstr.create(elt, "[]", array, argList.toArray(new Operand[argList.size()]), null)); // elt = a[args]
addInstr(s, CallInstr.create(elt, "[]", array, argList, null)); // elt = a[args]
Operand value = build(opElementAsgnNode.getValueNode(), s); // Load 'value'
String operation = opElementAsgnNode.getOperatorName();
addInstr(s, CallInstr.create(elt, operation, elt, new Operand[] { value }, null)); // elt = elt.OPERATION(value)
// SSS: do not load the call result into 'elt' to eliminate the RAW dependency on the call
// We already know what the result is going be .. we are just storing it back into the array
Variable tmp = s.createTemporaryVariable();
argList.add(elt);
addInstr(s, CallInstr.create(tmp, "[]=", array, argList.toArray(new Operand[argList.size()]), null)); // a[args] = elt
argList = addArg(argList, elt);
addInstr(s, CallInstr.create(tmp, "[]=", array, argList, null)); // a[args] = elt
return elt;
}

@@ -3307,10 +3292,10 @@ private Operand buildSuperInstr(IRScope s, Operand block, Operand[] args) {
public Operand buildSuper(SuperNode superNode, IRScope s) {
if (s.isModuleBody()) return buildSuperInScriptBody(s);

List<Operand> args = setupCallArgs(superNode.getArgsNode(), s);
Operand[] args = setupCallArgs(superNode.getArgsNode(), s);
Operand block = setupCallClosure(superNode.getIterNode(), s);
if (block == null) block = getImplicitBlockArg(s);
return buildSuperInstr(s, block, args.toArray(new Operand[args.size()]));
return buildSuperInstr(s, block, args);
}

private Operand buildSuperInScriptBody(IRScope s) {