Inheritance: TypeWrapperFactory
示例#1
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
        }
示例#2
0
        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);
        }
示例#3
0
文件: Proxy.cs 项目: moayyaed/ikvm
        private static void CreateNoFail(CompilerClassLoader loader, TypeWrapper[] interfaces, List <ProxyMethod> methods)
        {
            bool ispublic = true;

            Type[] interfaceTypes = new Type[interfaces.Length];
            for (int i = 0; i < interfaceTypes.Length; i++)
            {
                ispublic         &= interfaces[i].IsPublic;
                interfaceTypes[i] = interfaces[i].TypeAsBaseType;
            }
            TypeAttributes attr = TypeAttributes.Class | TypeAttributes.Sealed;

            attr |= ispublic ? TypeAttributes.NestedPublic : TypeAttributes.NestedAssembly;
            DynamicClassLoader factory = (DynamicClassLoader)loader.GetTypeWrapperFactory();
            TypeBuilder        tb      = factory.DefineProxy(TypeNameUtil.GetProxyNestedName(interfaces), attr, proxyClass.TypeAsBaseType, interfaceTypes);

            AttributeHelper.SetImplementsAttribute(tb, interfaces);
            // we apply an InnerClass attribute to avoid the CompiledTypeWrapper heuristics for figuring out the modifiers
            AttributeHelper.SetInnerClass(tb, null, ispublic ? Modifiers.Public | Modifiers.Final : Modifiers.Final);
            CreateConstructor(tb);
            for (int i = 0; i < methods.Count; i++)
            {
                methods[i].fb = tb.DefineField("m" + i, javaLangReflectMethod.TypeAsSignatureType, FieldAttributes.Private | FieldAttributes.Static);
            }
            foreach (ProxyMethod method in methods)
            {
                CreateMethod(loader, tb, method);
            }
            CreateStaticInitializer(tb, methods, loader);
        }
示例#4
0
        internal TypeWrapperFactory GetTypeWrapperFactory()
        {
            if (factory == null)
            {
                lock (this)
                {
                    if (factory == null)
                    {
#if CLASSGC
                        if (dynamicAssemblies == null)
                        {
                            Interlocked.CompareExchange(ref dynamicAssemblies, new ConditionalWeakTable <Assembly, ClassLoaderWrapper>(), null);
                        }
                        typeToTypeWrapper = new Dictionary <Type, TypeWrapper>();
                        DynamicClassLoader instance = DynamicClassLoader.Get(this);
                        dynamicAssemblies.Add(instance.ModuleBuilder.Assembly.ManifestModule.Assembly, this);
                        this.factory = instance;
#else
                        factory = DynamicClassLoader.Get(this);
#endif
                    }
                }
            }
            return(factory);
        }
示例#5
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);
        }
示例#6
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
        }
示例#7
0
        private static void CreateNoFail(CompilerClassLoader loader, TypeWrapper[] interfaces, List <ProxyMethod> methods)
        {
            DynamicClassLoader factory = (DynamicClassLoader)loader.GetTypeWrapperFactory();
            TypeBuilder        tb      = factory.DefineProxy(proxyClass, interfaces);

            AttributeHelper.SetImplementsAttribute(tb, interfaces);
            CreateConstructor(tb);
            for (int i = 0; i < methods.Count; i++)
            {
                methods[i].fb = tb.DefineField("m" + i, javaLangReflectMethod.TypeAsSignatureType, FieldAttributes.Private | FieldAttributes.Static);
            }
            foreach (ProxyMethod method in methods)
            {
                CreateMethod(loader, tb, method);
            }
            CreateStaticInitializer(tb, methods);
        }
示例#8
0
 public static void SaveDebugImage()
 {
     DynamicClassLoader.SaveDebugImages();
 }
 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;
 }
 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;
 }
示例#11
0
        public static void SaveDebugImage()
        {
#if !NOEMIT
            DynamicClassLoader.SaveDebugImages();
#endif
        }