Beispiel #1
0
        internal void SetWrapperForType(Type type, TypeWrapper wrapper)
        {
#if !STATIC_COMPILER
            TypeWrapper.AssertFinished(type);
#endif
            Dictionary <Type, TypeWrapper> dict;
#if CLASSGC
            dict = typeToTypeWrapper ?? globalTypeToTypeWrapper;
#else
            dict = globalTypeToTypeWrapper;
#endif
            lock (dict)
            {
                dict.Add(type, wrapper);
            }
        }
Beispiel #2
0
        internal static TypeWrapper GetWrapperFromType(Type type)
        {
            //Tracer.Info(Tracer.Runtime, "GetWrapperFromType: {0}", type.AssemblyQualifiedName);
#if !STATIC_COMPILER
            TypeWrapper.AssertFinished(type);
#endif
            Debug.Assert(!type.IsPointer);
            Debug.Assert(!type.IsByRef);
            TypeWrapper wrapper;
            lock (globalTypeToTypeWrapper)
            {
                globalTypeToTypeWrapper.TryGetValue(type, out wrapper);
            }
            if (wrapper != null)
            {
                return(wrapper);
            }
            string remapped;
            if (remappedTypes.TryGetValue(type, out remapped))
            {
                wrapper = LoadClassCritical(remapped);
            }
            else if (ReflectUtil.IsVector(type))
            {
                // it might be an array of a dynamically compiled Java type
                int  rank = 1;
                Type elem = type.GetElementType();
                while (ReflectUtil.IsVector(elem))
                {
                    rank++;
                    elem = elem.GetElementType();
                }
                wrapper = GetWrapperFromType(elem).MakeArrayType(rank);
            }
            else
            {
                Assembly asm = type.Assembly;
#if CLASSGC
                ClassLoaderWrapper loader;
                if (dynamicAssemblies != null && dynamicAssemblies.TryGetValue(asm, out loader))
                {
                    lock (loader.typeToTypeWrapper)
                    {
                        return(loader.typeToTypeWrapper[type]);
                    }
                }
#endif
#if !STATIC_COMPILER && !STUB_GENERATOR
                if (ReflectUtil.IsReflectionOnly(type))
                {
                    // historically we've always returned null for types that don't have a corresponding TypeWrapper (or java.lang.Class)
                    return(null);
                }
#endif
                // if the wrapper doesn't already exist, that must mean that the type
                // is a .NET type (or a pre-compiled Java class), which means that it
                // was "loaded" by an assembly classloader
                wrapper = AssemblyClassLoader.FromAssembly(asm).GetWrapperFromAssemblyType(type);
            }
#if CLASSGC
            if (type.Assembly.IsDynamic)
            {
                // don't cache types in dynamic assemblies, because they might live in a RunAndCollect assembly
                // TODO we also shouldn't cache generic type instances that have a GCable type parameter
                return(wrapper);
            }
#endif
            lock (globalTypeToTypeWrapper)
            {
                globalTypeToTypeWrapper[type] = wrapper;
            }
            return(wrapper);
        }