Skip to content
Permalink
Browse files
Plug in specialized fixnum RHS 1-arg calls, as in 1.7.
  • Loading branch information
headius committed Dec 22, 2014
1 parent f5d1f9b commit dcd9597d78dcd21200799ecefa4ce36b67878256
@@ -987,7 +987,7 @@ public Operand buildCall(CallNode callNode, IRScope s) {
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(callNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(callResult, callNode.getName(), receiver, args.toArray(new Operand[args.size()]), block);
CallInstr callInstr = (CallInstr)CallInstr.create(callResult, callNode.getName(), receiver, args.toArray(new Operand[args.size()]), block).specializeForInterpretation();

// This is to support the ugly Proc.new with no block, which must see caller's frame
if (
@@ -2204,7 +2204,7 @@ public Operand buildFCall(FCallNode fcallNode, IRScope s) {
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(fcallNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args.toArray(new Operand[args.size()]), block);
CallInstr callInstr = (CallInstr)CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args.toArray(new Operand[args.size()]), block).specializeForInterpretation();
receiveBreakException(s, block, callInstr);
return callResult;
}
@@ -3381,7 +3381,7 @@ public Operand buildVAlias(VAliasNode valiasNode, IRScope s) {

public Operand buildVCall(VCallNode node, IRScope s) {
Variable callResult = s.createTemporaryVariable();
Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, node.getName(), s.getSelf(), NO_ARGS, null);
Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, node.getName(), s.getSelf(), NO_ARGS, null).specializeForInterpretation();
addInstr(s, callInstr);
return callResult;
}
@@ -5,6 +5,9 @@
import org.jruby.ir.instructions.boxing.*;
import org.jruby.ir.instructions.defined.GetErrorInfoInstr;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Boolean;

@@ -75,6 +78,8 @@ private void error(Object object) {
public void NonlocalReturnInstr(NonlocalReturnInstr nonlocalreturninstr) { error(nonlocalreturninstr); }
public void NopInstr(NopInstr nopinstr) { error(nopinstr); }
public void NoResultCallInstr(NoResultCallInstr noresultcallinstr) { error(noresultcallinstr); }
public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumArgNoBlockCallInstr) { error(oneFixnumArgNoBlockCallInstr); }
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) { error(oneOperandArgNoBlockCallInstr); }
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) { error(optargmultipleasgninstr); }
public void PopBindingInstr(PopBindingInstr popbindinginstr) { error(popbindinginstr); }
public void PopFrameInstr(PopFrameInstr popframeinstr) { error(popframeinstr); }
@@ -111,6 +116,7 @@ private void error(Object object) {
public void UndefMethodInstr(UndefMethodInstr undefmethodinstr) { error(undefmethodinstr); }
public void UnresolvedSuperInstr(UnresolvedSuperInstr unresolvedsuperinstr) { error(unresolvedsuperinstr); }
public void YieldInstr(YieldInstr yieldinstr) { error(yieldinstr); }
public void ZeroOperandArgNoBlockCallInstr(ZeroOperandArgNoBlockCallInstr zeroOperandArgNoBlockCallInstr) { error(zeroOperandArgNoBlockCallInstr); }
public void ZSuperInstr(ZSuperInstr zsuperinstr) { error(zsuperinstr); }

// "defined" instructions
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Fixnum;
@@ -34,4 +35,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, fixNum);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneFixnumArgNoBlockCallInstr(this);
}
}
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Operand;
@@ -28,4 +29,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
IRubyObject arg1 = (IRubyObject) getCallArgs()[0].retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, arg1);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneOperandArgNoBlockCallInstr(this);
}
}
@@ -1,8 +1,8 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
@@ -24,4 +24,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco

return getCallSite().call(context, self, object);
}

@Override
public void visit(IRVisitor visitor) {
visitor.ZeroOperandArgNoBlockCallInstr(this);
}
}
@@ -13,6 +13,9 @@
import org.jruby.ir.instructions.boxing.*;
import org.jruby.ir.instructions.defined.GetErrorInfoInstr;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.Float;
@@ -23,6 +26,7 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.invokedynamic.InvokeDynamicSupport;
import org.jruby.util.ByteList;
import org.jruby.util.ClassDefiningClassLoader;
import org.jruby.util.JavaNameMangler;
@@ -1281,6 +1285,52 @@ public void NoResultCallInstr(NoResultCallInstr noResultCallInstr) {
compileCallCommon(m, name, args, receiver, numArgs, closure, hasClosure, callType, null);
}

@Override
public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumArgNoBlockCallInstr) {
if (MethodIndex.getFastFixnumOpsMethod(oneFixnumArgNoBlockCallInstr.getName()) == null) {
CallInstr(oneFixnumArgNoBlockCallInstr);
return;
}
IRBytecodeAdapter m = jvmMethod();
String name = oneFixnumArgNoBlockCallInstr.getName();
long fixnum = oneFixnumArgNoBlockCallInstr.getFixnumArg();
Operand receiver = oneFixnumArgNoBlockCallInstr.getReceiver();
Operand closure = oneFixnumArgNoBlockCallInstr.getClosureArg(null);
boolean hasClosure = closure != null;
CallType callType = oneFixnumArgNoBlockCallInstr.getCallType();
Variable result = oneFixnumArgNoBlockCallInstr.getResult();

m.loadContext();

// for visibility checking without requiring frame self
// TODO: don't bother passing when fcall or vcall, and adjust callsite appropriately
m.loadSelf(); // caller

visit(receiver);

String signature = sig(IRubyObject.class, params(ThreadContext.class, IRubyObject.class, IRubyObject.class));

m.adapter.invokedynamic(
"fixnumOperator:" + JavaNameMangler.mangleMethodName(name),
signature,
InvokeDynamicSupport.getFixnumOperatorHandle(),
fixnum,
"",
0);

if (result != null) {
jvmStoreLocal(result);
} else {
// still need to drop, since all dyncalls return something (FIXME)
m.adapter.pop();
}
}

@Override
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) {
CallInstr(oneOperandArgNoBlockCallInstr);
}

@Override
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) {
visit(optargmultipleasgninstr.getArrayArg());
@@ -1781,6 +1831,11 @@ public void YieldInstr(YieldInstr yieldinstr) {
jvmStoreLocal(yieldinstr.getResult());
}

@Override
public void ZeroOperandArgNoBlockCallInstr(ZeroOperandArgNoBlockCallInstr zeroOperandArgNoBlockCallInstr) {
CallInstr(zeroOperandArgNoBlockCallInstr);
}

@Override
public void ZSuperInstr(ZSuperInstr zsuperinstr) {
String name = zsuperinstr.getName();
@@ -51,44 +51,44 @@
public class MathLinker {
private static final Logger LOG = LoggerFactory.getLogger("MathLinker");

// public static CallSite fixnumOperatorBootstrap(Lookup lookup, String name, MethodType type, long value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
// String[] names = name.split(":");
// String operator = JavaNameMangler.demangleMethodName(names[1]);
// JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, false, false, true);
//
// MethodHandle target = lookup.findStatic(MathLinker.class, "fixnumOperator",
// methodType(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, long.class));
// target = insertArguments(target, 3, site, value);
//
// site.setTarget(target);
// return site;
// }
//
// public static CallSite fixnumBooleanBootstrap(Lookup lookup, String name, MethodType type, long value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
// String[] names = name.split(":");
// String operator = JavaNameMangler.demangleMethodName(names[1]);
// JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, false, false, true);
//
// MethodHandle target = lookup.findStatic(MathLinker.class, "fixnumBoolean",
// methodType(boolean.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, long.class));
// target = insertArguments(target, 3, site, value);
//
// site.setTarget(target);
// return site;
// }
//
// public static CallSite floatOperatorBootstrap(Lookup lookup, String name, MethodType type, double value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
// String[] names = name.split(":");
// String operator = JavaNameMangler.demangleMethodName(names[1]);
// JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, false, false, true);
//
// MethodHandle target = lookup.findStatic(MathLinker.class, "floatOperator",
// methodType(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, double.class));
// target = insertArguments(target, 3, site, value);
//
// site.setTarget(target);
// return site;
// }
public static CallSite fixnumOperatorBootstrap(Lookup lookup, String name, MethodType type, long value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, true);

MethodHandle target = lookup.findStatic(MathLinker.class, "fixnumOperator",
methodType(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, long.class));
target = insertArguments(target, 3, site, value);

site.setTarget(target);
return site;
}

public static CallSite fixnumBooleanBootstrap(Lookup lookup, String name, MethodType type, long value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, true);

MethodHandle target = lookup.findStatic(MathLinker.class, "fixnumBoolean",
methodType(boolean.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, long.class));
target = insertArguments(target, 3, site, value);

site.setTarget(target);
return site;
}

public static CallSite floatOperatorBootstrap(Lookup lookup, String name, MethodType type, double value, String file, int line) throws NoSuchMethodException, IllegalAccessException {
String[] names = name.split(":");
String operator = JavaNameMangler.demangleMethodName(names[1]);
JRubyCallSite site = new JRubyCallSite(lookup, type, CallType.NORMAL, file, line, operator, true);

MethodHandle target = lookup.findStatic(MathLinker.class, "floatOperator",
methodType(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, JRubyCallSite.class, double.class));
target = insertArguments(target, 3, site, value);

site.setTarget(target);
return site;
}

public static IRubyObject fixnumOperator(ThreadContext context, IRubyObject caller, IRubyObject self, JRubyCallSite site, long value) throws Throwable {
String operator = site.name();

0 comments on commit dcd9597

Please sign in to comment.