private static MethodHandle dynamicCallTarget(Signature from, Signature to) { return SmartBinder .from(from) .fold("selfClass", from.asFold(RubyClass.class).permuteWith(PGC, "context", "self")) .permute(to) .cast(to) .invokeVirtualQuiet(lookup(), "call") .handle(); }
mh = binder .permute("context", "self", "arg.*", "block") // filter caller .cast(nc.getNativeReturn(), nc.getNativeSignature()) .invokeStaticQuiet(LOOKUP, nc.getNativeTarget(), nc.getNativeName()) .handle();
.from(Signature.returning(MethodHandle.class).appendArg("args", IRubyObject[].class)) .filterReturn(HANDLE_GETTER.bindTo(varargsTargets)) .cast(int.class, Object.class) .invokeStaticQuiet(LOOKUP, Array.class, "getLength");
.from(Signature.returning(MethodHandle.class).appendArg("args", IRubyObject[].class)) .filterReturn(HANDLE_GETTER.bindTo(varargsTargets)) .cast(int.class, Object.class) .invokeStaticQuiet(LOOKUP, Array.class, "getLength");
mh = binder .permute("context", "self", "arg.*", "block") // filter caller .cast(nc.getNativeReturn(), nc.getNativeSignature()) .invokeStaticQuiet(LOOKUP, nc.getNativeTarget(), nc.getNativeName()) .handle();
private static MethodHandle dynamicCallTarget(Signature from, Signature to) { return SmartBinder .from(from) .fold("selfClass", from.asFold(RubyClass.class).permuteWith(PGC, "context", "self")) .permute(to) .cast(to) .invokeVirtualQuiet(lookup(), "call") .handle(); }
.permute("self") .insert(1, "selfJavaType", self.getClass()) .cast(boolean.class, Object.class, Class.class) .invoke(TEST_CLASS);
.permute("self") .insert(1, "selfJavaType", self.getClass()) .cast(boolean.class, Object.class, Class.class) .invoke(TEST_CLASS);
.from(ARITY_CHECK_FOLD) .append(new String[]{"min", "max"}, new Class[]{int.class, int.class}, specificArity, specificArity) .cast(ARITY_CHECK_SIGNATURE) .invokeStaticQuiet(LOOKUP, Arity.class, "checkArgumentCount");
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) throws Throwable { RubyClass selfClass = pollAndGetClass(context, self); MethodHandle mh; CacheEntry entry = selfClass.searchWithCache(methodName); DynamicMethod method = entry.method; if (method.isBuiltin() && selfClass == context.runtime.getHash()) { // fast path since we know we're working with a normal hash and have a pre-frozen string mh = SmartBinder.from(signature) .permute("self", "context", "arg0") .cast(IRubyObject.class, RubyHash.class, ThreadContext.class, IRubyObject.class) .invokeVirtual(MethodHandles.publicLookup(), "op_aref") .handle(); SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData(); updateInvocationTarget(mh, self, selfClass, method, switchPoint); return ((RubyHash) self).op_aref(context, args[0]); } else { // slow path follows normal invoke logic with a strDup for the key SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData(); // strdup for this call args[0] = ((RubyString) args[0]).strDup(context.runtime); if (methodMissing(entry, caller)) { return callMethodMissing(entry, callType, context, self, selfClass, methodName, args, block); } mh = getHandle(self, selfClass, method); // strdup for future calls mh = MethodHandles.filterArguments(mh, 3, STRDUP_FILTER); updateInvocationTarget(mh, self, selfClass, entry.method, switchPoint); return method.call(context, self, selfClass, methodName, args, block); } }
.from(ARITY_CHECK_FOLD) .append(new String[]{"min", "max"}, new Class[]{int.class, int.class}, specificArity, specificArity) .cast(ARITY_CHECK_SIGNATURE) .invokeStaticQuiet(LOOKUP, Arity.class, "checkArgumentCount");
public IRubyObject invoke(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) throws Throwable { RubyClass selfClass = pollAndGetClass(context, self); MethodHandle mh; CacheEntry entry = selfClass.searchWithCache(methodName); DynamicMethod method = entry.method; if (method.isBuiltin() && selfClass == context.runtime.getHash()) { // fast path since we know we're working with a normal hash and have a pre-frozen string mh = SmartBinder.from(signature) .permute("self", "context", "arg0") .cast(IRubyObject.class, RubyHash.class, ThreadContext.class, IRubyObject.class) .invokeVirtual(MethodHandles.publicLookup(), "op_aref") .handle(); SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData(); updateInvocationTarget(mh, self, selfClass, method, switchPoint); return ((RubyHash) self).op_aref(context, args[0]); } else { // slow path follows normal invoke logic with a strDup for the key SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData(); // strdup for this call args[0] = ((RubyString) args[0]).strDup(context.runtime); if (methodMissing(entry, caller)) { return callMethodMissing(entry, callType, context, self, selfClass, methodName, args, block); } mh = getHandle(self, selfClass, method); // strdup for future calls mh = MethodHandles.filterArguments(mh, 3, STRDUP_FILTER); updateInvocationTarget(mh, self, selfClass, entry.method, switchPoint); return method.call(context, self, selfClass, methodName, args, block); } }