public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) { ClassLoader classLoader = callerLookup.lookupClass().getClassLoader(); checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName()); DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader; MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId); checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList()); return new ConstantCallSite(target); } }
@SuppressWarnings("UnusedDeclaration") public static CallSite bootstrapIntrinsic(MethodHandles.Lookup caller, String name, MethodType type, String callee) throws IllegalAccessException { MethodHandle mh = getMethodHandle(callee, name, type); if (mh == null) { throw new IllegalArgumentException("Could not find intrinsic for " + callee + ":" + name); } return new ConstantCallSite(mh.asType(type)); }
/** * @since 2.5.0 */ public static CallSite staticArrayAccess(MethodHandles.Lookup lookup, String name, MethodType type) { if (type.parameterCount()==2) { return new ConstantCallSite(IndyArrayAccess.arrayGet(type)); } else { return new ConstantCallSite(IndyArrayAccess.arraySet(type)); } } }
@Override public CallSite getField(Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException { try { return new ConstantCallSite(caller.findGetter(owner, fieldName, fieldType)); } catch (ReflectiveOperationException e) { return null; } }
@Override public CallSite getStatic(Lookup caller, String fieldName, Class<?> fieldType, Class<?> owner) throws ReflectiveOperationException { try { return new ConstantCallSite(caller.findStaticGetter(owner, fieldName, fieldType)); } catch (ReflectiveOperationException e) { return null; } }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, MethodType reflectiveCallType) throws Throwable { StructuralCallSite structuralCallSite = new StructuralCallSite(reflectiveCallType); return new ConstantCallSite(MethodHandles.constant(StructuralCallSite.class, structuralCallSite)); } }
@SuppressWarnings("unused") public static CallSite bootstrapRascalPrimitive(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { MethodHandles.Lookup lookup = MethodHandles.lookup(); RascalPrimitive enumElement = RascalPrimitive.valueOf(name); Class<?>[] parameters = type.parameterArray(); int arity = parameters.length - 2; // do not count common arguments cf and rex String suffix = arity <= 2 ? String.valueOf(arity): "N"; Method execute = enumElement.getClass().getMethod("execute" + suffix, parameters); MethodHandle foundMethod = lookup.unreflect(execute).bindTo(enumElement); return new ConstantCallSite(foundMethod.asType(type)); }
@SuppressWarnings("unused") public static CallSite bootstrapMuPrimitive(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { MethodHandles.Lookup lookup = MethodHandles.lookup(); MuPrimitive enumElement = MuPrimitive.valueOf(name); Class<?>[] parameters = type.parameterArray(); int arity = parameters.length; String suffix = arity <= 2 ? String.valueOf(arity): "N"; Method execute = enumElement.getClass().getMethod("execute" + suffix, parameters); MethodHandle foundMethod = lookup.unreflect(execute).bindTo(enumElement); return new ConstantCallSite(foundMethod.asType(type)); }
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; }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, String value) throws Throwable { ClassLoader classLoader = lookup.lookupClass().getClassLoader(); MethodType type = MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", classLoader); Class<?> symbolClass = Class.forName("scala.Symbol", false, classLoader); MethodHandle factoryMethod = lookup.findStatic(symbolClass, "apply", type); Object symbolValue = factoryMethod.invokeWithArguments(value); return new ConstantCallSite(MethodHandles.constant(symbolClass, symbolValue)); } }
public static CallSite hash(Lookup lookup, String name, MethodType type) { MethodHandle handle = Binder .from(lookup, type) .collect(1, IRubyObject[].class) .invokeStaticQuiet(LOOKUP, Bootstrap.class, "hash"); 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; }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, String value) throws Throwable { ClassLoader classLoader = lookup.lookupClass().getClassLoader(); MethodType type = MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", classLoader); Class<?> symbolClass = Class.forName("scala.Symbol", false, classLoader); MethodHandle factoryMethod = lookup.findStatic(symbolClass, "apply", type); Object symbolValue = factoryMethod.invokeWithArguments(value); return new ConstantCallSite(MethodHandles.constant(symbolClass, symbolValue)); } }
public static CallSite bootstrap(Lookup caller, String name, MethodType type, String moduleClass, int arity, int varargs) throws Throwable { Class<?> module = caller.lookupClass().getClassLoader().loadClass(moduleClass); Method function = module.getDeclaredMethod(name, genericMethodType(arity, varargs == 1).parameterArray()); function.setAccessible(true); return new ConstantCallSite(constant( FunctionReference.class, new FunctionReference(caller.unreflect(function), parameterNames(function)))); }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, MethodHandle... targetMethods) throws Throwable { MethodHandle deserializeLambda = lookup.findVirtual(LambdaDeserialize.class, "deserializeLambda", DESERIALIZE_LAMBDA_MT); MethodHandle exact = deserializeLambda.bindTo(new LambdaDeserialize(lookup, targetMethods)).asType(invokedType); return new ConstantCallSite(exact); } public static String nameAndDescriptorKey(String name, String descriptor) {
@Override public <T> ConstantCallSite invokeReducerLongIntReturnLongMethodHandle(T object) { MethodType methodType = MethodType.methodType(long.class, long.class, int.class); try { return new ConstantCallSite(this.lookup.bind(object, this.name(), methodType)); } catch (NoSuchMethodException e) { handle(e, "Method not found", this.name()); } catch (IllegalAccessException e) { handle(e, "Illegal access to method", this.name()); } return null; }
@Override public <T> ConstantCallSite invokeReducerLongIntReturnLongMethodHandle(T object) { MethodType methodType = MethodType.methodType(long.class, long.class, int.class); try { return new ConstantCallSite(this.lookup.bind(object, this.name(), methodType)); } catch (NoSuchMethodException e) { handle(e, "Method not found", this.name()); } catch (IllegalAccessException e) { handle(e, "Illegal access to method", this.name()); } return null; }
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, String prefix) throws Exception { MethodHandle methodHandle = callerLookup.findVirtual(String.class, "concat", MethodType.methodType(String.class, String.class)); methodHandle = methodHandle.bindTo(name + "-" + prefix + "-"); return new ConstantCallSite(methodHandle); } }
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, String prefix) throws Exception { MethodHandle methodHandle = callerLookup.findVirtual(String.class, "concat", MethodType.methodType(String.class, String.class)); methodHandle = methodHandle.bindTo(name + "-" + prefix + "-"); return new ConstantCallSite(methodHandle); } }