/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ @Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name) { return getAnnotatedMethod(implementationClass, Collections.singletonList(desc), name); }
@Override public MethodHandle call() throws Exception { //Class returnClass = method.type().returnType(); int specificArity = -1; if (optional == 0 && !rest) { if (required == 0) { if (actualRequired <= 3) { specificArity = actualRequired; } } else if (required >= 0 && required <= 3) { specificArity = required; } } SmartBinder targetBinder = getBinder(specificArity, isStatic, hasContext, hasBlock); return finishAdapting(targetBinder, implementationClass, rubyName, method, declaringClass, runtime, isStatic, frame); } };
/** * Use code generation to provide a method handle for a compiled Ruby method. * * @see org.jruby.runtime.MethodFactory#getCompiledMethod */ @Override public DynamicMethod getCompiledMethodLazily( RubyModule implementationClass, String rubyName, String javaName, Arity arity, Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position, String parameterDesc) { return getCompiledMethod(implementationClass, rubyName, javaName, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc); }
@Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> descs) { JavaMethodDescriptor desc1 = descs.get(0); if (desc1.anno.frame()) { // super logic does not work yet because we need to take impl class // and method name from the DynamicMethod#call call, so punt to // generated class for now return super.getAnnotatedMethod(implementationClass, descs); } if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); } DescriptorInfo info = new DescriptorInfo(descs); MethodHandle[] targets = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass); return new HandleMethod(implementationClass, desc1.anno.visibility(), CallConfiguration.getCallConfig(info.isFrame(), info.isScope()), targets, null); }
/** * Based on optional properties, create a new MethodFactory. By default, * this will create a code-generation-based InvocationMethodFactory. If * security restricts code generation, ReflectionMethodFactory will be used. * If we are dumping class definitions, DumpingInvocationMethodFactory will * be used. See MethodFactory's static initializer for more details. * * @param classLoader The classloader to use for searching for and * dynamically loading code. * @return A new MethodFactory. */ public static MethodFactory createFactory(ClassLoader classLoader) { // otherwise, generate invokers at runtime if (Options.INVOKEDYNAMIC_HANDLES.load()) { return new InvokeDynamicMethodFactory(classLoader); } else { return new InvocationMethodFactory(classLoader); } }
Callable<MethodHandle> target = adaptHandle(method, runtime, desc.actualRequired, desc.required, desc.optional, desc.rest, rubyName, desc.declaringClass, desc.isStatic, desc.hasContext, desc.hasBlock, desc.anno.frame(), implementationClass); int specificArity = -1; if (desc.required < 4 && desc.optional == 0 && !desc.rest) {
@Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<JavaMethodDescriptor> descs) { JavaMethodDescriptor desc1 = descs.get(0); if (desc1.anno.frame()) { // super logic does not work yet because we need to take impl class // and method name from the DynamicMethod#call call, so punt to // generated class for now return super.getAnnotatedMethod(implementationClass, descs); } if (!Modifier.isPublic(desc1.getDeclaringClass().getModifiers())) { LOG.warn("warning: binding non-public class {}; reflected handles won't work", desc1.declaringClassName); } DescriptorInfo info = new DescriptorInfo(descs); MethodHandle[] targets = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass); return new HandleMethod(implementationClass, desc1.anno.visibility(), CallConfiguration.getCallConfig(info.isFrame(), info.isScope()), targets, null); }
/** * Based on optional properties, create a new MethodFactory. By default, * this will create a code-generation-based InvocationMethodFactory. If * security restricts code generation, ReflectionMethodFactory will be used. * If we are dumping class definitions, DumpingInvocationMethodFactory will * be used. See MethodFactory's static initializer for more details. * * @param classLoader The classloader to use for searching for and * dynamically loading code. * @return A new MethodFactory. */ public static MethodFactory createFactory(ClassLoader classLoader) { // otherwise, generate invokers at runtime if (Options.INVOKEDYNAMIC_HANDLES.load()) { return new InvokeDynamicMethodFactory(classLoader); } else { return new InvocationMethodFactory(classLoader); } }
Callable<MethodHandle> target = adaptHandle(method, runtime, desc.actualRequired, desc.required, desc.optional, desc.rest, rubyName, desc.declaringClass, desc.isStatic, desc.hasContext, desc.hasBlock, desc.anno.frame(), implementationClass); int specificArity = -1; if (desc.required < 4 && desc.optional == 0 && !desc.rest) {
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ @Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { return getAnnotatedMethod(implementationClass, Arrays.asList(desc)); }
Callable<MethodHandle>[] generators = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass);
/** * Based on optional properties, create a new MethodFactory. By default, * this will create a code-generation-based InvocationMethodFactory. If * security restricts code generation, ReflectionMethodFactory will be used. * If we are dumping class definitions, DumpingInvocationMethodFactory will * be used. See MethodFactory's static initializer for more details. * * @param classLoader The classloader to use for searching for and * dynamically loading code. * @return A new MethodFactory. */ public static MethodFactory createFactory(ClassLoader classLoader) { // if reflection is forced or we've determined that we can't load bytecode, use reflection if (reflection || !CAN_LOAD_BYTECODE) return new ReflectionMethodFactory(); // otherwise, generate invokers at runtime if (Options.COMPILE_INVOKEDYNAMIC.load() && Options.INVOKEDYNAMIC_HANDLES.load()) { return new InvokeDynamicMethodFactory(classLoader); } else { return new InvocationMethodFactory(classLoader); } }
@Override public MethodHandle call() throws Exception { //Class returnClass = method.type().returnType(); int specificArity = -1; if (optional == 0 && !rest) { if (required == 0) { if (actualRequired <= 3) { specificArity = actualRequired; } } else if (required >= 0 && required <= 3) { specificArity = required; } } SmartBinder targetBinder = getBinder(specificArity, isStatic, hasContext, hasBlock); return finishAdapting(targetBinder, implementationClass, rubyName, method, declaringClass, runtime, isStatic, frame); } };
/** * Use code generation to provide a method handle for a compiled Ruby method. * * @see org.jruby.runtime.MethodFactory#getCompiledMethod */ @Override public DynamicMethod getCompiledMethodLazily( RubyModule implementationClass, String rubyName, String javaName, Arity arity, Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position, String parameterDesc) { return getCompiledMethod(implementationClass, rubyName, javaName, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc); }
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ @Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name) { return getAnnotatedMethod(implementationClass, Collections.singletonList(desc), name); }
Callable<MethodHandle>[] generators = buildAnnotatedMethodHandles(implementationClass.getRuntime(), descs, implementationClass);
/** * Based on optional properties, create a new MethodFactory. By default, * this will create a code-generation-based InvocationMethodFactory. If * security restricts code generation, ReflectionMethodFactory will be used. * If we are dumping class definitions, DumpingInvocationMethodFactory will * be used. See MethodFactory's static initializer for more details. * * @param classLoader The classloader to use for searching for and * dynamically loading code. * @return A new MethodFactory. */ public static MethodFactory createFactory(ClassLoader classLoader) { // if reflection is forced or we've determined that we can't load bytecode, use reflection if (reflection || !CAN_LOAD_BYTECODE) return new ReflectionMethodFactory(); // otherwise, generate invokers at runtime if (Options.COMPILE_INVOKEDYNAMIC.load() && Options.INVOKEDYNAMIC_HANDLES.load()) { return new InvokeDynamicMethodFactory(classLoader); } else { return new InvocationMethodFactory(classLoader); } }
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ @Override public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { return getAnnotatedMethod(implementationClass, Arrays.asList(desc)); }