Пример #1
0
        internal sealed override TypeWrapper DefineClassImpl(Dictionary <string, TypeWrapper> types, ClassFile f, ClassLoaderWrapper classLoader, object protectionDomain)
        {
            DynamicTypeWrapper type;

#if STATIC_COMPILER
            type = new AotTypeWrapper(f, (CompilerClassLoader)classLoader);
#else
            type = new DynamicTypeWrapper(f, classLoader);
#endif
            // this step can throw a retargettable exception, if the class is incorrect
            bool hasclinit;
            type.CreateStep1(out hasclinit);
            // now we can allocate the mangledTypeName, because the next step cannot fail
            string mangledTypeName = AllocMangledName(f.Name);
            // This step actually creates the TypeBuilder. It is not allowed to throw any exceptions,
            // if an exception does occur, it is due to a programming error in the IKVM or CLR runtime
            // and will cause a CriticalFailure and exit the process.
            type.CreateStep2NoFail(hasclinit, mangledTypeName);
            lock (types)
            {
                // in very extreme conditions another thread may have beaten us to it
                // and loaded (not defined) a class with the same name, in that case
                // we'll leak the the Reflection.Emit defined type. Also see the comment
                // in ClassLoaderWrapper.RegisterInitiatingLoader().
                TypeWrapper race;
                types.TryGetValue(f.Name, out race);
                if (race == null)
                {
                    lock (dynamicTypes)
                    {
                        Debug.Assert(dynamicTypes.ContainsKey(mangledTypeName) && dynamicTypes[mangledTypeName] == null);
                        dynamicTypes[mangledTypeName] = type;
                    }
                    types[f.Name] = type;
#if !STATIC_COMPILER && !FIRST_PASS
                    java.lang.Class clazz = new java.lang.Class(null);
#if __MonoCS__
                    TypeWrapper.SetTypeWrapperHack(clazz, type);
#else
                    clazz.typeWrapper = type;
#endif
                    clazz.pd = (java.security.ProtectionDomain)protectionDomain;
                    type.SetClassObject(clazz);
#endif
                }
                else
                {
                    throw new LinkageError("duplicate class definition: " + f.Name);
                }
            }
            return(type);
        }
Пример #2
0
        internal sealed override TypeWrapper DefineClassImpl(Dictionary <string, TypeWrapper> types, TypeWrapper host, ClassFile f, ClassLoaderWrapper classLoader, ProtectionDomain protectionDomain)
        {
#if STATIC_COMPILER
            AotTypeWrapper type = new AotTypeWrapper(f, (CompilerClassLoader)classLoader);
            type.CreateStep1();
            types[f.Name] = type;
            return(type);
#elif FIRST_PASS
            return(null);
#else
            // this step can throw a retargettable exception, if the class is incorrect
            DynamicTypeWrapper type = new DynamicTypeWrapper(host, f, classLoader, protectionDomain);
            // This step actually creates the TypeBuilder. It is not allowed to throw any exceptions,
            // if an exception does occur, it is due to a programming error in the IKVM or CLR runtime
            // and will cause a CriticalFailure and exit the process.
            type.CreateStep1();
            type.CreateStep2();
            if (types == null)
            {
                // we're defining an anonymous class, so we don't need any locking
                TieClassAndWrapper(type, protectionDomain);
                return(type);
            }
            lock (types)
            {
                // in very extreme conditions another thread may have beaten us to it
                // and loaded (not defined) a class with the same name, in that case
                // we'll leak the the Reflection.Emit defined type. Also see the comment
                // in ClassLoaderWrapper.RegisterInitiatingLoader().
                TypeWrapper race;
                types.TryGetValue(f.Name, out race);
                if (race == null)
                {
                    types[f.Name] = type;
                    TieClassAndWrapper(type, protectionDomain);
                }
                else
                {
                    throw new LinkageError("duplicate class definition: " + f.Name);
                }
            }
            return(type);
#endif // STATIC_COMPILER
        }