private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) { RubyClass selfType = pollAndGetClass(context, self); CacheEntry myCache = cache; if (CacheEntry.typeOk(myCache, selfType)) { return myCache.method.call(context, self, selfType, methodName, args, block); } return cacheAndCall(caller, selfType, block, args, context, self); }
public final CacheEntry retrieveCache(RubyClass selfType, String methodName) { // This must be retrieved *once* to avoid racing with other threads. CacheEntry cache = this.cache; if (cache.typeOk(selfType)) { return cache; } return cacheAndGet(selfType, methodName); }
@Override public final IRubyObject callVarargs(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject... args) { switch (args.length) { case 0: return call(context, caller, self); case 1: return call(context, caller, self, args[0]); case 2: return call(context, caller, self, args[0], args[1]); case 3: return call(context, caller, self, args[0], args[1], args[2]); default: return call(context, caller, self, args); } }
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClass selfType, IRubyObject[] args, ThreadContext context, IRubyObject self) { CacheEntry entry = selfType.searchWithCache(methodName); DynamicMethod method = entry.method; if (methodMissing(method, caller)) { return callMethodMissing(context, self, method, args); } updateCache(entry); return method.call(context, self, selfType, methodName, args); }
private IRubyObject cacheAndCall(IRubyObject caller, RubyClass selfType, Block block, ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2) { CacheEntry entry = selfType.searchWithCache(methodName); DynamicMethod method = entry.method; if (methodMissing(method, caller)) { return callMethodMissing(context, self, selfType, method, arg1, arg2, block); } cache = entry; return method.call(context, self, selfType, methodName, arg1, arg2, block); }
public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
@Override public IRubyObject isNegative(ThreadContext context) { Ruby runtime = context.runtime; CachingCallSite op_lt_site = sites(context).basic_op_lt; if (op_lt_site.retrieveCache(metaClass).method.isBuiltin()) { return runtime.newBoolean(value.signum() < 0); } return op_lt_site.call(context, this, this, RubyFixnum.zero(runtime)); }
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) { RubyClass selfType = getMetaClass(self); // This must be retrieved *once* to avoid racing with other threads. CacheEntry cache = this.cache; if (cache.typeOk(selfType)) { return cache.method.call(context, self, selfType, methodName, args, block); } return cacheAndCall(caller, selfType, block, args, context, self); }
public boolean isOptimizable() { return getCache() != CacheEntry.NULL_CACHE;// && !isPolymorphic.get(); }
private int getArg0Generation(CachingCallSite op_cmp) { IRubyObject arg0 = eltInternal(0); RubyClass metaclass = arg0.getMetaClass(); CacheEntry entry = op_cmp.retrieveCache(metaclass); int generation = -1; if (entry.method.isBuiltin()) { generation = entry.token; } return generation; }
@Override public final IRubyObject callVarargsIter(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) { switch (args.length) { case 0: return callIter(context, caller, self, block); case 1: return callIter(context, caller, self, args[0], block); case 2: return callIter(context, caller, self, args[0], args[1], block); case 3: return callIter(context, caller, self, args[0], args[1], args[2], block); default: return callIter(context, caller, self, args, block); } }
public static MemoryIO convertToPointerMemoryIO(ThreadContext context, IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = getConversionMethod(parameter, callSite); IRubyObject ptr = method.call(context, parameter, parameter.getMetaClass(), callSite.getMethodName(), Block.NULL_BLOCK); if (ptr instanceof AbstractMemory) { return ((AbstractMemory) ptr).getMemoryIO(); } throw parameter.getRuntime().newTypeError(parameter.getMetaClass() + "#" + callSite.getMethodName() + " should return " + context.runtime.getFFI().pointerClass); }
public final boolean isBuiltin(RubyClass selfType) { // This must be retrieved *once* to avoid racing with other threads. CacheEntry cache = this.cache; if (cache.typeOk(selfType)) { return cache.method.isBuiltin(); } return cacheAndGetBuiltin(selfType, methodName); }
public static DynamicMethod getConversionMethod(IRubyObject parameter, CachingCallSite callSite) { DynamicMethod method = callSite.retrieveCache(parameter.getMetaClass(), callSite.getMethodName()).method; if (method.isUndefined()) { throw parameter.getRuntime().newTypeError("cannot convert parameter of type " + parameter.getMetaClass() + " to native pointer; does not respond to :" + callSite.getMethodName()); } return method; }
private IRubyObject cacheAndCall(IRubyObject caller, RubyClass selfType, ThreadContext context, IRubyObject self) { CacheEntry entry = selfType.searchWithCache(methodName); DynamicMethod method = entry.method; if (methodMissing(method, caller)) { return callMethodMissing(context, self, selfType, method); } cache = entry; return method.call(context, self, selfType, methodName); }
protected IRubyObject cacheAndCall(IRubyObject caller, RubyClass selfType, ThreadContext context, IRubyObject self, IRubyObject arg) { CacheEntry entry = selfType.searchWithCache(methodName); DynamicMethod method = entry.method; if (methodMissing(method, caller)) { return callMethodMissing(context, self, method, arg); } updateCache(entry); return method.call(context, self, selfType, methodName, arg); }
@Override public IRubyObject isPositive(ThreadContext context) { Ruby runtime = context.runtime; CachingCallSite op_gt_site = sites(context).basic_op_gt; if (op_gt_site.retrieveCache(metaClass).method.isBuiltin()) { return runtime.newBoolean(value.signum() > 0); } return op_gt_site.call(context, this, this, RubyFixnum.zero(runtime)); }
public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, Block block) { RubyClass selfType = getMetaClass(self); // This must be retrieved *once* to avoid racing with other threads. CacheEntry cache = this.cache; if (cache.typeOk(selfType)) { return cache.method.call(context, self, selfType, methodName, block); } return cacheAndCall(caller, selfType, block, context, self); }
public boolean isOptimizable() { return getCache() != CacheEntry.NULL_CACHE;// && !isPolymorphic.get(); }
private int getArg0Generation(CachingCallSite op_cmp) { IRubyObject arg0 = eltInternal(0); RubyClass metaclass = arg0.getMetaClass(); CacheEntry entry = op_cmp.retrieveCache(metaclass); int generation = -1; if (entry.method.isBuiltin()) { generation = entry.token; } return generation; }