public static object DynamicInvokevirtual(object obj, RuntimeTypeHandle type, string clazz, string name, string sig, object[] args, [email protected] callerID) { Profiler.Count("DynamicInvokevirtual"); MethodWrapper mw = GetMethodWrapper(obj, type, clazz, name, sig, false); java.lang.reflect.Method m = (java.lang.reflect.Method)mw.ToMethodOrConstructor(false); object val = m.invoke(obj, BoxArgs(mw, args), callerID); if (mw.ReturnType.IsPrimitive && mw.ReturnType != PrimitiveTypeWrapper.VOID) { val = JVM.Unbox(val); } return(val); }
public static object DynamicGetfield(object obj, string name, string sig, RuntimeTypeHandle type, string clazz, [email protected] callerID) { Profiler.Count("DynamicGetfield"); FieldWrapper fw = GetFieldWrapper(ClassLoaderWrapper.GetWrapperFromType(obj.GetType()), type, clazz, name, sig, false); java.lang.reflect.Field field = (java.lang.reflect.Field)fw.ToField(false); object val = field.get(obj, callerID); if (fw.FieldTypeWrapper.IsPrimitive) { val = JVM.Unbox(val); } return(val); }
public static object DynamicGetstatic(string name, string sig, RuntimeTypeHandle type, string clazz, [email protected] callerID) { Profiler.Count("DynamicGetstatic"); FieldWrapper fw = GetFieldWrapper(null, type, clazz, name, sig, true); java.lang.reflect.Field field = (java.lang.reflect.Field)fw.ToField(false); object val = field.get(null, callerID); if (fw.FieldTypeWrapper.IsPrimitive) { val = JVM.Unbox(val); } return(val); }
public static object createDelegate(MethodType newType, MethodHandle mh, int argnum, object argument) { #if FIRST_PASS return(null); #else Delegate del = (Delegate)mh.vmtarget; if (argnum == 0 && del.Target == null // we don't have to check for instance methods on a Value Type, because DirectMethodHandle can't use a direct delegate for that anyway && (!del.Method.IsStatic || !del.Method.GetParameters()[0].ParameterType.IsValueType) && !ReflectUtil.IsDynamicMethod(del.Method)) { return(Delegate.CreateDelegate(MethodHandleUtil.CreateDelegateType(newType), argument, del.Method)); } else { // slow path where we're generating a DynamicMethod if (mh.type().parameterType(argnum).isPrimitive()) { argument = JVM.Unbox(argument); } MethodHandleUtil.DynamicMethodBuilder dm = new MethodHandleUtil.DynamicMethodBuilder("BoundMethodHandle", newType, mh, argument); for (int i = 0, count = mh.type().parameterCount(), pos = 0; i < count; i++) { if (i == argnum) { dm.LoadValue(); } else { dm.Ldarg(pos++); } } dm.CallTarget(); dm.Ret(); return(dm.CreateDelegate()); } #endif }