/** * Use code generation to provide a method handle for a compiled Ruby method. * * @see org.jruby.runtime.MethodFactory#getCompiledMethod */ public DynamicMethod getCompiledMethodLazily( RubyModule implementationClass, String rubyName, String javaName, Arity arity, Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position, String parameterDesc) { return new CompiledMethod.LazyCompiledMethod( implementationClass, rubyName, javaName, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc, new InvocationMethodFactory(classLoader)); }
Class superclass = determineSuperclass(info); Class c = tryClass(generatedClassName, desc1.declaringClass, superclass); if (c == null) { synchronized (syncObject) { c = tryClass(generatedClassName, desc1.declaringClass, superclass); if (c == null) { if (DEBUG) LOG.debug("Generating " + generatedClassName + ", min: " + info.getMin() + ", max: " + info.getMax() + ", hasBlock: " + info.isBlock() + ", rest: " + info.isRest()); ClassWriter cw = createJavaMethodCtor(generatedClassPath, superClassString, info.getParameterDesc()); addAnnotatedMethodInvoker(cw, superClassString, descs); c = endClass(cw, generatedClassName);
private void addAnnotatedMethodInvoker(ClassWriter cw, String superClass, List<JavaMethodDescriptor> descs) { for (JavaMethodDescriptor desc: descs) { int specificArity = desc.calculateSpecificCallArity(); SkinnyMethodAdapter mv = beginMethod(cw, "call", specificArity, desc.hasBlock); mv.visitCode(); createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, desc.hasBlock); mv.end(); } }
String javaMethodName = desc.name; checkArity(desc.anno, method, specificArity); invokeCallConfigPre(method, superClass, specificArity, block, callConfig); invokeCCallTrace(method, traceBoolIndex); loadReceiver(typePath, desc, method); loadArguments(method, desc, specificArity); loadBlock(method, specificArity, block); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig);
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Collections.singletonList(desc)); JavaMethod ic = constructJavaMethod(implementationClass, desc, name, c); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, desc.anno.notImplemented(), desc.declaringClass, desc.name, desc.returnClass, desc.parameters); return ic; } catch(Exception e) { LOG.error(e); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
@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); }
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Arrays.asList(desc)); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc.anno.visibility()}); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented(), desc.getDeclaringClass(), desc.name, desc.getReturnClass(), desc.getParameterClasses()); return ic; } catch(Exception e) { e.printStackTrace(); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
protected Class endCall(ClassWriter cw, String name) { return endClass(cw, name); }
String javaMethodName = desc.name; checkArity(desc.anno, method, specificArity); invokeCallConfigPre(method, superClass, specificArity, block, callConfig); invokeCCallTrace(method, traceBoolIndex); loadReceiver(typePath, desc, method); loadArguments(method, desc, specificArity); loadBlock(method, specificArity, block); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig);
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Collections.singletonList(desc)); JavaMethod ic = constructJavaMethod(implementationClass, desc, name, c); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, desc.anno.notImplemented(), desc.declaringClass, desc.name, desc.returnClass, desc.parameters); return ic; } catch(Exception e) { LOG.error(e); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
@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); }
/** * Use code generation to provide a method handle based on an annotated Java * method. * * @see org.jruby.runtime.MethodFactory#getAnnotatedMethod */ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc) { String javaMethodName = desc.name; try { Class c = getAnnotatedMethodClass(Arrays.asList(desc)); JavaMethod ic = (JavaMethod)c.getConstructor(new Class[]{RubyModule.class, Visibility.class}).newInstance(new Object[]{implementationClass, desc.anno.visibility()}); TypePopulator.populateMethod( ic, Arity.fromAnnotation(desc.anno, desc.actualRequired).getValue(), javaMethodName, desc.isStatic, CallConfiguration.getCallConfigByAnno(desc.anno), desc.anno.notImplemented(), desc.getDeclaringClass(), desc.name, desc.getReturnClass(), desc.getParameterClasses()); return ic; } catch(Exception e) { e.printStackTrace(); throw implementationClass.getRuntime().newLoadError(e.getMessage()); } }
protected Class endCall(ClassWriter cw, String name) { return endClass(cw, name); }
String javaMethodName = desc.name; checkArity(desc.anno, method, specificArity); invokeCallConfigPre(method, superClass, specificArity, block, callConfig); invokeCCallTrace(method, traceBoolIndex); loadReceiver(typePath, desc, method); loadArguments(method, desc, specificArity); loadBlock(method, specificArity, block); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig); invokeCReturnTrace(method, traceBoolIndex); invokeCallConfigPost(method, superClass, callConfig);
Class superclass = determineSuperclass(info); Class c = tryClass(generatedClassName, desc1.declaringClass, superclass); if (c == null) { synchronized (syncObject) { c = tryClass(generatedClassName, desc1.declaringClass, superclass); if (c == null) { if (DEBUG) LOG.debug("Generating " + generatedClassName + ", min: " + info.getMin() + ", max: " + info.getMax() + ", hasBlock: " + info.isBlock() + ", rest: " + info.isRest()); ClassWriter cw = createJavaMethodCtor(generatedClassPath, superClassString, info.getParameterDesc()); addAnnotatedMethodInvoker(cw, superClassString, descs); c = endClass(cw, generatedClassName);
private void addAnnotatedMethodInvoker(ClassWriter cw, String superClass, List<JavaMethodDescriptor> descs) { for (JavaMethodDescriptor desc: descs) { int specificArity = desc.calculateSpecificCallArity(); SkinnyMethodAdapter mv = beginMethod(cw, "call", specificArity, desc.hasBlock); mv.visitCode(); createAnnotatedMethodInvocation(desc, mv, superClass, specificArity, desc.hasBlock); mv.end(); } }
Class c = getAnnotatedMethodClass(descs); JavaMethod ic = constructJavaMethod(implementationClass, desc1, name, c);
/** * Use code generation to provide a method handle for a compiled Ruby method. * * @see org.jruby.runtime.MethodFactory#getCompiledMethod */ public DynamicMethod getCompiledMethodLazily( RubyModule implementationClass, String rubyName, String javaName, Arity arity, Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position, String parameterDesc) { return new CompiledMethod.LazyCompiledMethod( implementationClass, rubyName, javaName, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc, new InvocationMethodFactory(classLoader)); }
return super.getAnnotatedMethod(implementationClass, descs, name);