Inheritance: DynamicTypeWrapper
Exemple #1
0
 internal WorkaroundBaseClass(AotTypeWrapper wrapper, TypeBuilder typeBuilder, MethodWrapper[] methods)
 {
     this.wrapper = wrapper;
     this.typeBuilder = typeBuilder;
     this.methods = methods;
 }
 internal override sealed 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;
 }