public static MethodHandle nullReplacingFilter(Class<?> target) throws NoSuchMethodException, IllegalAccessException { Lookup lookup = MethodHandles.lookup(); MethodHandle returnNull = lookup.findStatic(DynJSCoercionMatrix.class, "returnNull", methodType(Object.class, Object.class)); return Binder.from(methodType(target, Object.class)) //.drop(0) //.insert(0, new Class[]{Object.class}, new Object[]{null}) .invoke(returnNull); }
public MethodHandle getBootstrapMethodHandle() throws NoSuchMethodException, IllegalAccessException { Lookup lookup = MethodHandles.lookup(); return Binder.from(CallSite.class, Lookup.class, String.class, MethodType.class) .insert(0, this) .invokeVirtual(lookup, "bootstrap"); }
public MethodHandle getNormalYieldSpecificHandle() { MethodHandle normalYieldSpecificHandle = this.normalYieldSpecificHandle; if (normalYieldSpecificHandle != null) return normalYieldSpecificHandle; return this.normalYieldSpecificHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class) .append(new Class[] {StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class}, getStaticScope(), null, null, Block.NULL_BLOCK) .invoke(handle); }
private MethodHandle SMFC() { if (_SMFC != null) return _SMFC; return _SMFC = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "searchModuleForConst"); }
private MethodHandle ISC() { if (_ISC != null) return _ISC; return _ISC = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "inheritanceSearchConst"); }
public static CallSite array(Lookup lookup, String name, MethodType type) { MethodHandle handle = Binder .from(type) .collect(1, IRubyObject[].class) .invokeStaticQuiet(LOOKUP, Bootstrap.class, "array"); CallSite site = new ConstantCallSite(handle); return site; }
public static CallSite kwargsHash(Lookup lookup, String name, MethodType type) { MethodHandle handle = Binder .from(lookup, type) .collect(2, IRubyObject[].class) .invokeStaticQuiet(LOOKUP, Bootstrap.class, "kwargsHash"); CallSite site = new ConstantCallSite(handle); return site; }
private MethodHandle noCacheISC() { if (_noCacheISC != null) return _noCacheISC; return _noCacheISC = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "noCacheInheritanceSearchConst"); } }
public MethodHandle getTestBlockBody() { final MethodHandle testBlockBody = this.testBlockBody; if (testBlockBody != null) return testBlockBody; return this.testBlockBody = Binder.from(boolean.class, ThreadContext.class, Block.class).drop(0).append(this).invoke(TEST_BLOCK_BODY); }
@Override public Binder prepareBinder() { return Binder .from(type()) .filterReturn(CACHE.bindTo(this)); } }
private MethodHandle noCacheSMFC() { if (_noCacheSMFC != null) return _noCacheSMFC; return _noCacheSMFC = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "noCacheSearchModuleForConst"); }
/** * Process the incoming arguments by calling the given static method on the * given class, inserting the result as the first argument. * * @param lookup the java.lang.invoke.MethodHandles.Lookup to use * @param target the class on which the method is defined * @param method the method to invoke on the first argument * @return a new Binder */ public Binder foldStatic(MethodHandles.Lookup lookup, Class<?> target, String method) { return fold(Binder.from(type()).invokeStaticQuiet(lookup, target, method)); }
@Override public MethodHandle guardMethodHandle(MethodType inputType) throws Exception { Binder binder = Binder.from(inputType); return binder.drop(0, inputType.parameterCount()) .constant(false); } }
public static RubyString frozenString(MutableCallSite site, ByteList value, int cr, String file, int line, ThreadContext context) throws Throwable { RubyString frozen = IRRuntimeHelpers.newFrozenString(context, value, cr, file, line); MethodHandle handle = Binder.from(RubyString.class, ThreadContext.class) .dropAll() .constant(frozen); site.setTarget(handle); return frozen; }
public static void checkpointFallback(MutableCallSite site, ThreadContext context) throws Throwable { Ruby runtime = context.runtime; Invalidator invalidator = runtime.getCheckpointInvalidator(); MethodHandle target = Binder .from(void.class, ThreadContext.class) .nop(); MethodHandle fallback = lookup().findStatic(Bootstrap.class, "checkpointFallback", methodType(void.class, MutableCallSite.class, ThreadContext.class)); fallback = fallback.bindTo(site); target = ((SwitchPoint)invalidator.getData()).guardWithTest(target, fallback); site.setTarget(target); }
public static CallSite constLookup(MethodHandles.Lookup lookup, String searchType, MethodType type, String constName, int publicOnly, int callConstMissing) { ConstantLookupSite site = new ConstantLookupSite(type, constName, publicOnly == 0 ? false : true, callConstMissing == 0 ? false : true); MethodHandle handle = Binder .from(lookup, type) .insert(0, site) .invokeVirtualQuiet(lookup, searchType); site.setTarget(handle); return site; }
public static CallSite contextValue(Lookup lookup, String name, MethodType type) { MutableCallSite site = new MutableCallSite(type); site.setTarget(Binder.from(type).append(site).invokeStaticQuiet(lookup, Bootstrap.class, name)); return site; }
public static IRubyObject symbol(MutableCallSite site, String name, ThreadContext context) { RubySymbol symbol = RubySymbol.newSymbol(context.runtime, name); site.setTarget(Binder .from(IRubyObject.class, ThreadContext.class) .drop(0) .constant(symbol) ); return symbol; }
public boolean init(IRubyObject obj) { IRubyObject nil = obj.getRuntime().getNil(); setTarget( Binder.from(type()) .insert(0, RubyNil.class, nil) .invokeStaticQuiet(LOOKUP, IsNilSite.class, "isNil") ); return nil == obj; }
public static CallSite fstring(Lookup lookup, String name, MethodType type, String value, String encodingName, int cr, String file, int line) { MutableCallSite site = new MutableCallSite(type); Binder binder = Binder .from(RubyString.class, ThreadContext.class) .insert(0, arrayOf(MutableCallSite.class, ByteList.class, int.class, String.class, int.class), site, bytelist(value, encodingName), cr, file, line); site.setTarget(binder.invokeStaticQuiet(lookup, Bootstrap.class, "frozenString")); return site; }