diff --git a/runtime/CoreClasses.cs b/runtime/CoreClasses.cs index d8cefb0a..a6f8e1ff 100644 --- a/runtime/CoreClasses.cs +++ b/runtime/CoreClasses.cs @@ -42,6 +42,17 @@ namespace IKVM.Internal internal static class java { + internal static class io + { + internal static class Serializable + { + // NOTE we have a dummy static initializer, to make sure we don't get the beforeFieldInit attribute + // (we don't want the classes to be loaded prematurely, because they might not be available then) + static Serializable() { } + internal static readonly TypeWrapper Wrapper = ClassLoaderWrapper.LoadClassCritical("java.io.Serializable"); + } + } + internal static class lang { internal static class Object @@ -68,6 +79,14 @@ namespace IKVM.Internal internal static readonly TypeWrapper Wrapper = ClassLoaderWrapper.LoadClassCritical("java.lang.Class"); } + internal static class Cloneable + { + // NOTE we have a dummy static initializer, to make sure we don't get the beforeFieldInit attribute + // (we don't want the classes to be loaded prematurely, because they might not be available then) + static Cloneable() {} + internal static readonly TypeWrapper Wrapper = ClassLoaderWrapper.LoadClassCritical("java.lang.Cloneable"); + } + internal static class Throwable { // NOTE we have a dummy static initializer, to make sure we don't get the beforeFieldInit attribute diff --git a/runtime/DotNetTypeWrapper.cs b/runtime/DotNetTypeWrapper.cs index 2ccd6887..f2e3fb9f 100644 --- a/runtime/DotNetTypeWrapper.cs +++ b/runtime/DotNetTypeWrapper.cs @@ -2006,7 +2006,7 @@ namespace IKVM.Internal internal override void EmitCall(CodeEmitter ilgen) { ilgen.Emit(OpCodes.Dup); - ilgen.Emit(OpCodes.Isinst, ClassLoaderWrapper.LoadClassCritical("java.lang.Cloneable").TypeAsBaseType); + ilgen.Emit(OpCodes.Isinst, CoreClasses.java.lang.Cloneable.Wrapper.TypeAsBaseType); CodeEmitterLabel label1 = ilgen.DefineLabel(); ilgen.EmitBrtrue(label1); CodeEmitterLabel label2 = ilgen.DefineLabel(); diff --git a/runtime/DynamicTypeWrapper.cs b/runtime/DynamicTypeWrapper.cs index e70dc778..8e525b96 100644 --- a/runtime/DynamicTypeWrapper.cs +++ b/runtime/DynamicTypeWrapper.cs @@ -412,7 +412,7 @@ namespace IKVM.Internal { get { - return this.IsSubTypeOf(ClassLoaderWrapper.LoadClassCritical("java.io.Serializable")); + return this.IsSubTypeOf(CoreClasses.java.io.Serializable.Wrapper); } } @@ -4814,7 +4814,7 @@ namespace IKVM.Internal // are public and so we can get away with replacing all other types with object. argTypes[i + instance] = (args[i].IsPrimitive || args[i].IsGhost || args[i].IsNonPrimitiveValueType) ? args[i].TypeAsSignatureType : typeof(object); } - argTypes[argTypes.Length - 1] = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.CallerID").TypeAsSignatureType; + argTypes[argTypes.Length - 1] = CoreClasses.ikvm.@internal.CallerID.Wrapper.TypeAsSignatureType; Type retType = (mw.ReturnType.IsPrimitive || mw.ReturnType.IsGhost || mw.ReturnType.IsNonPrimitiveValueType) ? mw.ReturnType.TypeAsSignatureType : typeof(object); MethodBuilder mb = tb.DefineMethod("method", MethodAttributes.Public | MethodAttributes.Static, retType, argTypes); AttributeHelper.HideFromJava(mb); diff --git a/runtime/Serialization.cs b/runtime/Serialization.cs index 4fff1663..1145d351 100644 --- a/runtime/Serialization.cs +++ b/runtime/Serialization.cs @@ -43,7 +43,6 @@ namespace IKVM.Internal private static readonly CustomAttributeBuilder securityCriticalAttribute = new CustomAttributeBuilder(JVM.Import(typeof(SecurityCriticalAttribute)).GetConstructor(Type.EmptyTypes), new object[0]); private static readonly TypeWrapper iserializable = ClassLoaderWrapper.GetWrapperFromType(JVM.Import(typeof(ISerializable))); private static readonly TypeWrapper iobjectreference = ClassLoaderWrapper.GetWrapperFromType(JVM.Import(typeof(IObjectReference))); - private static readonly TypeWrapper serializable = ClassLoaderWrapper.LoadClassCritical("java.io.Serializable"); private static readonly TypeWrapper externalizable = ClassLoaderWrapper.LoadClassCritical("java.io.Externalizable"); private static readonly PermissionSet psetSerializationFormatter; @@ -85,7 +84,7 @@ namespace IKVM.Internal { MarkSerializable(typeBuilder); } - else if (wrapper.IsSubTypeOf(serializable) && IsSafeForAutomagicSerialization(wrapper)) + else if (wrapper.IsSubTypeOf(CoreClasses.java.io.Serializable.Wrapper) && IsSafeForAutomagicSerialization(wrapper)) { if (wrapper.IsSubTypeOf(externalizable)) { @@ -95,7 +94,7 @@ namespace IKVM.Internal MarkSerializable(typeBuilder); ctor.Link(); serializationCtor = AddConstructor(typeBuilder, ctor, null, true); - if (!wrapper.BaseTypeWrapper.IsSubTypeOf(serializable)) + if (!wrapper.BaseTypeWrapper.IsSubTypeOf(CoreClasses.java.io.Serializable.Wrapper)) { AddGetObjectData(typeBuilder); } @@ -105,7 +104,7 @@ namespace IKVM.Internal } } } - else if (wrapper.BaseTypeWrapper.IsSubTypeOf(serializable)) + else if (wrapper.BaseTypeWrapper.IsSubTypeOf(CoreClasses.java.io.Serializable.Wrapper)) { MethodBase baseCtor = wrapper.GetBaseSerializationConstructor(); if (baseCtor != null && (baseCtor.IsFamily || baseCtor.IsFamilyOrAssembly)) diff --git a/runtime/TypeWrapper.cs b/runtime/TypeWrapper.cs index 18b55d7d..f41f6986 100644 --- a/runtime/TypeWrapper.cs +++ b/runtime/TypeWrapper.cs @@ -4809,8 +4809,8 @@ namespace IKVM.Internal if(interfaces == null) { TypeWrapper[] tw = new TypeWrapper[2]; - tw[0] = ClassLoaderWrapper.LoadClassCritical("java.lang.Cloneable"); - tw[1] = ClassLoaderWrapper.LoadClassCritical("java.io.Serializable"); + tw[0] = CoreClasses.java.lang.Cloneable.Wrapper; + tw[1] = CoreClasses.java.io.Serializable.Wrapper; interfaces = tw; } return interfaces;