Exemplo n.º 1
0
    // this overload is called via a map.xml patch to the MemberName(Method, boolean) constructor, because we need wantSpecial
    public static void init(MemberName self, object refObj, bool wantSpecial)
    {
#if !FIRST_PASS
        JlReflect.Method      method;
        JlReflect.Constructor constructor;
        JlReflect.Field       field;
        if ((method = refObj as JlReflect.Method) != null)
        {
            InitMethodImpl(self, MethodWrapper.FromExecutable(method), wantSpecial);
        }
        else if ((constructor = refObj as JlReflect.Constructor) != null)
        {
            InitMethodImpl(self, MethodWrapper.FromExecutable(constructor), wantSpecial);
        }
        else if ((field = refObj as JlReflect.Field) != null)
        {
            FieldWrapper fw = FieldWrapper.FromField(field);
            self._clazz(fw.DeclaringType.ClassObject);
            int flags = (int)fw.Modifiers | MethodHandleNatives.Constants.MN_IS_FIELD;
            flags |= (fw.IsStatic ? MethodHandleNatives.Constants.REF_getStatic : MethodHandleNatives.Constants.REF_getField) << MethodHandleNatives.Constants.MN_REFERENCE_KIND_SHIFT;
            self._flags(flags);
        }
        else
        {
            throw new InvalidOperationException();
        }
#endif
    }
Exemplo n.º 2
0
    private static FieldInfo GetFieldInfo(long offset)
    {
        FieldWrapper fw = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset));

        fw.Link();
        fw.ResolveField();
        return(fw.GetField());
    }
Exemplo n.º 3
0
        internal static void Log(string key, long offset)
        {
#if !FIRST_PASS && UNSAFE_STATISTICS
            FieldWrapper field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset));
            key += field.DeclaringType.Name + "::" + field.Name;
            Log(key);
#endif
        }
Exemplo n.º 4
0
            public static bool isFieldDeprecated(object field)
            {
                FieldWrapper fieldWrapper = FieldWrapper.FromField(field);
                FieldInfo    fi           = fieldWrapper.GetField();

                if (fi != null)
                {
                    return(fi.IsDefined(typeof(ObsoleteAttribute), false));
                }
                return(false);
            }
Exemplo n.º 5
0
    public static bool compareAndSwapObject(object thisUnsafe, object obj, long offset, object expect, object update)
    {
#if FIRST_PASS
        return(false);
#else
        object[] array = obj as object[];
        if (array != null)
        {
            Stats.Log("compareAndSwapObject.array");
            return(Atomic.CompareExchange(array, (int)offset, update, expect) == expect);
        }
        else
        {
            Stats.Log("compareAndSwapObject.", offset);
            FieldInfo field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset)).GetField();
            return(Atomic.CompareExchange(obj, new FieldInfo[] { field }, update, expect) == expect);
        }
#endif
    }
Exemplo n.º 6
0
    public static void init(MemberName self, object r)
    {
#if !FIRST_PASS
        if (r is java.lang.reflect.Method || r is java.lang.reflect.Constructor)
        {
            MethodWrapper mw    = MethodWrapper.FromMethodOrConstructor(r);
            int           index = Array.IndexOf(mw.DeclaringType.GetMethods(), mw);
            if (index != -1)
            {
                // TODO self.setVMIndex(index);
                typeof(MemberName).GetField("vmindex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, index);
                typeof(MemberName).GetField("vmtarget", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, mw.DeclaringType);
                int flags = (int)mw.Modifiers;
                if (r is java.lang.reflect.Method)
                {
                    flags |= MemberName.IS_METHOD;
                }
                else
                {
                    flags |= MemberName.IS_CONSTRUCTOR;
                }
                typeof(MemberName).GetField("flags", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, flags);
            }
        }
        else if (r is java.lang.reflect.Field)
        {
            FieldWrapper fw    = FieldWrapper.FromField(r);
            int          index = Array.IndexOf(fw.DeclaringType.GetFields(), fw);
            if (index != -1)
            {
                // TODO self.setVMIndex(index);
                typeof(MemberName).GetField("vmindex", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, index);
                typeof(MemberName).GetField("flags", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(self, (int)fw.Modifiers | MemberName.IS_FIELD);
            }
        }
        else
        {
            throw new InvalidOperationException();
        }
#endif
    }
Exemplo n.º 7
0
    private static Delegate CreateCompareExchange(long fieldOffset)
    {
#if !WINRT
        FieldWrapper fw = FieldWrapper.FromField(sun.misc.Unsafe.getField(fieldOffset));
        fw.Link();
        fw.ResolveField();
        FieldInfo     field = fw.GetField();
        DynamicMethod dm    = new DynamicMethod("CompareExchange", field.FieldType, new Type[] { typeof(object), field.FieldType, field.FieldType }, field.DeclaringType);
        ILGenerator   ilgen = dm.GetILGenerator();
        ilgen.Emit(OpCodes.Ldarg_0);
        ilgen.Emit(OpCodes.Castclass, field.DeclaringType);
        ilgen.Emit(OpCodes.Ldflda, field);
        ilgen.Emit(OpCodes.Ldarg_1);
        ilgen.Emit(OpCodes.Ldarg_2);
        ilgen.Emit(OpCodes.Call, typeof(Interlocked).GetMethod("CompareExchange", new Type[] { field.FieldType.MakeByRefType(), field.FieldType, field.FieldType }));
        ilgen.Emit(OpCodes.Ret);
        return(dm.CreateDelegate(field.FieldType == typeof(int) ? typeof(CompareExchangeInt32) : typeof(CompareExchangeInt64)));
#else
        throw new NotImplementedException();
#endif
    }
Exemplo n.º 8
0
 private static FieldWrapper GetFieldWrapper(java.io.ObjectStreamField field)
 {
     java.lang.reflect.Field f = field.getField();
     return(f == null ? null : FieldWrapper.FromField(f));
 }
Exemplo n.º 9
0
 public static object getFieldConstantValue(object field)
 {
     return(FieldWrapper.FromField(field).GetConstant());
 }
Exemplo n.º 10
0
    public static object getDeclaredAnnotationsImpl(java.lang.reflect.Field thisField)
    {
        FieldWrapper fw = FieldWrapper.FromField(thisField);

        return(Java_java_lang_Class.AnnotationsToMap(fw.DeclaringType.GetClassLoader(), fw.DeclaringType.GetFieldAnnotations(fw)));
    }
Exemplo n.º 11
0
    public static byte[] getTypeAnnotationBytes0(java.lang.reflect.Field thisField)
    {
        FieldWrapper fw = FieldWrapper.FromField(thisField);

        return(fw.DeclaringType.GetFieldRawTypeAnnotations(fw));
    }