This commit is contained in:
jfrijters 2005-09-01 07:34:53 +00:00
Родитель 86c1c21beb
Коммит 7e46ac06b0
4 изменённых файлов: 91 добавлений и 39 удалений

Просмотреть файл

@ -474,6 +474,8 @@ namespace IKVM.Runtime
delegate IntPtr pf_IntPtr_pbyte_IntPtr_psbyte_IntPtr(JNIEnv* pEnv, byte* p1, IntPtr p2, sbyte* p3, int p4); delegate IntPtr pf_IntPtr_pbyte_IntPtr_psbyte_IntPtr(JNIEnv* pEnv, byte* p1, IntPtr p2, sbyte* p3, int p4);
delegate IntPtr pf_IntPtr_IntPtr_IntPtr(JNIEnv* pEnv, IntPtr p1, IntPtr p2); delegate IntPtr pf_IntPtr_IntPtr_IntPtr(JNIEnv* pEnv, IntPtr p1, IntPtr p2);
delegate jchar* pf_pjchar_IntPtr_pjboolean(JNIEnv* pEnv, IntPtr p1, jboolean* p2); delegate jchar* pf_pjchar_IntPtr_pjboolean(JNIEnv* pEnv, IntPtr p1, jboolean* p2);
delegate void pf_void_IntPtr_pvoid_int(JNIEnv* pEnv, IntPtr p1, void* p2, int p3);
delegate void* pf_pvoid_IntPtr_pjboolean(JNIEnv* pEnv, IntPtr p1, jboolean* p2);
delegate int pf_int_IntPtr_pbyte(JNIEnv* pEnv, IntPtr p1, byte* p2); delegate int pf_int_IntPtr_pbyte(JNIEnv* pEnv, IntPtr p1, byte* p2);
delegate void pf_void_pbyte(JNIEnv* pEnv, byte* p1); delegate void pf_void_pbyte(JNIEnv* pEnv, byte* p1);
delegate IntPtr pf_IntPtr_IntPtr_pbyte_pbyte(JNIEnv* pEnv, IntPtr p1, byte* p2, byte* p3); delegate IntPtr pf_IntPtr_IntPtr_pbyte_pbyte(JNIEnv* pEnv, IntPtr p1, byte* p2, byte* p3);
@ -851,11 +853,11 @@ namespace IKVM.Runtime
new pf_void_IntPtr_int_int_IntPtr(JNIEnv.GetStringRegion), //virtual void JNICALL GetStringRegion(jstring str, jsize start, jsize len, jchar *buf); new pf_void_IntPtr_int_int_IntPtr(JNIEnv.GetStringRegion), //virtual void JNICALL GetStringRegion(jstring str, jsize start, jsize len, jchar *buf);
new pf_void_IntPtr_int_int_IntPtr(JNIEnv.GetStringUTFRegion), //virtual void JNICALL GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf); new pf_void_IntPtr_int_int_IntPtr(JNIEnv.GetStringUTFRegion), //virtual void JNICALL GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf);
new pf_IntPtr_IntPtr_IntPtr(JNIEnv.GetPrimitiveArrayCritical), //virtual void* JNICALL GetPrimitiveArrayCritical(jarray array, jboolean *isCopy); new pf_pvoid_IntPtr_pjboolean(JNIEnv.GetPrimitiveArrayCritical), //virtual void* JNICALL GetPrimitiveArrayCritical(jarray array, jboolean *isCopy);
new pf_void_IntPtr_IntPtr_int(JNIEnv.ReleasePrimitiveArrayCritical), //virtual void JNICALL ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode); new pf_void_IntPtr_pvoid_int(JNIEnv.ReleasePrimitiveArrayCritical), //virtual void JNICALL ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode);
new pf_IntPtr_IntPtr_IntPtr(JNIEnv.GetStringCritical), //virtual const jchar* JNICALL GetStringCritical(jstring string, jboolean *isCopy); new pf_pjchar_IntPtr_pjboolean(JNIEnv.GetStringCritical), //virtual const jchar* JNICALL GetStringCritical(jstring string, jboolean *isCopy);
new pf_void_IntPtr_IntPtr(JNIEnv.ReleaseStringCritical), //virtual void JNICALL ReleaseStringCritical(jstring string, const jchar *cstring); new pf_void_IntPtr_pjchar(JNIEnv.ReleaseStringCritical), //virtual void JNICALL ReleaseStringCritical(jstring string, const jchar *cstring);
new pf_IntPtr_IntPtr(JNIEnv.NewWeakGlobalRef), //virtual jweak JNICALL NewWeakGlobalRef(jobject obj); new pf_IntPtr_IntPtr(JNIEnv.NewWeakGlobalRef), //virtual jweak JNICALL NewWeakGlobalRef(jobject obj);
new pf_void_IntPtr(JNIEnv.DeleteWeakGlobalRef), //virtual void JNICALL DeleteWeakGlobalRef(jweak ref); new pf_void_IntPtr(JNIEnv.DeleteWeakGlobalRef), //virtual void JNICALL DeleteWeakGlobalRef(jweak ref);
@ -1035,6 +1037,8 @@ namespace IKVM.Runtime
internal IntPtr pendingException; internal IntPtr pendingException;
internal RuntimeMethodHandle currentMethod; internal RuntimeMethodHandle currentMethod;
internal GCHandle classLoader; internal GCHandle classLoader;
internal GCHandle criticalArrayHandle1;
internal GCHandle criticalArrayHandle2;
private static LocalDataStoreSlot cleanupHelperDataSlot = System.Threading.Thread.AllocateDataSlot(); private static LocalDataStoreSlot cleanupHelperDataSlot = System.Threading.Thread.AllocateDataSlot();
unsafe class JNIEnvCleanupHelper unsafe class JNIEnvCleanupHelper
@ -1064,6 +1068,14 @@ namespace IKVM.Runtime
{ {
pJNIEnv->classLoader.Free(); pJNIEnv->classLoader.Free();
} }
if(pJNIEnv->criticalArrayHandle1.IsAllocated)
{
pJNIEnv->criticalArrayHandle1.Free();
}
if(pJNIEnv->criticalArrayHandle2.IsAllocated)
{
pJNIEnv->criticalArrayHandle2.Free();
}
JniMem.Free((IntPtr)(void*)pJNIEnv); JniMem.Free((IntPtr)(void*)pJNIEnv);
} }
} }
@ -1089,6 +1101,8 @@ namespace IKVM.Runtime
pJNIEnv->pendingException = IntPtr.Zero; pJNIEnv->pendingException = IntPtr.Zero;
pJNIEnv->currentMethod = new RuntimeMethodHandle(); pJNIEnv->currentMethod = new RuntimeMethodHandle();
pJNIEnv->classLoader = GCHandle.Alloc(null); pJNIEnv->classLoader = GCHandle.Alloc(null);
pJNIEnv->criticalArrayHandle1 = GCHandle.Alloc(null, GCHandleType.Pinned);
pJNIEnv->criticalArrayHandle2 = GCHandle.Alloc(null, GCHandleType.Pinned);
return pJNIEnv; return pJNIEnv;
} }
@ -3096,9 +3110,27 @@ namespace IKVM.Runtime
} }
} }
internal static IntPtr GetPrimitiveArrayCritical(JNIEnv* pEnv, IntPtr array, IntPtr isCopy) internal static void* GetPrimitiveArrayCritical(JNIEnv* pEnv, jarray array, jboolean* isCopy)
{ {
Array ar = (Array)pEnv->UnwrapRef(array); Array ar = (Array)pEnv->UnwrapRef(array);
if(pEnv->criticalArrayHandle1.Target == null)
{
pEnv->criticalArrayHandle1.Target = ar;
if(isCopy != null)
{
*isCopy = JNI_FALSE;
}
return (void*)pEnv->criticalArrayHandle1.AddrOfPinnedObject();
}
if(pEnv->criticalArrayHandle2.Target == null)
{
pEnv->criticalArrayHandle2.Target = ar;
if(isCopy != null)
{
*isCopy = JNI_FALSE;
}
return (void*)pEnv->criticalArrayHandle2.AddrOfPinnedObject();
}
// TODO not 64-bit safe (len can overflow) // TODO not 64-bit safe (len can overflow)
int len = ar.Length * GetPrimitiveArrayElementSize(ar); int len = ar.Length * GetPrimitiveArrayElementSize(ar);
GCHandle h = GCHandle.Alloc(ar, GCHandleType.Pinned); GCHandle h = GCHandle.Alloc(ar, GCHandleType.Pinned);
@ -3112,11 +3144,11 @@ namespace IKVM.Runtime
{ {
*pdst++ = *psrc++; *pdst++ = *psrc++;
} }
if(isCopy != IntPtr.Zero) if(isCopy != null)
{ {
*((sbyte*)(void*)isCopy) = JNI_TRUE; *isCopy = JNI_TRUE;
} }
return hglobal; return (void*)hglobal;
} }
finally finally
{ {
@ -3124,11 +3156,29 @@ namespace IKVM.Runtime
} }
} }
internal static void ReleasePrimitiveArrayCritical(JNIEnv* pEnv, IntPtr array, IntPtr carray, int mode) internal static void ReleasePrimitiveArrayCritical(JNIEnv* pEnv, jarray array, void* carray, jint mode)
{ {
Array ar = (Array)pEnv->UnwrapRef(array);
if(pEnv->criticalArrayHandle1.Target == ar
&& (void*)pEnv->criticalArrayHandle1.AddrOfPinnedObject() == carray)
{
if(mode == 0 || mode == JNI_ABORT)
{
pEnv->criticalArrayHandle1.Target = null;
}
return;
}
if(pEnv->criticalArrayHandle2.Target == ar
&& (void*)pEnv->criticalArrayHandle2.AddrOfPinnedObject() == carray)
{
if(mode == 0 || mode == JNI_ABORT)
{
pEnv->criticalArrayHandle2.Target = null;
}
return;
}
if(mode == 0 || mode == JNI_COMMIT) if(mode == 0 || mode == JNI_COMMIT)
{ {
Array ar = (Array)pEnv->UnwrapRef(array);
// TODO not 64-bit safe (len can overflow) // TODO not 64-bit safe (len can overflow)
int len = ar.Length * GetPrimitiveArrayElementSize(ar); int len = ar.Length * GetPrimitiveArrayElementSize(ar);
GCHandle h = GCHandle.Alloc(ar, GCHandleType.Pinned); GCHandle h = GCHandle.Alloc(ar, GCHandleType.Pinned);
@ -3149,28 +3199,28 @@ namespace IKVM.Runtime
} }
if(mode == 0 || mode == JNI_ABORT) if(mode == 0 || mode == JNI_ABORT)
{ {
JniMem.Free(carray); JniMem.Free((IntPtr)carray);
} }
} }
internal static IntPtr GetStringCritical(JNIEnv* pEnv, IntPtr str, IntPtr isCopy) internal static jchar* GetStringCritical(JNIEnv* pEnv, jstring str, jboolean* isCopy)
{ {
string s = (string)pEnv->UnwrapRef(str); string s = (string)pEnv->UnwrapRef(str);
if(s != null) if(s != null)
{ {
if(isCopy != IntPtr.Zero) if(isCopy != null)
{ {
*((sbyte*)(void*)isCopy) = JNI_TRUE; *isCopy = JNI_TRUE;
} }
return Marshal.StringToHGlobalUni(s); return (jchar*)(void*)Marshal.StringToHGlobalUni(s);
} }
SetPendingException(pEnv, JavaException.NullPointerException()); SetPendingException(pEnv, JavaException.NullPointerException());
return IntPtr.Zero; return null;
} }
internal static void ReleaseStringCritical(JNIEnv* pEnv, IntPtr str, IntPtr cstring) internal static void ReleaseStringCritical(JNIEnv* pEnv, jstring str, jchar* cstring)
{ {
Marshal.FreeHGlobal(cstring); Marshal.FreeHGlobal((IntPtr)(void*)cstring);
} }
internal static jweak NewWeakGlobalRef(JNIEnv* pEnv, jobject obj) internal static jweak NewWeakGlobalRef(JNIEnv* pEnv, jobject obj)

Просмотреть файл

@ -474,7 +474,7 @@ namespace IKVM.Internal
// this returns the Java method's attributes in .NET terms (e.g. used to create stubs for this method) // this returns the Java method's attributes in .NET terms (e.g. used to create stubs for this method)
internal MethodAttributes GetMethodAttributes() internal MethodAttributes GetMethodAttributes()
{ {
MethodAttributes attribs = 0; MethodAttributes attribs = MethodAttributes.HideBySig;
if(IsStatic) if(IsStatic)
{ {
attribs |= MethodAttributes.Static; attribs |= MethodAttributes.Static;
@ -1552,6 +1552,7 @@ namespace IKVM.Internal
PropertyBuilder pb = typeBuilder.DefineProperty(Name, PropertyAttributes.None, basefield.FieldTypeWrapper.TypeAsSignatureType, Type.EmptyTypes); PropertyBuilder pb = typeBuilder.DefineProperty(Name, PropertyAttributes.None, basefield.FieldTypeWrapper.TypeAsSignatureType, Type.EmptyTypes);
AttributeHelper.HideFromReflection(pb); AttributeHelper.HideFromReflection(pb);
MethodAttributes attribs = basefield.IsPublic ? MethodAttributes.Public : MethodAttributes.FamORAssem; MethodAttributes attribs = basefield.IsPublic ? MethodAttributes.Public : MethodAttributes.FamORAssem;
attribs |= MethodAttributes.HideBySig;
if(basefield.IsStatic) if(basefield.IsStatic)
{ {
attribs |= MethodAttributes.Static; attribs |= MethodAttributes.Static;

Просмотреть файл

@ -1563,7 +1563,7 @@ namespace IKVM.Internal
} }
if(error) if(error)
{ {
MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod());
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
EmitHelper.Throw(mb.GetILGenerator(), "java.lang.LinkageError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature); EmitHelper.Throw(mb.GetILGenerator(), "java.lang.LinkageError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature);
typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod()); typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod());
@ -1580,7 +1580,7 @@ namespace IKVM.Internal
// it makes sense, so I hope the spec is wrong // it makes sense, so I hope the spec is wrong
// UPDATE unfortunately, according to Serge Lidin the spec is correct, and it is not allowed to have virtual privatescope // UPDATE unfortunately, according to Serge Lidin the spec is correct, and it is not allowed to have virtual privatescope
// methods. Sigh! So I have to use private methods and mangle the name // methods. Sigh! So I have to use private methods and mangle the name
MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod());
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
EmitHelper.Throw(mb.GetILGenerator(), "java.lang.IllegalAccessError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature); EmitHelper.Throw(mb.GetILGenerator(), "java.lang.IllegalAccessError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature);
typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod()); typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod());
@ -1588,7 +1588,7 @@ namespace IKVM.Internal
} }
else if(mce.GetMethod() == null || mce.RealName != ifmethod.RealName) else if(mce.GetMethod() == null || mce.RealName != ifmethod.RealName)
{ {
MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod());
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
ILGenerator ilGenerator = mb.GetILGenerator(); ILGenerator ilGenerator = mb.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_0);
@ -1606,7 +1606,7 @@ namespace IKVM.Internal
// NOTE methods inherited from base classes in a different assembly do *not* automatically implement // NOTE methods inherited from base classes in a different assembly do *not* automatically implement
// interface methods, so we have to generate a stub here that doesn't do anything but call the base // interface methods, so we have to generate a stub here that doesn't do anything but call the base
// implementation // implementation
MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod());
typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod()); typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod());
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
ILGenerator ilGenerator = mb.GetILGenerator(); ILGenerator ilGenerator = mb.GetILGenerator();
@ -1626,7 +1626,7 @@ namespace IKVM.Internal
{ {
// the type doesn't implement the interface method and isn't abstract either. The JVM allows this, but the CLR doesn't, // the type doesn't implement the interface method and isn't abstract either. The JVM allows this, but the CLR doesn't,
// so we have to create a stub method that throws an AbstractMethodError // so we have to create a stub method that throws an AbstractMethodError
MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(mangledName, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final, ifmethod.ReturnTypeForDefineMethod, ifmethod.GetParametersForDefineMethod());
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
EmitHelper.Throw(mb.GetILGenerator(), "java.lang.AbstractMethodError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature); EmitHelper.Throw(mb.GetILGenerator(), "java.lang.AbstractMethodError", wrapper.Name + "." + ifmethod.Name + ifmethod.Signature);
typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod()); typeBuilder.DefineMethodOverride(mb, (MethodInfo)ifmethod.GetMethod());
@ -3046,7 +3046,7 @@ namespace IKVM.Internal
fieldName += "/" + typeWrapper.Name; fieldName += "/" + typeWrapper.Name;
} }
FieldAttributes attribs = 0; FieldAttributes attribs = 0;
MethodAttributes methodAttribs = 0; MethodAttributes methodAttribs = MethodAttributes.HideBySig;
bool setModifiers = false; bool setModifiers = false;
if(fld.IsPrivate) if(fld.IsPrivate)
{ {
@ -3460,7 +3460,7 @@ namespace IKVM.Internal
// TODO do this for indirectly implemented interfaces (interfaces implemented by interfaces) as well // TODO do this for indirectly implemented interfaces (interfaces implemented by interfaces) as well
if(JVM.IsStaticCompiler && interfaces[i].IsGhost && wrapper.IsPublic) if(JVM.IsStaticCompiler && interfaces[i].IsGhost && wrapper.IsPublic)
{ {
MethodBuilder mb = typeBuilder.DefineMethod("op_Implicit", MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName, interfaces[i].TypeAsSignatureType, new Type[] { wrapper.TypeAsSignatureType }); MethodBuilder mb = typeBuilder.DefineMethod("op_Implicit", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName, interfaces[i].TypeAsSignatureType, new Type[] { wrapper.TypeAsSignatureType });
ILGenerator ilgen = mb.GetILGenerator(); ILGenerator ilgen = mb.GetILGenerator();
LocalBuilder local = ilgen.DeclareLocal(interfaces[i].TypeAsSignatureType); LocalBuilder local = ilgen.DeclareLocal(interfaces[i].TypeAsSignatureType);
ilgen.Emit(OpCodes.Ldloca, local); ilgen.Emit(OpCodes.Ldloca, local);
@ -4009,7 +4009,7 @@ namespace IKVM.Internal
// We're a Miranda method // We're a Miranda method
Debug.Assert(baseMethods[index].DeclaringType.IsInterface); Debug.Assert(baseMethods[index].DeclaringType.IsInterface);
string name = GenerateUniqueMethodName(methods[index].Name, baseMethods[index]); string name = GenerateUniqueMethodName(methods[index].Name, baseMethods[index]);
MethodBuilder mb = typeBuilder.DefineMethod(methods[index].Name, MethodAttributes.NewSlot | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract | MethodAttributes.CheckAccessOnOverride, methods[index].ReturnTypeForDefineMethod, methods[index].GetParametersForDefineMethod()); MethodBuilder mb = typeBuilder.DefineMethod(methods[index].Name, MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Abstract | MethodAttributes.CheckAccessOnOverride, methods[index].ReturnTypeForDefineMethod, methods[index].GetParametersForDefineMethod());
AttributeHelper.HideFromReflection(mb); AttributeHelper.HideFromReflection(mb);
if(unloadableOverrideStub || name != methods[index].Name) if(unloadableOverrideStub || name != methods[index].Name)
{ {
@ -4027,6 +4027,7 @@ namespace IKVM.Internal
else if(methods[index].IsAccessStub) else if(methods[index].IsAccessStub)
{ {
MethodAttributes stubattribs = baseMethods[index].IsPublic ? MethodAttributes.Public : MethodAttributes.FamORAssem; MethodAttributes stubattribs = baseMethods[index].IsPublic ? MethodAttributes.Public : MethodAttributes.FamORAssem;
stubattribs |= MethodAttributes.HideBySig;
if(baseMethods[index].IsStatic) if(baseMethods[index].IsStatic)
{ {
stubattribs |= MethodAttributes.Static; stubattribs |= MethodAttributes.Static;
@ -4073,7 +4074,7 @@ namespace IKVM.Internal
setNameSig |= tw.IsUnloadable || tw.IsGhostArray; setNameSig |= tw.IsUnloadable || tw.IsGhostArray;
} }
bool setModifiers = false; bool setModifiers = false;
MethodAttributes attribs = 0; MethodAttributes attribs = MethodAttributes.HideBySig;
if(m.IsNative) if(m.IsNative)
{ {
if(wrapper.IsPInvokeMethod(m)) if(wrapper.IsPInvokeMethod(m))
@ -4278,7 +4279,7 @@ namespace IKVM.Internal
if(needFinalize) if(needFinalize)
{ {
MethodInfo baseFinalize = typeBuilder.BaseType.GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null); MethodInfo baseFinalize = typeBuilder.BaseType.GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null);
MethodAttributes attr = MethodAttributes.Virtual; MethodAttributes attr = MethodAttributes.HideBySig | MethodAttributes.Virtual;
// make sure we don't reduce accessibility // make sure we don't reduce accessibility
attr |= baseFinalize.IsPublic ? MethodAttributes.Public : MethodAttributes.Family; attr |= baseFinalize.IsPublic ? MethodAttributes.Public : MethodAttributes.Family;
if(m.IsFinal) if(m.IsFinal)
@ -5077,7 +5078,7 @@ namespace IKVM.Internal
private static MethodAttributes GetPropertyMethodAttributes(MethodWrapper mw, bool final) private static MethodAttributes GetPropertyMethodAttributes(MethodWrapper mw, bool final)
{ {
MethodAttributes attribs = (MethodAttributes)0; MethodAttributes attribs = MethodAttributes.HideBySig;
if(mw.IsStatic) if(mw.IsStatic)
{ {
attribs |= MethodAttributes.Static; attribs |= MethodAttributes.Static;
@ -5503,7 +5504,7 @@ namespace IKVM.Internal
TypeWrapper[] implementers = GetGhostImplementers(this); TypeWrapper[] implementers = GetGhostImplementers(this);
for(int i = 0; i < implementers.Length; i++) for(int i = 0; i < implementers.Length; i++)
{ {
mb = typeBuilder.DefineMethod("op_Implicit", MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName, TypeAsSignatureType, new Type[] { implementers[i].TypeAsSignatureType }); mb = typeBuilder.DefineMethod("op_Implicit", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName, TypeAsSignatureType, new Type[] { implementers[i].TypeAsSignatureType });
ilgen = mb.GetILGenerator(); ilgen = mb.GetILGenerator();
local = ilgen.DeclareLocal(TypeAsSignatureType); local = ilgen.DeclareLocal(TypeAsSignatureType);
ilgen.Emit(OpCodes.Ldloca, local); ilgen.Emit(OpCodes.Ldloca, local);
@ -5610,7 +5611,7 @@ namespace IKVM.Internal
ilgen.Emit(OpCodes.Ldobj, TypeAsSignatureType); ilgen.Emit(OpCodes.Ldobj, TypeAsSignatureType);
ilgen.Emit(OpCodes.Ret); ilgen.Emit(OpCodes.Ret);
// Add "ToObject" methods // Add "ToObject" methods
mb = typeBuilder.DefineMethod("ToObject", MethodAttributes.Public, typeof(object), Type.EmptyTypes); mb = typeBuilder.DefineMethod("ToObject", MethodAttributes.HideBySig | MethodAttributes.Public, typeof(object), Type.EmptyTypes);
AttributeHelper.HideFromJava(mb); AttributeHelper.HideFromJava(mb);
ilgen = mb.GetILGenerator(); ilgen = mb.GetILGenerator();
ilgen.Emit(OpCodes.Ldarg_0); ilgen.Emit(OpCodes.Ldarg_0);
@ -5658,14 +5659,14 @@ namespace IKVM.Internal
ghostRefField = typeBuilder.DefineField("__<ref>", typeof(object), FieldAttributes.Public | FieldAttributes.SpecialName); ghostRefField = typeBuilder.DefineField("__<ref>", typeof(object), FieldAttributes.Public | FieldAttributes.SpecialName);
typeBuilderGhostInterface = typeBuilder.DefineNestedType("__Interface", TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic); typeBuilderGhostInterface = typeBuilder.DefineNestedType("__Interface", TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.NestedPublic);
AttributeHelper.HideFromJava(typeBuilderGhostInterface); AttributeHelper.HideFromJava(typeBuilderGhostInterface);
ghostIsInstanceMethod = typeBuilder.DefineMethod("IsInstance", MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object) }); ghostIsInstanceMethod = typeBuilder.DefineMethod("IsInstance", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object) });
ghostIsInstanceMethod.DefineParameter(1, ParameterAttributes.None, "obj"); ghostIsInstanceMethod.DefineParameter(1, ParameterAttributes.None, "obj");
ghostIsInstanceArrayMethod = typeBuilder.DefineMethod("IsInstanceArray", MethodAttributes.Public | MethodAttributes.Static, typeof(bool), new Type[] { typeof(object), typeof(int) }); 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(1, ParameterAttributes.None, "obj");
ghostIsInstanceArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank"); ghostIsInstanceArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
ghostCastMethod = typeBuilder.DefineMethod("Cast", MethodAttributes.Public | MethodAttributes.Static, typeBuilder, new Type[] { typeof(object) }); ghostCastMethod = typeBuilder.DefineMethod("Cast", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeBuilder, new Type[] { typeof(object) });
ghostCastMethod.DefineParameter(1, ParameterAttributes.None, "obj"); ghostCastMethod.DefineParameter(1, ParameterAttributes.None, "obj");
ghostCastArrayMethod = typeBuilder.DefineMethod("CastArray", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(object), typeof(int) }); 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(1, ParameterAttributes.None, "obj");
ghostCastArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank"); ghostCastArrayMethod.DefineParameter(2, ParameterAttributes.None, "rank");
return typeBuilder; return typeBuilder;

Просмотреть файл

@ -1218,7 +1218,7 @@ namespace IKVM.Internal
typeWrapper.helperTypeBuilder = typeWrapper.typeBuilder.DefineNestedType("__Helper", TypeAttributes.NestedPublic | TypeAttributes.Class); typeWrapper.helperTypeBuilder = typeWrapper.typeBuilder.DefineNestedType("__Helper", TypeAttributes.NestedPublic | TypeAttributes.Class);
AttributeHelper.HideFromJava(typeWrapper.helperTypeBuilder); AttributeHelper.HideFromJava(typeWrapper.helperTypeBuilder);
} }
helper = typeWrapper.helperTypeBuilder.DefineMethod(m.Name, MethodAttributes.Public | MethodAttributes.Static, typeWrapper.GetClassLoader().RetTypeWrapperFromSig(m.Sig).TypeAsSignatureType, argTypes); helper = typeWrapper.helperTypeBuilder.DefineMethod(m.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeWrapper.GetClassLoader().RetTypeWrapperFromSig(m.Sig).TypeAsSignatureType, argTypes);
if(m.Attributes != null) if(m.Attributes != null)
{ {
foreach(IKVM.Internal.MapXml.Attribute custattr in m.Attributes) foreach(IKVM.Internal.MapXml.Attribute custattr in m.Attributes)
@ -1284,7 +1284,7 @@ namespace IKVM.Internal
else else
{ {
MethodInfo overrideMethod = null; MethodInfo overrideMethod = null;
MethodAttributes attr = MapMethodAccessModifiers(m.Modifiers); MethodAttributes attr = MapMethodAccessModifiers(m.Modifiers) | MethodAttributes.HideBySig;
if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Static) != 0) if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Static) != 0)
{ {
attr |= MethodAttributes.Static; attr |= MethodAttributes.Static;
@ -1328,7 +1328,7 @@ namespace IKVM.Internal
if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Static) == 0) if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Static) == 0)
{ {
// instance methods must have an instancehelper method // instance methods must have an instancehelper method
MethodAttributes attr = MapMethodAccessModifiers(m.Modifiers) | MethodAttributes.Static; MethodAttributes attr = MapMethodAccessModifiers(m.Modifiers) | MethodAttributes.HideBySig | MethodAttributes.Static;
// NOTE instancehelpers for protected methods are made public, // NOTE instancehelpers for protected methods are made public,
// because cli.System.Object derived types can call protected methods // because cli.System.Object derived types can call protected methods
if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Protected) != 0) if((m.Modifiers & IKVM.Internal.MapXml.MapModifiers.Protected) != 0)