private static TypeWrapper GetWrapper(TypeWrapper primitive)
        {
            Debug.Assert(primitive.IsPrimitive);
            switch (primitive.SigName[0])
            {
            case 'Z':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Boolean"));

            case 'B':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Byte"));

            case 'S':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Short"));

            case 'C':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Character"));

            case 'I':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Integer"));

            case 'J':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Long"));

            case 'F':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Float"));

            case 'D':
                return(ClassLoaderWrapper.LoadClassCritical("java.lang.Double"));

            default:
                throw new InvalidOperationException();
            }
        }
Example #2
0
        internal override bool InternalsVisibleToImpl(TypeWrapper wrapper, TypeWrapper friend)
        {
            ClassLoaderWrapper other = friend.GetClassLoader();

            if (this == other)
            {
                return(true);
            }
            AssemblyName otherName;

#if STATIC_COMPILER
            CompilerClassLoader ccl = other as CompilerClassLoader;
            if (ccl == null)
            {
                return(false);
            }
            otherName = ccl.GetAssemblyName();
#else
            AssemblyClassLoader acl = other as AssemblyClassLoader;
            if (acl == null)
            {
                return(false);
            }
            otherName = acl.GetAssembly(friend).GetName();
#endif
            return(GetLoaderForExportedAssembly(GetAssembly(wrapper)).InternalsVisibleTo(otherName));
        }
Example #3
0
        internal static DynamicClassLoader Get(ClassLoaderWrapper loader)
        {
#if STATIC_COMPILER
            return(new DynamicClassLoader(((CompilerClassLoader)loader).CreateModuleBuilder(), false));
#else
            AssemblyClassLoader acl = loader as AssemblyClassLoader;
            if (acl != null && ForgedKeyPair.Instance != null)
            {
                string name = acl.MainAssembly.GetName().Name + DynamicAssemblySuffixAndPublicKey;
                foreach (InternalsVisibleToAttribute attr in acl.MainAssembly.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false))
                {
                    if (attr.AssemblyName == name)
                    {
                        AssemblyName n = new AssemblyName(name);
                        n.KeyPair = ForgedKeyPair.Instance;
                        return(new DynamicClassLoader(CreateModuleBuilder(n), true));
                    }
                }
            }
#if CLASSGC
            DynamicClassLoader instance = new DynamicClassLoader(CreateModuleBuilder(), false);
#endif
            return(instance);
#endif
        }
Example #4
0
        internal static void AddGetObjectData(TypeBuilder tb)
        {
            string name = tb.IsSealed
                                ? "System.Runtime.Serialization.ISerializable.GetObjectData"
                                : "GetObjectData";
            MethodAttributes attr = tb.IsSealed
                                ? MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.Final
                                : MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.NewSlot | MethodAttributes.CheckAccessOnOverride;

            tb.AddInterfaceImplementation(JVM.Import(typeof(ISerializable)));
            MethodBuilder getObjectData = tb.DefineMethod(name, attr, null,
                                                          new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });

            getObjectData.SetCustomAttribute(securityCriticalAttribute);
            AttributeHelper.HideFromJava(getObjectData);
            // AddDeclarativeSecurity does not exist in .net core
#if NETFRAMEWORK
            getObjectData.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
#endif
            tb.DefineMethodOverride(getObjectData, JVM.Import(typeof(ISerializable)).GetMethod("GetObjectData"));
            CodeEmitter ilgen = CodeEmitter.Create(getObjectData);
            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldarg_1);
            TypeWrapper   serializationHelper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.Serialization");
            MethodWrapper mw = serializationHelper.GetMethodWrapper("writeObject", "(Ljava.lang.Object;Lcli.System.Runtime.Serialization.SerializationInfo;)V", false);
            mw.Link();
            mw.EmitCall(ilgen);
            ilgen.Emit(OpCodes.Ret);
            ilgen.DoEmit();
        }
Example #5
0
        private static MethodBuilder AddConstructor(TypeBuilder tb, MethodWrapper defaultConstructor, MethodBase serializationConstructor, bool callReadObject)
        {
            MethodBuilder ctor = ReflectUtil.DefineConstructor(tb, MethodAttributes.Family, new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });

            AttributeHelper.HideFromJava(ctor);
            // AddDeclarativeSecurity does not exist in .net core
#if NETFRAMEWORK
            ctor.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
#endif
            CodeEmitter ilgen = CodeEmitter.Create(ctor);
            ilgen.Emit(OpCodes.Ldarg_0);
            if (defaultConstructor != null)
            {
                defaultConstructor.EmitCall(ilgen);
            }
            else
            {
                ilgen.Emit(OpCodes.Ldarg_1);
                ilgen.Emit(OpCodes.Ldarg_2);
                ilgen.Emit(OpCodes.Call, serializationConstructor);
            }
            if (callReadObject)
            {
                ilgen.Emit(OpCodes.Ldarg_0);
                ilgen.Emit(OpCodes.Ldarg_1);
                TypeWrapper   serializationHelper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.Serialization");
                MethodWrapper mw = serializationHelper.GetMethodWrapper("readObject", "(Ljava.lang.Object;Lcli.System.Runtime.Serialization.SerializationInfo;)V", false);
                mw.Link();
                mw.EmitCall(ilgen);
            }
            ilgen.Emit(OpCodes.Ret);
            ilgen.DoEmit();
            return(ctor);
        }
Example #6
0
        private static ConstructorBuilder DefineThreadLocalType(DynamicTypeWrapper.FinishContext context, int opcodeIndex, MethodWrapper caller)
        {
            TypeWrapper  threadLocal = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.IntrinsicThreadLocal");
            TypeBuilder  tb          = caller.DeclaringType.TypeAsBuilder.DefineNestedType("__<tls>_" + opcodeIndex, TypeAttributes.NestedPrivate | TypeAttributes.Sealed, threadLocal.TypeAsBaseType);
            FieldBuilder fb          = tb.DefineField("field", Types.Object, FieldAttributes.Private | FieldAttributes.Static);

            fb.SetCustomAttribute(new CustomAttributeBuilder(JVM.Import(typeof(ThreadStaticAttribute)).GetConstructor(Type.EmptyTypes), new object[0]));
            MethodBuilder mbGet = tb.DefineMethod("get", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final, Types.Object, Type.EmptyTypes);
            ILGenerator   ilgen = mbGet.GetILGenerator();

            ilgen.Emit(OpCodes.Ldsfld, fb);
            ilgen.Emit(OpCodes.Ret);
            MethodBuilder mbSet = tb.DefineMethod("set", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final, null, new Type[] { Types.Object });

            ilgen = mbSet.GetILGenerator();
            ilgen.Emit(OpCodes.Ldarg_1);
            ilgen.Emit(OpCodes.Stsfld, fb);
            ilgen.Emit(OpCodes.Ret);
            ConstructorBuilder cb        = tb.DefineConstructor(MethodAttributes.Assembly, CallingConventions.Standard, Type.EmptyTypes);
            CodeEmitter        ctorilgen = CodeEmitter.Create(cb);

            ctorilgen.Emit(OpCodes.Ldarg_0);
            MethodWrapper basector = threadLocal.GetMethodWrapper("<init>", "()V", false);

            basector.Link();
            basector.EmitCall(ctorilgen);
            ctorilgen.Emit(OpCodes.Ret);
            context.RegisterPostFinishProc(delegate
            {
                threadLocal.Finish();
                tb.CreateType();
            });
            return(cb);
        }
Example #7
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);
        }
Example #8
0
        private static AssemblyClassLoader Create(Assembly assembly)
        {
            // If the assembly is a part of a multi-assembly shared class loader,
            // it will export the __<MainAssembly> type from the main assembly in the group.
            Type forwarder = assembly.GetType("__<MainAssembly>");

            if (forwarder != null)
            {
                Assembly mainAssembly = forwarder.Assembly;
                if (mainAssembly != assembly)
                {
                    return(FromAssembly(mainAssembly));
                }
            }
#if STATIC_COMPILER
            if (JVM.CoreAssembly == null && CompilerClassLoader.IsCoreAssembly(assembly))
            {
                JVM.CoreAssembly = assembly;
                ClassLoaderWrapper.LoadRemappedTypes();
            }
#endif
            if (assembly == JVM.CoreAssembly)
            {
                // This cast is necessary for ikvmc and a no-op for the runtime.
                // Note that the cast cannot fail, because ikvmc will only return a non AssemblyClassLoader
                // from GetBootstrapClassLoader() when compiling the core assembly and in that case JVM.CoreAssembly
                // will be null.
                return((AssemblyClassLoader)GetBootstrapClassLoader());
            }
            return(new AssemblyClassLoader(assembly));
        }
Example #9
0
 internal static int GetGenericClassLoaderId(ClassLoaderWrapper wrapper)
 {
     lock (wrapperLock)
     {
         return(genericClassLoaders.IndexOf(wrapper as GenericClassLoader));
     }
 }
        private static Assembly OnTypeResolve(object sender, ResolveEventArgs args)
        {
            TypeWrapper type;

#if CLASSGC
            DynamicClassLoader instance;
            ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderForDynamicJavaAssembly(args.RequestingAssembly);
            if (loader == null)
            {
                return(null);
            }
            instance = (DynamicClassLoader)loader.GetTypeWrapperFactory();
#endif
            instance.dynamicTypes.TryGetValue(args.Name, out type);
            if (type == null)
            {
                return(null);
            }
            try
            {
                type.Finish();
            }
            catch (RetargetableJavaException x)
            {
                throw x.ToJava();
            }
            // NOTE We used to remove the type from the hashtable here, but that creates a race condition if
            // another thread also fires the OnTypeResolve event while we're baking the type.
            // I really would like to remove the type from the hashtable, but at the moment I don't see
            // any way of doing that that wouldn't cause this race condition.
            // UPDATE since we now also use the dynamicTypes hashtable to keep track of type names that
            // have been used already, we cannot remove the keys.
            return(type.TypeAsTBD.Assembly);
        }
Example #11
0
        private static void CreateEnumEnum(ModuleBuilder modb, ClassLoaderWrapper loader)
        {
            TypeBuilder tb = modb.DefineType(DotNetTypeWrapper.GenericEnumEnumTypeName, TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public);
            GenericTypeParameterBuilder gtpb = tb.DefineGenericParameters("T")[0];

            gtpb.SetBaseTypeConstraint(Types.Enum);
            genericEnumEnumType = tb;
        }
        internal TypeWrapper DefineClass(ClassFile f, object protectionDomain)
        {
#if NOEMIT
            throw new InvalidOperationException();
#else
            string dotnetAssembly = f.IKVMAssemblyAttribute;
            if (dotnetAssembly != null)
            {
                // It's a stub class generated by ikvmstub (or generated by the runtime when getResource was
                // called on a statically compiled class).
                ClassLoaderWrapper loader;
                try
                {
                    loader = ClassLoaderWrapper.GetAssemblyClassLoaderByName(dotnetAssembly);
                }
                catch (Exception x)
                {
                    // TODO don't catch all exceptions here
                    throw new NoClassDefFoundError(f.Name + " (" + x.Message + ")");
                }
                TypeWrapper tw = loader.LoadClassByDottedNameFast(f.Name);
                if (tw == null)
                {
                    throw new NoClassDefFoundError(f.Name + " (type not found in " + dotnetAssembly + ")");
                }
                return(RegisterInitiatingLoader(tw));
            }
            CheckDefineClassAllowed(f.Name);
            lock (types)
            {
                if (types.ContainsKey(f.Name))
                {
                    throw new LinkageError("duplicate class definition: " + f.Name);
                }
                // mark the type as "loading in progress", so that we can detect circular dependencies.
                types.Add(f.Name, null);
                defineClassInProgress.Add(f.Name, Thread.CurrentThread);
            }
            try
            {
                return(GetTypeWrapperFactory().DefineClassImpl(types, f, this, protectionDomain));
            }
            finally
            {
                lock (types)
                {
                    if (types[f.Name] == null)
                    {
                        // if loading the class fails, we remove the indicator that we're busy loading the class,
                        // because otherwise we get a ClassCircularityError if we try to load the class again.
                        types.Remove(f.Name);
                    }
                    defineClassInProgress.Remove(f.Name);
                    Monitor.PulseAll(types);
                }
            }
        }
Example #13
0
        internal void EmitThrow(string dottedClassName)
        {
            TypeWrapper   exception = ClassLoaderWrapper.GetBootstrapClassLoader().LoadClassByDottedName(dottedClassName);
            MethodWrapper mw        = exception.GetMethodWrapper("<init>", "()V", false);

            mw.Link();
            mw.EmitNewobj(this);
            Emit(OpCodes.Throw);
        }
        private static void EmitUnboxNumber(CodeEmitter ilgen, string methodName, string methodSig)
        {
            TypeWrapper tw = ClassLoaderWrapper.LoadClassCritical("java.lang.Number");

            tw.EmitCheckcast(ilgen);
            MethodWrapper mw = tw.GetMethodWrapper(methodName, methodSig, false);

            mw.Link();
            mw.EmitCallvirt(ilgen);
        }
Example #15
0
        protected static void SetWrapperForClassLoader(object javaClassLoader, ClassLoaderWrapper wrapper)
        {
#if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR
#if __MonoCS__
            SetClassLoadWrapperHack(ref ((java.lang.ClassLoader)javaClassLoader).wrapper, wrapper);
#else
            ((java.lang.ClassLoader)javaClassLoader).wrapper = wrapper;
#endif
#endif
        }
        protected static void SetWrapperForClassLoader(object javaClassLoader, ClassLoaderWrapper wrapper)
        {
#if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR
#if __MonoCS__
            typeof(java.lang.ClassLoader).GetField("wrapper", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(javaClassLoader, wrapper);
#else
            ((java.lang.ClassLoader)javaClassLoader).wrapper = wrapper;
#endif
#endif
        }
Example #17
0
        internal static void Create(ModuleBuilder modb, ClassLoaderWrapper loader)
        {
            TypeBuilder tb = modb.DefineType(DotNetTypeWrapper.GenericDelegateInterfaceTypeName, TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public);

            tb.DefineGenericParameters("T")[0].SetBaseTypeConstraint(Types.MulticastDelegate);
            genericDelegateInterfaceType = tb.CreateType();

            genericAttributeAnnotationType            = CreateAnnotationType(modb, DotNetTypeWrapper.GenericAttributeAnnotationTypeName);
            genericAttributeAnnotationMultipleType    = CreateAnnotationType(modb, DotNetTypeWrapper.GenericAttributeAnnotationMultipleTypeName);
            genericAttributeAnnotationReturnValueType = CreateAnnotationType(modb, DotNetTypeWrapper.GenericAttributeAnnotationReturnValueTypeName);
            CreateEnumEnum(modb, loader);
        }
Example #18
0
        internal static AssemblyClassLoader GetBootstrapClassLoader()
#endif
        {
            lock (wrapperLock)
            {
                if (bootstrapClassLoader == null)
                {
                    bootstrapClassLoader = new BootstrapClassLoader();
                }
                return(bootstrapClassLoader);
            }
        }
        internal static TypeWrapper LoadClassNoThrow(ClassLoaderWrapper classLoader, string name)
        {
            try
            {
                TypeWrapper wrapper = classLoader.LoadClassByDottedNameFast(name);
                if (wrapper == null)
                {
                    string elementTypeName = name;
                    if (elementTypeName.StartsWith("["))
                    {
                        int skip = 1;
                        while (elementTypeName[skip++] == '[')
                        {
                            ;
                        }
                        elementTypeName = elementTypeName.Substring(skip, elementTypeName.Length - skip - 1);
                    }
#if STATIC_COMPILER
                    classLoader.IssueMessage(Message.ClassNotFound, elementTypeName);
#else
                    Tracer.Error(Tracer.ClassLoading, "Class not found: {0}", elementTypeName);
#endif
                    wrapper = new UnloadableTypeWrapper(name);
                }
                return(wrapper);
            }
            catch (RetargetableJavaException x)
            {
                // HACK keep the compiler from warning about unused local
                GC.KeepAlive(x);
#if !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR && !NOEMIT
                if (Tracer.ClassLoading.TraceError)
                {
                    java.lang.ClassLoader cl = (java.lang.ClassLoader)classLoader.GetJavaClassLoader();
                    if (cl != null)
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        string sep = "";
                        while (cl != null)
                        {
                            sb.Append(sep).Append(cl);
                            sep = " -> ";
                            cl  = cl.getParent();
                        }
                        Tracer.Error(Tracer.ClassLoading, "ClassLoader chain: {0}", sb);
                    }
                    Exception m = ikvm.runtime.Util.mapException(x.ToJava());
                    Tracer.Error(Tracer.ClassLoading, m.ToString() + Environment.NewLine + m.StackTrace);
                }
#endif // !STATIC_COMPILER && !FIRST_PASS && !STUB_GENERATOR
                return(new UnloadableTypeWrapper(name));
            }
        }
Example #20
0
 private static TypeWrapper[] LoadTypes(ClassLoaderWrapper loader, string[] classes)
 {
     if (classes == null || classes.Length == 0)
     {
         return(TypeWrapper.EmptyArray);
     }
     TypeWrapper[] tw = new TypeWrapper[classes.Length];
     for (int i = 0; i < tw.Length; i++)
     {
         tw[i] = loader.LoadClassByDottedName(classes[i]);
     }
     return(tw);
 }
Example #21
0
        internal static DynamicClassLoader Get(ClassLoaderWrapper loader)
        {
#if STATIC_COMPILER
            DynamicClassLoader instance = new DynamicClassLoader(((CompilerClassLoader)loader).CreateModuleBuilder());
#elif CLASSGC
            DynamicClassLoader instance = new DynamicClassLoader(CreateModuleBuilder());
            if (saveClassLoaders != null)
            {
                saveClassLoaders.Add(instance);
            }
#endif
            return(instance);
        }
Example #22
0
        private static string GetFileName(StackFrame frame)
        {
            MethodBase mb = frame.GetMethod();

            if (mb != null)
            {
                TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(mb.DeclaringType);
                if (tw != null)
                {
                    return(tw.GetSourceFileName());
                }
            }
            return(null);
        }
Example #23
0
        private static Assembly OnTypeResolve(object sender, ResolveEventArgs args)
        {
#if CLASSGC
            ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderForDynamicJavaAssembly(args.RequestingAssembly);
            if (loader == null)
            {
                return(null);
            }
            DynamicClassLoader instance = (DynamicClassLoader)loader.GetTypeWrapperFactory();
            return(Resolve(instance.dynamicTypes, args.Name));
#else
            return(Resolve(dynamicTypes, args.Name));
#endif
        }
Example #24
0
        internal static void Finish(ClassLoaderWrapper loader)
        {
            TypeBuilder tb = (TypeBuilder)genericEnumEnumType;
            TypeWrapper enumTypeWrapper = loader.LoadClassByDottedName("java.lang.Enum");

            enumTypeWrapper.Finish();
            tb.SetParent(enumTypeWrapper.TypeAsBaseType);
            CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineConstructor(tb, MethodAttributes.Private, new Type[] { Types.String, Types.Int32 }));

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldarg_1);
            ilgen.Emit(OpCodes.Ldarg_2);
            enumTypeWrapper.GetMethodWrapper("<init>", "(Ljava.lang.String;I)V", false).EmitCall(ilgen);
            ilgen.Emit(OpCodes.Ret);
            ilgen.DoEmit();
            genericEnumEnumType = tb.CreateType();
        }
Example #25
0
        static Boxer()
        {
            ClassLoaderWrapper bootClassLoader = ClassLoaderWrapper.GetBootstrapClassLoader();

            javaLangByte = bootClassLoader.LoadClassByDottedNameFast("java.lang.Byte");
            byteValue    = javaLangByte.GetMethodWrapper("byteValue", "()B", false);
            byteValue.Link();
            valueOfByte = javaLangByte.GetMethodWrapper("valueOf", "(B)Ljava.lang.Byte;", false);
            valueOfByte.Link();
            javaLangBoolean = bootClassLoader.LoadClassByDottedNameFast("java.lang.Boolean");
            booleanValue    = javaLangBoolean.GetMethodWrapper("booleanValue", "()Z", false);
            booleanValue.Link();
            valueOfBoolean = javaLangBoolean.GetMethodWrapper("valueOf", "(Z)Ljava.lang.Boolean;", false);
            valueOfBoolean.Link();
            javaLangShort = bootClassLoader.LoadClassByDottedNameFast("java.lang.Short");
            shortValue    = javaLangShort.GetMethodWrapper("shortValue", "()S", false);
            shortValue.Link();
            valueOfShort = javaLangShort.GetMethodWrapper("valueOf", "(S)Ljava.lang.Short;", false);
            valueOfShort.Link();
            javaLangCharacter = bootClassLoader.LoadClassByDottedNameFast("java.lang.Character");
            charValue         = javaLangCharacter.GetMethodWrapper("charValue", "()C", false);
            charValue.Link();
            valueOfCharacter = javaLangCharacter.GetMethodWrapper("valueOf", "(C)Ljava.lang.Character;", false);
            valueOfCharacter.Link();
            javaLangInteger = bootClassLoader.LoadClassByDottedNameFast("java.lang.Integer");
            intValue        = javaLangInteger.GetMethodWrapper("intValue", "()I", false);
            intValue.Link();
            valueOfInteger = javaLangInteger.GetMethodWrapper("valueOf", "(I)Ljava.lang.Integer;", false);
            valueOfInteger.Link();
            javaLangFloat = bootClassLoader.LoadClassByDottedNameFast("java.lang.Float");
            floatValue    = javaLangFloat.GetMethodWrapper("floatValue", "()F", false);
            floatValue.Link();
            valueOfFloat = javaLangFloat.GetMethodWrapper("valueOf", "(F)Ljava.lang.Float;", false);
            valueOfFloat.Link();
            javaLangLong = bootClassLoader.LoadClassByDottedNameFast("java.lang.Long");
            longValue    = javaLangLong.GetMethodWrapper("longValue", "()J", false);
            longValue.Link();
            valueOfLong = javaLangLong.GetMethodWrapper("valueOf", "(J)Ljava.lang.Long;", false);
            valueOfLong.Link();
            javaLangDouble = bootClassLoader.LoadClassByDottedNameFast("java.lang.Double");
            doubleValue    = javaLangDouble.GetMethodWrapper("doubleValue", "()D", false);
            doubleValue.Link();
            valueOfDouble = javaLangDouble.GetMethodWrapper("valueOf", "(D)Ljava.lang.Double;", false);
            valueOfDouble.Link();
        }
Example #26
0
        private static void CreateEnumEnum(ModuleBuilder modb, ClassLoaderWrapper loader)
        {
            TypeWrapper enumTypeWrapper = loader.LoadClassByDottedName("java.lang.Enum");

            enumTypeWrapper.Finish();
            TypeBuilder tb = modb.DefineType(DotNetTypeWrapper.GenericEnumEnumTypeName, TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public, enumTypeWrapper.TypeAsBaseType);
            GenericTypeParameterBuilder gtpb = tb.DefineGenericParameters("T")[0];

            gtpb.SetBaseTypeConstraint(Types.Enum);
            CodeEmitter ilgen = CodeEmitter.Create(tb.DefineConstructor(MethodAttributes.Private, CallingConventions.Standard, new Type[] { Types.String, Types.Int32 }));

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldarg_1);
            ilgen.Emit(OpCodes.Ldarg_2);
            enumTypeWrapper.GetMethodWrapper("<init>", "(Ljava.lang.String;I)V", false).EmitCall(ilgen);
            ilgen.Emit(OpCodes.Ret);
            genericEnumEnumType = tb.CreateType();
        }
Example #27
0
        private static int GetLineNumber(StackFrame frame)
        {
            int ilOffset = frame.GetILOffset();

            if (ilOffset != StackFrame.OFFSET_UNKNOWN)
            {
                MethodBase mb = frame.GetMethod();
                if (mb != null)
                {
                    TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(mb.DeclaringType);
                    if (tw != null)
                    {
                        return(tw.GetSourceLineNumber(mb, ilOffset));
                    }
                }
            }
            return(-1);
        }
Example #28
0
        private static string getClassNameFromType(Type type)
        {
            if (ClassLoaderWrapper.IsRemappedType(type))
            {
                return(DotNetTypeWrapper.GetName(type));
            }
            TypeWrapper tw = ClassLoaderWrapper.GetWrapperFromType(type);

            if (tw != null)
            {
                if (tw.IsPrimitive)
                {
                    return(DotNetTypeWrapper.GetName(type));
                }
                return(tw.Name);
            }
            return(type.FullName);
        }
Example #29
0
        internal static ClassLoaderWrapper GetGenericClassLoaderByName(string name)
        {
            Debug.Assert(name.StartsWith("[[") && name.EndsWith("]]"));
            Stack <List <ClassLoaderWrapper> > stack = new Stack <List <ClassLoaderWrapper> >();
            List <ClassLoaderWrapper>          list  = null;

            for (int i = 0; i < name.Length; i++)
            {
                if (name[i] == '[')
                {
                    if (name[i + 1] == '[')
                    {
                        stack.Push(list);
                        list = new List <ClassLoaderWrapper>();
                        if (name[i + 2] == '[')
                        {
                            i++;
                        }
                    }
                    else
                    {
                        int start = i + 1;
                        i = name.IndexOf(']', i);
                        list.Add(ClassLoaderWrapper.GetAssemblyClassLoaderByName(name.Substring(start, i - start)));
                    }
                }
                else if (name[i] == ']')
                {
                    ClassLoaderWrapper loader = GetGenericClassLoaderByKey(list.ToArray());
                    list = stack.Pop();
                    if (list == null)
                    {
                        return(loader);
                    }
                    list.Add(loader);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            throw new InvalidOperationException();
        }
Example #30
0
        internal static MethodBuilder DefineTypeInitializer(TypeBuilder typeBuilder, ClassLoaderWrapper loader)
        {
            MethodAttributes attr = MethodAttributes.Static | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;

            if (typeBuilder.IsInterface && loader.WorkaroundInterfacePrivateMethods)
            {
                // LAMESPEC the ECMA spec says (part. I, sect. 8.5.3.2) that all interface members must be public, so we make
                // the class constructor public.
                // NOTE it turns out that on .NET 2.0 this isn't necessary anymore (neither Ref.Emit nor the CLR verifier complain about it),
                // but the C# compiler still considers interfaces with non-public methods to be invalid, so to keep interop with C# we have
                // to keep making the .cctor method public.
                attr |= MethodAttributes.Public;
            }
            else
            {
                attr |= MethodAttributes.Private;
            }
            return(typeBuilder.DefineMethod(ConstructorInfo.TypeConstructorName, attr, null, Type.EmptyTypes));
        }