public static CallSite ivar(MethodHandles.Lookup lookup, String name, MethodType type) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, "noname", 0); MethodHandle handle; handle = lookup.findVirtual(VariableSite.class, operation, type); handle = handle.bindTo(site); site.setTarget(handle.asType(site.type())); return site; }
if (site.getTarget() == null || site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { site.clearChainCount(); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(setValue);
public void ivarSet(IRubyObject self, IRubyObject value) throws Throwable { RubyClass realClass = self.getMetaClass().getRealClass(); VariableAccessor accessor = realClass.getVariableAccessorForWrite(name()); setValue = explicitCastArguments(setValue, methodType(void.class, IRubyObject.class, IRubyObject.class)); } else { setValue = findStatic(accessor.getClass(), "setVariableChecked", methodType(void.class, RubyBasicObject.class, RubyClass.class, int.class, Object.class)); setValue = explicitCastArguments(setValue, methodType(void.class, IRubyObject.class, RubyClass.class, int.class, IRubyObject.class)); setValue = insertArguments(setValue, 1, realClass, accessor.getIndex()); if (chainCount() + 1 > Options.INVOKEDYNAMIC_MAXPOLY.load()) { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tset on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo()); fallback = findVirtual(VariableSite.class, "ivarSetFail", methodType(void.class, IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(this); setTarget(fallback); fallback.invokeExact(self, value); } else { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) { if (direct) { LOG.info(name() + "\tset field on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); } else { LOG.info(name() + "\tset on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); fallback = getTarget(); incrementChainCount(); MethodHandle test = findStatic(VariableSite.class, "testRealClass", methodType(boolean.class, int.class, IRubyObject.class)); test = insertArguments(test, 0, accessor.getClassId()); test = dropArguments(test, 1, IRubyObject.class);
public static CallSite variableBootstrap(Lookup lookup, String name, MethodType type, String file, int line) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, file, line); MethodHandle handle; if (operation.equals("get")) { handle = lookup.findStatic(InvokeDynamicSupport.class, "getVariableFallback", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class)); } else if (operation.equals("set")) { handle = lookup.findStatic(InvokeDynamicSupport.class, "setVariableFallback", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class, IRubyObject.class)); } else { throw new RuntimeException("invalid variable access type"); } handle = handle.bindTo(site); site.setTarget(handle); return site; }
if (site.getTarget() == null || site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { site.clearChainCount(); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(setValue);
public void ivarSet(IRubyObject self, IRubyObject value) throws Throwable { RubyClass realClass = self.getMetaClass().getRealClass(); VariableAccessor accessor = realClass.getVariableAccessorForWrite(name()); setValue = explicitCastArguments(setValue, methodType(void.class, IRubyObject.class, IRubyObject.class)); } else { setValue = findStatic(accessor.getClass(), "setVariableChecked", methodType(void.class, RubyBasicObject.class, RubyClass.class, int.class, Object.class)); setValue = explicitCastArguments(setValue, methodType(void.class, IRubyObject.class, RubyClass.class, int.class, IRubyObject.class)); setValue = insertArguments(setValue, 1, realClass, accessor.getIndex()); if (chainCount() + 1 > Options.INVOKEDYNAMIC_MAXPOLY.load()) { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tset on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo()); fallback = findVirtual(VariableSite.class, "ivarSetFail", methodType(void.class, IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(this); setTarget(fallback); fallback.invokeExact(self, value); } else { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) { if (direct) { LOG.info(name() + "\tset field on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); } else { LOG.info(name() + "\tset on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); fallback = getTarget(); incrementChainCount(); MethodHandle test = findStatic(VariableSite.class, "testRealClass", methodType(boolean.class, int.class, IRubyObject.class)); test = insertArguments(test, 0, accessor.getClassId()); test = dropArguments(test, 1, IRubyObject.class);
public static CallSite variableBootstrap(Lookup lookup, String name, MethodType type, String file, int line) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, file, line); MethodHandle handle; if (operation.equals("get")) { handle = lookup.findStatic(InvokeDynamicSupport.class, "getVariableFallback", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class)); } else if (operation.equals("set")) { handle = lookup.findStatic(InvokeDynamicSupport.class, "setVariableFallback", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class, IRubyObject.class)); } else { throw new RuntimeException("invalid variable access type"); } handle = handle.bindTo(site); site.setTarget(handle); return site; }
if (site.getTarget() == null || site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { site.clearChainCount(); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(getValue);
public IRubyObject ivarGet(IRubyObject self) throws Throwable { RubyClass realClass = self.getMetaClass().getRealClass(); VariableAccessor accessor = realClass.getVariableAccessorForRead(name()); getValue = explicitCastArguments(getValue, methodType(Object.class, IRubyObject.class)); } else { getValue = findStatic(VariableAccessor.class, "getVariable", methodType(Object.class, RubyBasicObject.class, int.class)); getValue = explicitCastArguments(getValue, methodType(Object.class, IRubyObject.class, int.class)); getValue = insertArguments(getValue, 1, accessor.getIndex()); if (chainCount() + 1 > Options.INVOKEDYNAMIC_MAXPOLY.load()) { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tqet on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo()); fallback = findVirtual(VariableSite.class, "ivarGetFail", methodType(IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(this); setTarget(fallback); return (IRubyObject)fallback.invokeWithArguments(self); } else { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) { if (direct) { LOG.info(name() + "\tget field on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); } else { LOG.info(name() + "\tget on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); fallback = getTarget(); incrementChainCount(); MethodHandle test = findStatic(VariableSite.class, "testRealClass", methodType(boolean.class, int.class, IRubyObject.class)); test = insertArguments(test, 0, accessor.getClassId()); if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tget on class " + self.getMetaClass().id + " bound directly" + extractSourceInfo());
public static CallSite ivar(MethodHandles.Lookup lookup, String name, MethodType type) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, "noname", 0); MethodHandle handle; handle = lookup.findVirtual(VariableSite.class, operation, type); handle = handle.bindTo(site); site.setTarget(handle.asType(site.type())); return site; }
if (site.getTarget() == null || site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { site.clearChainCount(); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(getValue);
public IRubyObject ivarGet(IRubyObject self) throws Throwable { RubyClass realClass = self.getMetaClass().getRealClass(); VariableAccessor accessor = realClass.getVariableAccessorForRead(name()); getValue = explicitCastArguments(getValue, methodType(Object.class, IRubyObject.class)); } else { getValue = findStatic(VariableAccessor.class, "getVariable", methodType(Object.class, RubyBasicObject.class, int.class)); getValue = explicitCastArguments(getValue, methodType(Object.class, IRubyObject.class, int.class)); getValue = insertArguments(getValue, 1, accessor.getIndex()); if (chainCount() + 1 > Options.INVOKEDYNAMIC_MAXPOLY.load()) { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tqet on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo()); fallback = findVirtual(VariableSite.class, "ivarGetFail", methodType(IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(this); setTarget(fallback); return (IRubyObject)fallback.invokeWithArguments(self); } else { if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) { if (direct) { LOG.info(name() + "\tget field on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); } else { LOG.info(name() + "\tget on type " + self.getMetaClass().id + " added to PIC" + extractSourceInfo()); fallback = getTarget(); incrementChainCount(); MethodHandle test = findStatic(VariableSite.class, "testRealClass", methodType(boolean.class, int.class, IRubyObject.class)); test = insertArguments(test, 0, accessor.getClassId()); if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) LOG.info(name() + "\tget on class " + self.getMetaClass().id + " bound directly" + extractSourceInfo());
public static CallSite ivar(Lookup lookup, String name, MethodType type) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, "noname", 0); MethodHandle handle; handle = lookup.findStatic(Bootstrap.class, operation, type.insertParameterTypes(0, VariableSite.class)); handle = handle.bindTo(site); site.setTarget(handle.asType(site.type())); return site; }
if (site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(site.name + "\tset on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo(site)); fallback = findStatic(InvokeDynamicSupport.class, "setVariableFail", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(site); site.setTarget(fallback); return (IRubyObject)fallback.invokeWithArguments(self, value); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(setValue);
public static CallSite ivar(Lookup lookup, String name, MethodType type) throws Throwable { String[] names = name.split(":"); String operation = names[0]; String varName = names[1]; VariableSite site = new VariableSite(type, varName, "noname", 0); MethodHandle handle; handle = lookup.findStatic(Bootstrap.class, operation, type.insertParameterTypes(0, VariableSite.class)); handle = handle.bindTo(site); site.setTarget(handle.asType(site.type())); return site; }
if (site.chainCount() + 1 > RubyInstanceConfig.MAX_POLY_COUNT) { if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(site.name + "\tset on type " + self.getMetaClass().id + " failed (polymorphic)" + extractSourceInfo(site)); fallback = findStatic(InvokeDynamicSupport.class, "setVariableFail", methodType(IRubyObject.class, VariableSite.class, IRubyObject.class, IRubyObject.class)); fallback = fallback.bindTo(site); site.setTarget(fallback); return (IRubyObject)fallback.invokeWithArguments(self, value); } else { fallback = site.getTarget(); site.incrementChainCount(); site.setTarget(setValue);