зеркало из https://github.com/mono/ikvm-fork.git
*** empty log message ***
This commit is contained in:
Родитель
367039bfe7
Коммит
90c47e239a
|
@ -570,10 +570,7 @@ namespace IKVM.Internal
|
|||
{
|
||||
return typeBuilderGhostInterface.DefineMethod(name, attribs, mw.ReturnTypeForDefineMethod, mw.GetParametersForDefineMethod());
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.DefineGhostMethod(name, attribs, mw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void FinishGhost(TypeBuilder typeBuilder, MethodWrapper[] methods)
|
||||
|
@ -783,34 +780,27 @@ namespace IKVM.Internal
|
|||
}
|
||||
}
|
||||
|
||||
protected override TypeBuilder DefineType(string mangledTypeName, TypeAttributes typeAttribs)
|
||||
protected override TypeBuilder DefineGhostType(string mangledTypeName, TypeAttributes typeAttribs)
|
||||
{
|
||||
if(IsGhost)
|
||||
{
|
||||
typeAttribs &= ~(TypeAttributes.Interface | TypeAttributes.Abstract);
|
||||
typeAttribs |= TypeAttributes.Class | TypeAttributes.Sealed;
|
||||
TypeBuilder typeBuilder = classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs, typeof(ValueType));
|
||||
AttributeHelper.SetGhostInterface(typeBuilder);
|
||||
AttributeHelper.SetModifiers(typeBuilder, Modifiers, IsInternal);
|
||||
ghostRefField = typeBuilder.DefineField("__<ref>", typeof(object), FieldAttributes.Public | FieldAttributes.SpecialName);
|
||||
typeBuilderGhostInterface = typeBuilder.DefineNestedType("__Interface", TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic);
|
||||
AttributeHelper.HideFromJava(typeBuilderGhostInterface);
|
||||
ghostIsInstanceMethod = typeBuilder.DefineMethod("IsInstance", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object) });
|
||||
ghostIsInstanceMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostIsInstanceArrayMethod = typeBuilder.DefineMethod("IsInstanceArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object), typeof(int) });
|
||||
ghostIsInstanceArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostIsInstanceArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
|
||||
ghostCastMethod = typeBuilder.DefineMethod("Cast", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeBuilder, new Type[] { typeof(object) });
|
||||
ghostCastMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostCastArrayMethod = typeBuilder.DefineMethod("CastArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(object), typeof(int) });
|
||||
ghostCastArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostCastArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
|
||||
return typeBuilder;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.DefineType(mangledTypeName, typeAttribs);
|
||||
}
|
||||
typeAttribs &= ~(TypeAttributes.Interface | TypeAttributes.Abstract);
|
||||
typeAttribs |= TypeAttributes.Class | TypeAttributes.Sealed;
|
||||
TypeBuilder typeBuilder = classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs, typeof(ValueType));
|
||||
AttributeHelper.SetGhostInterface(typeBuilder);
|
||||
AttributeHelper.SetModifiers(typeBuilder, Modifiers, IsInternal);
|
||||
ghostRefField = typeBuilder.DefineField("__<ref>", typeof(object), FieldAttributes.Public | FieldAttributes.SpecialName);
|
||||
typeBuilderGhostInterface = typeBuilder.DefineNestedType("__Interface", TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic);
|
||||
AttributeHelper.HideFromJava(typeBuilderGhostInterface);
|
||||
ghostIsInstanceMethod = typeBuilder.DefineMethod("IsInstance", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object) });
|
||||
ghostIsInstanceMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostIsInstanceArrayMethod = typeBuilder.DefineMethod("IsInstanceArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object), typeof(int) });
|
||||
ghostIsInstanceArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostIsInstanceArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
|
||||
ghostCastMethod = typeBuilder.DefineMethod("Cast", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeBuilder, new Type[] { typeof(object) });
|
||||
ghostCastMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostCastArrayMethod = typeBuilder.DefineMethod("CastArray", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(object), typeof(int) });
|
||||
ghostCastArrayMethod.DefineParameter(1, ParameterAttributes.None, "obj");
|
||||
ghostCastArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
|
||||
return typeBuilder;
|
||||
}
|
||||
|
||||
internal override FieldInfo GhostRefField
|
||||
|
|
|
@ -93,25 +93,6 @@ namespace IKVM.Internal
|
|||
referencedAssemblies = temp;
|
||||
}
|
||||
|
||||
class CompilerTypeWrapperFactory : DynamicClassLoader
|
||||
{
|
||||
internal CompilerTypeWrapperFactory(ModuleBuilder moduleBuilder)
|
||||
: base(moduleBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
protected override DynamicTypeWrapper CreateDynamicTypeWrapper(ClassFile f, ClassLoaderWrapper loader)
|
||||
{
|
||||
CompilerClassLoader classLoader = (CompilerClassLoader)loader;
|
||||
int pos = f.Name.LastIndexOf('.');
|
||||
if(pos != -1)
|
||||
{
|
||||
classLoader.packages[f.Name.Substring(0, pos)] = "";
|
||||
}
|
||||
return new AotTypeWrapper(f, classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
internal override string SourcePath
|
||||
{
|
||||
get
|
||||
|
@ -120,12 +101,7 @@ namespace IKVM.Internal
|
|||
}
|
||||
}
|
||||
|
||||
protected override TypeWrapperFactory CreateTypeWrapperFactory()
|
||||
{
|
||||
return new CompilerTypeWrapperFactory(CreateModuleBuilder());
|
||||
}
|
||||
|
||||
private ModuleBuilder CreateModuleBuilder()
|
||||
internal ModuleBuilder CreateModuleBuilder()
|
||||
{
|
||||
AssemblyName name = new AssemblyName();
|
||||
name.Name = assemblyName;
|
||||
|
@ -2357,6 +2333,11 @@ namespace IKVM.Internal
|
|||
{
|
||||
wrapper.Finish();
|
||||
}
|
||||
int pos = wrapper.Name.LastIndexOf('.');
|
||||
if(pos != -1)
|
||||
{
|
||||
loader.packages[wrapper.Name.Substring(0, pos)] = "";
|
||||
}
|
||||
allwrappers.Add(wrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace IKVM.Internal
|
|||
private static readonly Hashtable typeToTypeWrapper = Hashtable.Synchronized(new Hashtable());
|
||||
#if STATIC_COMPILER
|
||||
private static ClassLoaderWrapper bootstrapClassLoader;
|
||||
private TypeWrapperFactory factory;
|
||||
#else
|
||||
private static AssemblyClassLoader bootstrapClassLoader;
|
||||
#endif
|
||||
|
@ -56,7 +57,6 @@ namespace IKVM.Internal
|
|||
private readonly object javaClassLoader;
|
||||
protected Hashtable types = new Hashtable();
|
||||
private ArrayList nativeLibraries;
|
||||
private TypeWrapperFactory factory;
|
||||
private CodeGenOptions codegenoptions;
|
||||
private static Hashtable remappedTypes = new Hashtable();
|
||||
|
||||
|
@ -244,7 +244,7 @@ namespace IKVM.Internal
|
|||
return RegisterInitiatingLoader(tw);
|
||||
}
|
||||
// this will create the factory as a side effect
|
||||
GetTypeWrapperFactory();
|
||||
TypeWrapperFactory factory = GetTypeWrapperFactory();
|
||||
lock(factory)
|
||||
{
|
||||
lock(types.SyncRoot)
|
||||
|
@ -278,22 +278,14 @@ namespace IKVM.Internal
|
|||
|
||||
internal TypeWrapperFactory GetTypeWrapperFactory()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
if(factory == null)
|
||||
{
|
||||
factory = CreateTypeWrapperFactory();
|
||||
}
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
protected virtual TypeWrapperFactory CreateTypeWrapperFactory()
|
||||
{
|
||||
#if COMPACT_FRAMEWORK
|
||||
throw new NoClassDefFoundError("Class loading is not supported on the Compact Framework");
|
||||
#elif STATIC_COMPILER
|
||||
throw new InvalidOperationException();
|
||||
if(factory == null)
|
||||
{
|
||||
factory = new DynamicClassLoader(((CompilerClassLoader)this).CreateModuleBuilder());
|
||||
}
|
||||
return factory;
|
||||
#else
|
||||
return DynamicClassLoader.Instance;
|
||||
#endif
|
||||
|
@ -340,7 +332,7 @@ namespace IKVM.Internal
|
|||
{
|
||||
return type;
|
||||
}
|
||||
if(defineInProgress && factory != null)
|
||||
if(defineInProgress)
|
||||
{
|
||||
// DefineClass synchronizes on factory, so if we can obtain that
|
||||
// lock it either means that the DefineClass has finished or
|
||||
|
@ -348,7 +340,7 @@ namespace IKVM.Internal
|
|||
// the two, we check the types hashtable again and if it still
|
||||
// contains the null entry we're on the same thread and should throw
|
||||
// the ClassCircularityError.
|
||||
lock(factory)
|
||||
lock(GetTypeWrapperFactory())
|
||||
{
|
||||
lock(types.SyncRoot)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace IKVM.Internal
|
|||
NoJNI = 8,
|
||||
}
|
||||
|
||||
class DynamicClassLoader : TypeWrapperFactory
|
||||
sealed class DynamicClassLoader : TypeWrapperFactory
|
||||
{
|
||||
#if !WHIDBEY
|
||||
internal static bool arrayConstructionHack;
|
||||
|
@ -63,7 +63,7 @@ namespace IKVM.Internal
|
|||
#endif // !STATIC_COMPILER
|
||||
}
|
||||
|
||||
protected DynamicClassLoader(ModuleBuilder moduleBuilder)
|
||||
internal DynamicClassLoader(ModuleBuilder moduleBuilder)
|
||||
{
|
||||
this.moduleBuilder = moduleBuilder;
|
||||
|
||||
|
@ -168,7 +168,12 @@ namespace IKVM.Internal
|
|||
|
||||
internal sealed override TypeWrapper DefineClassImpl(Hashtable types, ClassFile f, ClassLoaderWrapper classLoader, object protectionDomain)
|
||||
{
|
||||
DynamicTypeWrapper type = CreateDynamicTypeWrapper(f, classLoader);
|
||||
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);
|
||||
|
@ -202,11 +207,6 @@ namespace IKVM.Internal
|
|||
return type;
|
||||
}
|
||||
|
||||
protected virtual DynamicTypeWrapper CreateDynamicTypeWrapper(ClassFile f, ClassLoaderWrapper classLoader)
|
||||
{
|
||||
return new DynamicTypeWrapper(f, classLoader);
|
||||
}
|
||||
|
||||
internal void FinishAll()
|
||||
{
|
||||
Hashtable done = new Hashtable();
|
||||
|
|
|
@ -1574,7 +1574,7 @@ namespace IKVM.Internal
|
|||
{
|
||||
get
|
||||
{
|
||||
Debug.Assert(!IsUnloadable && !IsVerifierType && !JVM.IsStaticCompiler);
|
||||
Debug.Assert(!IsUnloadable && !IsVerifierType);
|
||||
lock(this)
|
||||
{
|
||||
if(classObject == null)
|
||||
|
@ -3079,7 +3079,11 @@ namespace IKVM.Internal
|
|||
}
|
||||
}
|
||||
|
||||
#if STATIC_COMPILER
|
||||
abstract class DynamicTypeWrapper : TypeWrapper
|
||||
#else
|
||||
class DynamicTypeWrapper : TypeWrapper
|
||||
#endif
|
||||
{
|
||||
protected readonly ClassLoaderWrapper classLoader;
|
||||
private volatile DynamicImpl impl;
|
||||
|
@ -3377,11 +3381,16 @@ namespace IKVM.Internal
|
|||
{
|
||||
fields[i] = new ConstantFieldWrapper(wrapper, null, fld.Name, fld.Signature, fld.Modifiers, null, fld.ConstantValue, MemberFlags.LiteralField);
|
||||
}
|
||||
else if(fld.IsFinal && (JVM.IsStaticCompiler && (fld.IsPublic || fld.IsProtected))
|
||||
&& !wrapper.IsInterface && (!wrapper.classLoader.StrictFinalFieldSemantics || ReferenceEquals(wrapper.Name, StringConstants.JAVA_LANG_SYSTEM)))
|
||||
#if STATIC_COMPILER
|
||||
else if(fld.IsFinal
|
||||
&& (fld.IsPublic || fld.IsProtected)
|
||||
&& wrapper.IsPublic
|
||||
&& !wrapper.IsInterface
|
||||
&& (!wrapper.classLoader.StrictFinalFieldSemantics || ReferenceEquals(wrapper.Name, StringConstants.JAVA_LANG_SYSTEM)))
|
||||
{
|
||||
fields[i] = new GetterFieldWrapper(wrapper, null, null, fld.Name, fld.Signature, new ExModifiers(fld.Modifiers, fld.IsInternal), null, null);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
fields[i] = FieldWrapper.Create(wrapper, null, null, fld.Name, fld.Signature, new ExModifiers(fld.Modifiers, fld.IsInternal));
|
||||
|
@ -3525,10 +3534,19 @@ namespace IKVM.Internal
|
|||
typeBuilder = outer.DefineNestedType(GetInnerClassName(outerClassWrapper.Name, f.Name), typeAttribs);
|
||||
}
|
||||
else
|
||||
#endif // STATIC_COMPILER
|
||||
{
|
||||
typeBuilder = wrapper.DefineType(mangledTypeName, typeAttribs);
|
||||
if(wrapper.IsGhost)
|
||||
{
|
||||
typeBuilder = wrapper.DefineGhostType(mangledTypeName, typeAttribs);
|
||||
}
|
||||
else
|
||||
{
|
||||
typeBuilder = wrapper.classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs);
|
||||
}
|
||||
}
|
||||
#else // STATIC_COMPILER
|
||||
typeBuilder = wrapper.classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs);
|
||||
#endif // STATIC_COMPILER
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4320,7 +4338,9 @@ namespace IKVM.Internal
|
|||
}
|
||||
innerClassesTypeWrappers = (TypeWrapper[])wrappers.ToArray(typeof(TypeWrapper));
|
||||
}
|
||||
#if STATIC_COMPILER
|
||||
wrapper.FinishGhost(typeBuilder, methods);
|
||||
#endif // STATIC_COMPILER
|
||||
// if we're not abstract make sure we don't inherit any abstract methods
|
||||
if(!wrapper.IsAbstract)
|
||||
{
|
||||
|
@ -4412,11 +4432,13 @@ namespace IKVM.Internal
|
|||
{
|
||||
ILGenerator ilGenerator = ((MethodBuilder)mb).GetILGenerator();
|
||||
TraceHelper.EmitMethodTrace(ilGenerator, classFile.Name + "." + m.Name + m.Signature);
|
||||
#if STATIC_COMPILER
|
||||
// do we have a native implementation in map.xml?
|
||||
if(wrapper.EmitMapXmlMethodBody(ilGenerator, classFile, m))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
// see if there exists a IKVM.NativeCode class for this type
|
||||
Type nativeCodeType = null;
|
||||
#if STATIC_COMPILER
|
||||
|
@ -4503,10 +4525,12 @@ namespace IKVM.Internal
|
|||
MethodBuilder mbld = (MethodBuilder)mb;
|
||||
ILGenerator ilGenerator = mbld.GetILGenerator();
|
||||
TraceHelper.EmitMethodTrace(ilGenerator, classFile.Name + "." + m.Name + m.Signature);
|
||||
#if STATIC_COMPILER
|
||||
if(wrapper.EmitMapXmlMethodBody(ilGenerator, classFile, m))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif // STATIC_COMPILER
|
||||
LineNumberTableAttribute.LineNumberWriter lineNumberTable = null;
|
||||
bool nonleaf = false;
|
||||
Compiler.Compile(wrapper, methods[i], classFile, m, ilGenerator, ref nonleaf, invokespecialstubcache, ref lineNumberTable);
|
||||
|
@ -4790,7 +4814,9 @@ namespace IKVM.Internal
|
|||
Profiler.Leave("TypeBuilder.CreateType");
|
||||
}
|
||||
ClassLoaderWrapper.SetWrapperForType(type, wrapper);
|
||||
#if STATIC_COMPILER
|
||||
wrapper.FinishGhostStep2();
|
||||
#endif
|
||||
BakedTypeCleanupHack.Process(wrapper);
|
||||
finishedType = new FinishedTypeImpl(type, innerClassesTypeWrappers, declaringTypeWrapper, this.ReflectiveModifiers, Metadata.Create(classFile));
|
||||
return finishedType;
|
||||
|
@ -5831,7 +5857,10 @@ namespace IKVM.Internal
|
|||
}
|
||||
}
|
||||
}
|
||||
MethodBuilder mb = wrapper.DefineGhostMethod(name, attribs, methods[index]);
|
||||
MethodBuilder mb = null;
|
||||
#if STATIC_COMPILER
|
||||
mb = wrapper.DefineGhostMethod(name, attribs, methods[index]);
|
||||
#endif
|
||||
if(mb == null)
|
||||
{
|
||||
bool needFinalize = false;
|
||||
|
@ -6671,18 +6700,23 @@ namespace IKVM.Internal
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void AddParameterNames(ClassFile classFile, ClassFile.Method m, MethodBase method)
|
||||
#if STATIC_COMPILER
|
||||
protected abstract void AddParameterNames(ClassFile classFile, ClassFile.Method m, MethodBase method);
|
||||
protected abstract bool EmitMapXmlMethodBody(ILGenerator ilgen, ClassFile f, ClassFile.Method m);
|
||||
protected abstract void EmitMapXmlMetadata(TypeBuilder typeBuilder, ClassFile classFile, FieldWrapper[] fields, MethodWrapper[] methods);
|
||||
protected abstract MethodBuilder DefineGhostMethod(string name, MethodAttributes attribs, MethodWrapper mw);
|
||||
protected abstract void FinishGhost(TypeBuilder typeBuilder, MethodWrapper[] methods);
|
||||
protected abstract void FinishGhostStep2();
|
||||
protected abstract TypeBuilder DefineGhostType(string mangledTypeName, TypeAttributes typeAttribs);
|
||||
#else
|
||||
private void AddParameterNames(ClassFile classFile, ClassFile.Method m, MethodBase method)
|
||||
{
|
||||
if((JVM.IsStaticCompiler && classFile.IsPublic && (m.IsPublic || m.IsProtected)) || GetClassLoader().EmitDebugInfo)
|
||||
if(GetClassLoader().EmitDebugInfo)
|
||||
{
|
||||
AddParameterNames(method, m, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool EmitMapXmlMethodBody(ILGenerator ilgen, ClassFile f, ClassFile.Method m)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // STATIC_COMPILER
|
||||
|
||||
protected virtual bool IsPInvokeMethod(ClassFile.Method m)
|
||||
{
|
||||
|
@ -6699,28 +6733,6 @@ namespace IKVM.Internal
|
|||
return false;
|
||||
}
|
||||
|
||||
protected virtual void EmitMapXmlMetadata(TypeBuilder typeBuilder, ClassFile classFile, FieldWrapper[] fields, MethodWrapper[] methods)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual MethodBuilder DefineGhostMethod(string name, MethodAttributes attribs, MethodWrapper mw)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual void FinishGhost(TypeBuilder typeBuilder, MethodWrapper[] methods)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void FinishGhostStep2()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual TypeBuilder DefineType(string mangledTypeName, TypeAttributes typeAttribs)
|
||||
{
|
||||
return classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(mangledTypeName, typeAttribs);
|
||||
}
|
||||
|
||||
internal override MethodBase LinkMethod(MethodWrapper mw)
|
||||
{
|
||||
mw.AssertLinked();
|
||||
|
|
|
@ -1331,26 +1331,33 @@ namespace IKVM.NativeCode.gnu.java.net.protocol.ikvmres
|
|||
{
|
||||
public static Stream ReadResourceFromAssemblyImpl(Assembly asm, string resource)
|
||||
{
|
||||
// chop off the leading slash
|
||||
resource = resource.Substring(1);
|
||||
#if WHIDBEY
|
||||
Stream s = asm.GetManifestResourceStream(JVM.MangleResourceName(resource.Substring(1)));
|
||||
Stream s = asm.GetManifestResourceStream(JVM.MangleResourceName(resource));
|
||||
if(s == null)
|
||||
{
|
||||
Tracer.Warning(Tracer.ClassLoading, "Resource \"{0}\" not found in {1}", resource, asm.FullName);
|
||||
throw new FileNotFoundException("resource " + resource + " not found in assembly " + asm.FullName);
|
||||
}
|
||||
switch (s.ReadByte())
|
||||
{
|
||||
case 0:
|
||||
Tracer.Info(Tracer.ClassLoading, "Reading resource \"{0}\" from {1}", resource, asm.FullName);
|
||||
return s;
|
||||
case 1:
|
||||
Tracer.Info(Tracer.ClassLoading, "Reading compressed resource \"{0}\" from {1}", resource, asm.FullName);
|
||||
return new System.IO.Compression.DeflateStream(s, System.IO.Compression.CompressionMode.Decompress, false);
|
||||
default:
|
||||
Tracer.Error(Tracer.ClassLoading, "Resource \"{0}\" in {1} has an unsupported encoding", resource, asm.FullName);
|
||||
throw new IOException("Unsupported resource encoding for resource " + resource + " found in assembly " + asm.FullName);
|
||||
}
|
||||
#else
|
||||
using(Stream s = asm.GetManifestResourceStream(JVM.MangleResourceName(resource.Substring(1))))
|
||||
using(Stream s = asm.GetManifestResourceStream(JVM.MangleResourceName(resource)))
|
||||
{
|
||||
if(s == null)
|
||||
{
|
||||
Tracer.Warning(Tracer.ClassLoading, "Resource \"{0}\" not found in {1}", resource, asm.FullName);
|
||||
throw new FileNotFoundException("resource " + resource + " not found in assembly " + asm.FullName);
|
||||
}
|
||||
using(System.Resources.ResourceReader r = new System.Resources.ResourceReader(s))
|
||||
|
@ -1359,17 +1366,21 @@ namespace IKVM.NativeCode.gnu.java.net.protocol.ikvmres
|
|||
{
|
||||
if((string)de.Key == "lz")
|
||||
{
|
||||
Tracer.Info(Tracer.ClassLoading, "Reading compressed resource \"{0}\" from {1}", resource, asm.FullName);
|
||||
return new LZInputStream(new MemoryStream((byte[])de.Value));
|
||||
}
|
||||
else if((string)de.Key == "ikvm")
|
||||
{
|
||||
Tracer.Info(Tracer.ClassLoading, "Reading resource \"{0}\" from {1}", resource, asm.FullName);
|
||||
return new MemoryStream((byte[])de.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracer.Error(Tracer.ClassLoading, "Resource \"{0}\" in {1} has an unsupported encoding", resource, asm.FullName);
|
||||
throw new IOException("Unsupported resource encoding " + de.Key + " for resource " + resource + " found in assembly " + asm.FullName);
|
||||
}
|
||||
}
|
||||
Tracer.Error(Tracer.ClassLoading, "Resource \"{0}\" in {1} is invalid", resource, asm.FullName);
|
||||
throw new IOException("Invalid resource " + resource + " found in assembly " + asm.FullName);
|
||||
}
|
||||
}
|
||||
|
@ -1531,34 +1542,36 @@ namespace IKVM.NativeCode.ikvm.@internal
|
|||
try
|
||||
{
|
||||
ClassLoaderWrapper wrapper = classLoader == null ? ClassLoaderWrapper.GetBootstrapClassLoader() : (ClassLoaderWrapper)JVM.Library.getWrapperFromClassLoader(classLoader);
|
||||
return wrapper.LoadClassByDottedName(name).ClassObject;
|
||||
TypeWrapper tw = wrapper.LoadClassByDottedName(name);
|
||||
Tracer.Info(Tracer.ClassLoading, "Loaded class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
|
||||
return tw.ClassObject;
|
||||
}
|
||||
catch(RetargetableJavaException x)
|
||||
{
|
||||
Tracer.Info(Tracer.ClassLoading, "Failed to load class \"{0}\" from {1}", name, classLoader == null ? "boot class loader" : classLoader);
|
||||
throw x.ToJava();
|
||||
}
|
||||
}
|
||||
|
||||
public static Assembly FindResourceAssembly(object classLoader, string name)
|
||||
{
|
||||
// TODO consider supporting delegation
|
||||
IKVM.Internal.AssemblyClassLoader wrapper = classLoader == null ? ClassLoaderWrapper.GetBootstrapClassLoader() : (JVM.Library.getWrapperFromClassLoader(classLoader) as IKVM.Internal.AssemblyClassLoader);
|
||||
if(wrapper == null)
|
||||
{
|
||||
// must be a GenericClassLoader
|
||||
return null;
|
||||
}
|
||||
name = JVM.MangleResourceName(name);
|
||||
if(wrapper.Assembly.GetManifestResourceInfo(name) != null)
|
||||
if(wrapper.Assembly.GetManifestResourceInfo(JVM.MangleResourceName(name)) != null)
|
||||
{
|
||||
Tracer.Info(Tracer.ClassLoading, "Found resource \"{0}\" in {1}", name, wrapper.Assembly.FullName);
|
||||
return wrapper.Assembly;
|
||||
}
|
||||
Tracer.Info(Tracer.ClassLoading, "Failed to find resource \"{0}\" in {1}", name, wrapper.Assembly.FullName);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Assembly[] FindResourceAssemblies(object classLoader, string name)
|
||||
{
|
||||
// TODO consider supporting delegation
|
||||
Assembly asm = FindResourceAssembly(classLoader, name);
|
||||
if(asm != null)
|
||||
{
|
||||
|
|
|
@ -26,12 +26,6 @@ using System.Threading;
|
|||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
#if !COMPACT_FRAMEWORK
|
||||
using System.Reflection.Emit;
|
||||
using ILGenerator = IKVM.Internal.CountingILGenerator;
|
||||
using Label = IKVM.Internal.CountingLabel;
|
||||
#endif
|
||||
using System.Configuration;
|
||||
|
||||
namespace IKVM.Internal
|
||||
|
|
Загрузка…
Ссылка в новой задаче