Exemplo n.º 1
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            ilgen.Emit(OpCodes.Ldflda, fw.GetField());
        }
Exemplo n.º 2
0
        static ProxyGenerator()
        {
            ClassLoaderWrapper bootClassLoader = ClassLoaderWrapper.GetBootstrapClassLoader();

            proxyClass            = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.Proxy");
            errorClass            = bootClassLoader.LoadClassByDottedNameFast("java.lang.Error");
            runtimeExceptionClass = bootClassLoader.LoadClassByDottedNameFast("java.lang.RuntimeException");
            undeclaredThrowableExceptionConstructor = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.UndeclaredThrowableException").GetMethodWrapper("<init>", "(Ljava.lang.Throwable;)V", false);
            undeclaredThrowableExceptionConstructor.Link();
            invocationHandlerField = proxyClass.GetFieldWrapper("h", "Ljava.lang.reflect.InvocationHandler;");
            invocationHandlerField.Link();
            javaLangReflectMethod                   = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.Method");
            javaLangNoSuchMethodException           = bootClassLoader.LoadClassByDottedNameFast("java.lang.NoSuchMethodException");
            javaLangNoClassDefFoundErrorConstructor = bootClassLoader.LoadClassByDottedNameFast("java.lang.NoClassDefFoundError").GetMethodWrapper("<init>", "(Ljava.lang.String;)V", false);
            javaLangNoClassDefFoundErrorConstructor.Link();
            javaLangThrowable_getMessage = bootClassLoader.LoadClassByDottedNameFast("java.lang.Throwable").GetMethodWrapper("getMessage", "()Ljava.lang.String;", false);
            javaLangThrowable_getMessage.Link();
            javaLangClass_getMethod = CoreClasses.java.lang.Class.Wrapper.GetMethodWrapper("getMethod", "(Ljava.lang.String;[Ljava.lang.Class;)Ljava.lang.reflect.Method;", false);
            javaLangClass_getMethod.Link();
            invocationHandlerClass = bootClassLoader.LoadClassByDottedNameFast("java.lang.reflect.InvocationHandler");
            invokeMethod           = invocationHandlerClass.GetMethodWrapper("invoke", "(Ljava.lang.Object;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.lang.Object;", false);
            proxyConstructor       = proxyClass.GetMethodWrapper("<init>", "(Ljava.lang.reflect.InvocationHandler;)V", false);
            proxyConstructor.Link();
            hashCodeMethod = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("hashCode", "()I", false);
            equalsMethod   = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("equals", "(Ljava.lang.Object;)Z", false);
            toStringMethod = CoreClasses.java.lang.Object.Wrapper.GetMethodWrapper("toString", "()Ljava.lang.String;", false);
        }
Exemplo n.º 3
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = StaticCompiler.GetClassForMapXml(context.ClassLoader, Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            ilgen.Emit(OpCodes.Ldflda, fw.GetField());
        }
Exemplo n.º 4
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.º 5
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            // we don't use fw.EmitSet because we don't want automatic unboxing and whatever
            ilgen.Emit(OpCodes.Stsfld, fw.GetField());
        }
Exemplo n.º 6
0
        internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
        {
            FieldWrapper fw = StaticCompiler.GetClassForMapXml(context.ClassLoader, Class).GetFieldWrapper(Name, Sig);

            fw.Link();
            // we don't use fw.EmitSet because we don't want automatic unboxing and whatever
            ilgen.Emit(OpCodes.Stsfld, fw.GetField());
        }
Exemplo n.º 7
0
 internal override void Generate(CodeGenContext context, CodeEmitter ilgen)
 {
     if (Type != null)
     {
         ilgen.Emit(OpCodes.Ldsfld, StaticCompiler.GetType(context.ClassLoader, Type).GetField(Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
     }
     else
     {
         FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig);
         fw.Link();
         // we don't use fw.EmitGet because we don't want automatic unboxing and whatever
         ilgen.Emit(OpCodes.Ldsfld, fw.GetField());
     }
 }
Exemplo n.º 8
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
    }
    /**
     * Emit an invoke for the given name, using the MemberName directly.
     */
    void emitStaticInvoke(MemberName member, Name name)
    {
        // push arguments
        emitPushArguments(name);

        // invocation
        if (member.isMethod())
        {
            if (IsMethodHandleLinkTo(member))
            {
                MethodType    mt   = member.getMethodType();
                TypeWrapper[] args = new TypeWrapper[mt.parameterCount()];
                for (int j = 0; j < args.Length; j++)
                {
                    args[j] = TypeWrapper.FromClass(mt.parameterType(j));
                    args[j].Finish();
                }
                TypeWrapper ret = TypeWrapper.FromClass(mt.returnType());
                ret.Finish();
                Compiler.MethodHandleMethodWrapper.EmitLinkToCall(ilgen, args, ret);
                ret.EmitConvSignatureTypeToStackType(ilgen);
            }
            else if (IsMethodHandleInvokeBasic(member))
            {
                EmitInvokeBasic(member.getMethodType());
            }
            else
            {
                switch (member.getReferenceKind())
                {
                case MethodHandleNatives.Constants.REF_invokeInterface:
                case MethodHandleNatives.Constants.REF_invokeSpecial:
                case MethodHandleNatives.Constants.REF_invokeStatic:
                case MethodHandleNatives.Constants.REF_invokeVirtual:
                    break;

                default:
                    throw new BailoutException(Bailout.UnsupportedRefKind, member);
                }
                MethodWrapper mw = GetMethodWrapper(member);
                if (!IsStaticallyInvocable(mw))
                {
                    throw new BailoutException(Bailout.NotStaticallyInvocable, member);
                }
                mw.Link();
                mw.DeclaringType.Finish();
                mw.ResolveMethod();
                if (mw.HasCallerID)
                {
                    EmitConstant(DynamicCallerIDProvider.Instance);
                    ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.DynamicCallerID);
                }
                if (mw.IsStatic || member.getReferenceKind() == MethodHandleNatives.Constants.REF_invokeSpecial)
                {
                    mw.EmitCall(ilgen);
                }
                else
                {
                    mw.EmitCallvirt(ilgen);
                }
                mw.ReturnType.EmitConvSignatureTypeToStackType(ilgen);
            }
        }
        else if (member.isField())
        {
            FieldWrapper fw = GetFieldWrapper(member);
            if (!IsStaticallyInvocable(fw))
            {
                throw new BailoutException(Bailout.NotStaticallyInvocable, member);
            }
            fw.Link();
            fw.DeclaringType.Finish();
            fw.ResolveField();
            switch (member.getReferenceKind())
            {
            case MethodHandleNatives.Constants.REF_getField:
            case MethodHandleNatives.Constants.REF_getStatic:
                fw.EmitGet(ilgen);
                fw.FieldTypeWrapper.EmitConvSignatureTypeToStackType(ilgen);
                break;

            case MethodHandleNatives.Constants.REF_putField:
            case MethodHandleNatives.Constants.REF_putStatic:
                fw.EmitSet(ilgen);
                break;

            default:
                throw new BailoutException(Bailout.UnsupportedRefKind, member);
            }
        }
        else
        {
            throw new BailoutException(Bailout.NotStaticallyInvocable, member);
        }
    }