@JIT public static IRubyObject invokeModuleBody(ThreadContext context, DynamicMethod method, Block block) { RubyModule implClass = method.getImplementationClass(); return method.call(context, implClass, implClass, "", block); }
@Override public Arity getArity() { return method.getArity(); }
public DelegatingDynamicMethod(DynamicMethod delegate) { super(delegate.getImplementationClass(), delegate.getVisibility(), delegate.getName()); this.delegate = delegate; }
public MethodMissingMethod(DynamicMethod delegate, Visibility lastVisibility, CallType lastCallStatus) { super(delegate.getImplementationClass(), lastVisibility, delegate.getName()); this.delegate = delegate; this.lastCallStatus = lastCallStatus; this.lastVisibility = lastVisibility; }
@Override public int hashCode() { long serial = method.getRealMethod().getSerialNumber(); return 997 * ((int) (serial >> 32) ^ (int) serial & 0xFF); }
private static MethodHandle createRubyHandle(JRubyCallSite site, DynamicMethod method, String name) { MethodHandle nativeTarget = (MethodHandle)method.getHandle(); if (nativeTarget != null) return nativeTarget; DynamicMethod.NativeCall nativeCall = method.getNativeCall(); .invokeStaticQuiet(site.lookup(), nativeCall.getNativeTarget(), nativeCall.getNativeName()); nativeTarget = wrapWithFraming(fullSig, method.getCallConfig(), method.getImplementationClass(), name, nativeTarget, scope); method.setHandle(nativeTarget); return nativeTarget; } catch (Exception e) {
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) { int previousSerial = context.profileEnter(name, this.delegate.getRealMethod()); final long start = System.nanoTime(); try { return delegate.call(context, self, clazz, name, arg0); } finally { context.profileExit(previousSerial, start); } }
public static DynamicMethod populateModuleMethod(RubyModule cls, DynamicMethod javaMethod) { DynamicMethod moduleMethod = javaMethod.dup(); moduleMethod.setImplementationClass(cls.getSingletonClass()); moduleMethod.setVisibility(Visibility.PUBLIC); return moduleMethod; }
public IRubyObject finvoke(ThreadContext context, IRubyObject self, String name, Block block) { DynamicMethod method = searchMethod(name); if (shouldCallMethodMissing(method)) { return Helpers.callMethodMissing(context, self, this, method.getVisibility(), name, CallType.FUNCTIONAL, block); } return method.call(context, self, this, name, block); }
private static MethodHandle createFFIHandle(JRubyCallSite site, DynamicMethod method) { if (site.type().parameterType(site.type().parameterCount() - 1) == Block.class) { // Called with a block to substitute for a callback param - cannot cache or use a cached handle return null; } MethodHandle nativeTarget = (MethodHandle) method.getHandle(); if (nativeTarget != null) return nativeTarget; nativeTarget = org.jruby.ext.ffi.jffi.InvokeDynamic.getMethodHandle(site, method); if (nativeTarget != null) { method.setHandle(nativeTarget); return nativeTarget; } // can't build native handle for it return null; }
@Override public Object invoke(Object _this, Object... args) throws InvocationTargetException, IllegalAccessException { IRubyObject[] argList = new IRubyObject[args.length]; for (int i=0; i<args.length; i++) argList[i] = Java.getInstance(klass.getRuntime(),args[i]); return method.call(klass.getRuntime().getCurrentContext() , (IRubyObject)_this, klass, method.getName(), argList); } }
public static ArgumentDescriptor[] methodToArgumentDescriptors(DynamicMethod method) { method = method.getRealMethod(); if (method instanceof MethodArgs2) { return parameterListToArgumentDescriptors(method.getImplementationClass().getRuntime(), ((MethodArgs2) method).getParameterList(), true); } else if (method instanceof IRMethodArgs) { return ((IRMethodArgs) method).getArgumentDescriptors(); } else { return new ArgumentDescriptor[]{new ArgumentDescriptor(ArgumentType.anonrest)}; } }
@Override protected RubyModule getProtectedClass() { return delegate.getProtectedClass(); }
public int getCachedClassIndex() { CacheEntry cacheEntry = getCache(); if (cacheEntry != CacheEntry.NULL_CACHE) { return cacheEntry.method.getImplementationClass().index; } return ClassIndex.NO_INDEX; }
/** * Set the class on which this method is implemented, used for 'super' * logic, among others. * * @param implClass The class on which this method is implemented */ public void setImplementationClass(RubyModule implClass) { implementationClass = implClass; protectedClass = calculateProtectedClass(implClass); }
@Override public void setVisibility(Visibility visibility) { // We promote our box to being its own box since we're changing // visibilities, and need it to be reflected on this method object // independent of any other sharing the box. DynamicMethodBox newBox = new DynamicMethodBox(); newBox.actualMethod = box.actualMethod.dup(); newBox.callCount = box.callCount; box = newBox; super.setVisibility(visibility); } }
@Override public MethodData getMethodData() { return delegate.getMethodData(); //To change body of overridden methods use File | Settings | File Templates. }
/** * Constructor for PartialDelegatingMethod. * @param visibility */ public PartialDelegatingMethod(RubyModule implementationClass, DynamicMethod method, Visibility visibility) { super(implementationClass, visibility, method.getName() ); this.method = method; }
@Override public DynamicMethod dup() { return new ProfilingDynamicMethod(delegate.dup()); } }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) { synchronized (self) { return delegate.call(context, self, clazz, name, arg0, block); } }