diff --git a/build-tools/scripts/RunNUnitTests.targets b/build-tools/scripts/RunNUnitTests.targets index 51aec7193..462dc48cb 100644 --- a/build-tools/scripts/RunNUnitTests.targets +++ b/build-tools/scripts/RunNUnitTests.targets @@ -19,14 +19,6 @@ - - <_JavaInteropNativeLibrary Include="$(_TopDir)\bin\$(Configuration)\libjava-interop.*" /> - - diff --git a/src/Java.Interop/Java.Interop/JavaProxyObject.cs b/src/Java.Interop/Java.Interop/JavaProxyObject.cs index e3c5b03ea..5454185b0 100644 --- a/src/Java.Interop/Java.Interop/JavaProxyObject.cs +++ b/src/Java.Interop/Java.Interop/JavaProxyObject.cs @@ -17,9 +17,9 @@ sealed class JavaProxyObject : JavaObject, IEquatable [JniAddNativeMethodRegistrationAttribute] static void RegisterNativeMembers (JniNativeMethodRegistrationArguments args) { - args.Registrations.Add (new JniNativeMethodRegistration ("equals", "(Ljava/lang/Object;)Z", (Func)Equals)); - args.Registrations.Add (new JniNativeMethodRegistration ("hashCode", "()I", (Func)GetHashCode)); - args.Registrations.Add (new JniNativeMethodRegistration ("toString", "()Ljava/lang/String;", (Func)ToString)); + args.Registrations.Add (new JniNativeMethodRegistration ("equals", "(Ljava/lang/Object;)Z", (EqualsMarshalMethod)Equals)); + args.Registrations.Add (new JniNativeMethodRegistration ("hashCode", "()I", (GetHashCodeMarshalMethod)GetHashCode)); + args.Registrations.Add (new JniNativeMethodRegistration ("toString", "()Ljava/lang/String;", (ToStringMarshalMethod)ToString)); } public override JniPeerMembers JniPeerMembers { @@ -72,6 +72,7 @@ public override bool Equals (object? obj) } // TODO: Keep in sync with the code generated by ExportedMemberBuilder + delegate bool EqualsMarshalMethod (IntPtr jnienv, IntPtr n_self, IntPtr n_value); static bool Equals (IntPtr jnienv, IntPtr n_self, IntPtr n_value) { var envp = new JniTransition (jnienv); @@ -91,6 +92,7 @@ static bool Equals (IntPtr jnienv, IntPtr n_self, IntPtr n_value) } // TODO: Keep in sync with the code generated by ExportedMemberBuilder + delegate int GetHashCodeMarshalMethod (IntPtr jnienv, IntPtr n_self); static int GetHashCode (IntPtr jnienv, IntPtr n_self) { var envp = new JniTransition (jnienv); @@ -107,6 +109,7 @@ static int GetHashCode (IntPtr jnienv, IntPtr n_self) } } + delegate IntPtr ToStringMarshalMethod (IntPtr jnienv, IntPtr n_self); static IntPtr ToString (IntPtr jnienv, IntPtr n_self) { var envp = new JniTransition (jnienv); diff --git a/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs b/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs index 387aa9856..d26ef55bb 100644 --- a/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs +++ b/src/Java.Interop/Java.Interop/JniEnvironment.Types.cs @@ -48,29 +48,37 @@ public static unsafe JniObjectReference FindClass (string classname) } NativeMethods.java_interop_jnienv_exception_clear (info.EnvironmentPointer); - var e = new JniObjectReference (thrown, JniObjectReferenceType.Local); - LogCreateLocalRef (e); + + var findClassThrown = new JniObjectReference (thrown, JniObjectReferenceType.Local); + LogCreateLocalRef (findClassThrown); + var pendingException = info.Runtime.GetExceptionForThrowable (ref findClassThrown, JniObjectReferenceOptions.CopyAndDispose); if (info.Runtime.ClassLoader_LoadClass != null) { var java = info.ToJavaName (classname); var __args = stackalloc JniArgumentValue [1]; __args [0] = new JniArgumentValue (java); - IntPtr ignoreThrown; - c = NativeMethods.java_interop_jnienv_call_object_method_a (info.EnvironmentPointer, out ignoreThrown, info.Runtime.ClassLoader.Handle, info.Runtime.ClassLoader_LoadClass.ID, (IntPtr) __args); + c = NativeMethods.java_interop_jnienv_call_object_method_a (info.EnvironmentPointer, out thrown, info.Runtime.ClassLoader.Handle, info.Runtime.ClassLoader_LoadClass.ID, (IntPtr) __args); JniObjectReference.Dispose (ref java); - if (ignoreThrown == IntPtr.Zero) { - JniObjectReference.Dispose (ref e); + if (thrown == IntPtr.Zero) { + (pendingException as IJavaPeerable)?.Dispose (); var r = new JniObjectReference (c, JniObjectReferenceType.Local); JniEnvironment.LogCreateLocalRef (r); return r; } NativeMethods.java_interop_jnienv_exception_clear (info.EnvironmentPointer); - NativeMethods.java_interop_jnienv_delete_local_ref (info.EnvironmentPointer, ignoreThrown); + if (pendingException != null) { + NativeMethods.java_interop_jnienv_delete_local_ref (info.EnvironmentPointer, thrown); + } + else { + var loadClassThrown = new JniObjectReference (thrown, JniObjectReferenceType.Local); + LogCreateLocalRef (loadClassThrown); + pendingException = info.Runtime.GetExceptionForThrowable (ref loadClassThrown, JniObjectReferenceOptions.CopyAndDispose); + } } - throw info.Runtime.GetExceptionForThrowable (ref e, JniObjectReferenceOptions.CopyAndDispose)!; + throw pendingException!; #endif // !FEATURE_JNIENVIRONMENT_JI_PINVOKES #if FEATURE_JNIOBJECTREFERENCE_SAFEHANDLES var c = info.Invoker.FindClass (info.EnvironmentPointer, classname); @@ -80,25 +88,32 @@ public static unsafe JniObjectReference FindClass (string classname) return new JniObjectReference (c, JniObjectReferenceType.Local); } info.Invoker.ExceptionClear (info.EnvironmentPointer); - LogCreateLocalRef (thrown); + var findClassThrown = new JniObjectReference (thrown, JniObjectReferenceType.Local); + LogCreateLocalRef (findClassThrown); + var pendingException = info.Runtime.GetExceptionForThrowable (ref findClassThrown, JniObjectReferenceOptions.CopyAndDispose); var java = info.ToJavaName (classname); var __args = stackalloc JniArgumentValue [1]; __args [0] = new JniArgumentValue (java); - c = info.Invoker.CallObjectMethodA (info.EnvironmentPointer, info.Runtime.ClassLoader.SafeHandle, info.Runtime.ClassLoader_LoadClass.ID, __args); + c = info.Invoker.CallObjectMethodA (info.EnvironmentPointer, info.Runtime.ClassLoader.SafeHandle, info.Runtime.ClassLoader_LoadClass.ID, __args); JniObjectReference.Dispose (ref java); - var ignoreThrown = info.Invoker.ExceptionOccurred (info.EnvironmentPointer); + thrown = info.Invoker.ExceptionOccurred (info.EnvironmentPointer); if (ignoreThrown.IsInvalid) { - thrown.Dispose (); - JniEnvironment.LogCreateLocalRef (c); - return new JniObjectReference (c, JniObjectReferenceType.Local); + (pendingException as IJavaPeerable)?.Dispose (); + var r = new JniObjectReference (c, JniObjectReferenceType.Local); + JniEnvironment.LogCreateLocalRef (r); + return r; } info.Invoker.ExceptionClear (info.EnvironmentPointer); - LogCreateLocalRef (ignoreThrown); - ignoreThrown.Dispose (); - var e = new JniObjectReference (thrown, JniObjectReferenceType.Local); - throw info.Runtime.GetExceptionForThrowable (ref e, JniObjectReferenceOptions.CopyAndDispose); + if (pendingException != null) { + thrown.Dispose (); + throw pendingException; + } + var loadClassThrown = new JniObjectReference (thrown, JniObjectReferenceType.Local); + LogCreateLocalRef (loadClassThrown); + pendingException = info.Runtime.GetExceptionForThrowable (ref loadClassThrown, JniObjectReferenceOptions.CopyAndDispose); + throw pendingException!; #endif // !FEATURE_JNIOBJECTREFERENCE_SAFEHANDLES } diff --git a/src/Java.Interop/Java.Interop/ManagedPeer.cs b/src/Java.Interop/Java.Interop/ManagedPeer.cs index 5a0469efb..5c0e033c3 100644 --- a/src/Java.Interop/Java.Interop/ManagedPeer.cs +++ b/src/Java.Interop/Java.Interop/ManagedPeer.cs @@ -14,18 +14,6 @@ namespace Java.Interop { [JniTypeSignature (JniTypeName)] /* static */ sealed class ManagedPeer : JavaObject { - delegate void ConstructDelegate (IntPtr jnienv, - IntPtr klass, - IntPtr n_self, - IntPtr n_assemblyQualifiedName, - IntPtr n_constructorSignature, - IntPtr n_constructorArguments); - delegate void RegisterDelegate (IntPtr jnienv, - IntPtr klass, - IntPtr n_nativeClass, - IntPtr n_assemblyQualifiedName, - IntPtr n_methods); - internal const string JniTypeName = "com/xamarin/java_interop/ManagedPeer"; @@ -37,11 +25,11 @@ static ManagedPeer () new JniNativeMethodRegistration ( "construct", ConstructSignature, - (ConstructDelegate) Construct), + (ConstructMarshalMethod) Construct), new JniNativeMethodRegistration ( "registerNativeMembers", RegisterNativeMembersSignature, - (RegisterDelegate) RegisterNativeMembers) + (RegisterMarshalMethod) RegisterNativeMembers) ); } @@ -62,6 +50,12 @@ public override JniPeerMembers JniPeerMembers { const string ConstructSignature = "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V"; // TODO: Keep in sync with the code generated by ExportedMemberBuilder + delegate void ConstructMarshalMethod (IntPtr jnienv, + IntPtr klass, + IntPtr n_self, + IntPtr n_assemblyQualifiedName, + IntPtr n_constructorSignature, + IntPtr n_constructorArguments); static void Construct ( IntPtr jnienv, IntPtr klass, @@ -183,6 +177,11 @@ static Type[] GetParameterTypes (string? signature) const string RegisterNativeMembersSignature = "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;)V"; + delegate void RegisterMarshalMethod (IntPtr jnienv, + IntPtr klass, + IntPtr n_nativeClass, + IntPtr n_assemblyQualifiedName, + IntPtr n_methods); static void RegisterNativeMembers ( IntPtr jnienv, IntPtr klass, diff --git a/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyObject.java b/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyObject.java index b3fe06738..3a9b5667f 100644 --- a/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyObject.java +++ b/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyObject.java @@ -8,7 +8,7 @@ extends java.lang.Object implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.Interop.JavaProxyObject, Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.Interop.JavaProxyObject, Java.Interop"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( JavaProxyObject.class, diff --git a/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyThrowable.java b/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyThrowable.java index b672d141a..47838b4b8 100644 --- a/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyThrowable.java +++ b/src/Java.Interop/java/com/xamarin/java_interop/internal/JavaProxyThrowable.java @@ -8,7 +8,7 @@ extends java.lang.Error implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.Interop.JavaProxyThrowable, Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.Interop.JavaProxyThrowable, Java.Interop"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( JavaProxyThrowable.class, diff --git a/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs b/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs index 651f0b4d1..c3ceb115d 100644 --- a/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs +++ b/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading; @@ -44,6 +45,10 @@ public JreRuntimeOptions () ValueManager = ValueManager ?? new MonoRuntimeValueManager (); ObjectReferenceManager = ObjectReferenceManager ?? new MonoRuntimeObjectReferenceManager (); } + else { + ValueManager = ValueManager ?? new DummyValueManager (); + ObjectReferenceManager = ObjectReferenceManager ?? new DummyObjectReferenceManager (); + } } public JreRuntimeOptions AddOption (string option) @@ -161,5 +166,52 @@ partial class NativeMethods { [DllImport (JavaInteropLib, CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] internal static extern int java_interop_jvm_create (out IntPtr javavm, out IntPtr jnienv, ref JavaVMInitArgs args); } + + class DummyValueManager : JniRuntime.JniValueManager { + + public override void WaitForGCBridgeProcessing () + { + } + + public override void CollectPeers () + { + } + + public override void AddPeer (IJavaPeerable reference) + { + } + + public override void RemovePeer (IJavaPeerable reference) + { + } + + public override void FinalizePeer (IJavaPeerable reference) + { + } + + public override List GetSurfacedPeers () + { + return null; + } + + public override IJavaPeerable PeekPeer (global::Java.Interop.JniObjectReference reference) + { + return null; + } + + public override void ActivatePeer (IJavaPeerable self, JniObjectReference reference, ConstructorInfo cinfo, object [] argumentValues) + { + } + } + + class DummyObjectReferenceManager : JniRuntime.JniObjectReferenceManager { + public override int GlobalReferenceCount { + get {return 0;} + } + + public override int WeakGlobalReferenceCount { + get {return 0;} + } + } } diff --git a/src/Java.Runtime.Environment/Java.Runtime.Environment.csproj b/src/Java.Runtime.Environment/Java.Runtime.Environment.csproj index 4d0260d77..b1440bad1 100644 --- a/src/Java.Runtime.Environment/Java.Runtime.Environment.csproj +++ b/src/Java.Runtime.Environment/Java.Runtime.Environment.csproj @@ -13,6 +13,7 @@ + diff --git a/src/java-interop/java-interop.csproj b/src/java-interop/java-interop.csproj index 25b8ad761..13ae624e8 100644 --- a/src/java-interop/java-interop.csproj +++ b/src/java-interop/java-interop.csproj @@ -39,7 +39,7 @@ - + diff --git a/src/java-interop/java-interop.targets b/src/java-interop/java-interop.targets index 06e5370f3..0c4050540 100644 --- a/src/java-interop/java-interop.targets +++ b/src/java-interop/java-interop.targets @@ -2,9 +2,9 @@ + Outputs="$(IntermediateOutputPath)jni.c"> - + @@ -12,11 +12,23 @@ <_UnixLib>$(OutputPath)/lib$(OutputName).so + + + PreserveNewest + + + + + + PreserveNewest + + + $([MSBuild]::Unescape($(DefineSymbols.Replace(' ', ';')))) $([MSBuild]::Unescape($(_MonoIncludePath)));$([MSBuild]::Unescape($(_JdkIncludePath))) - obj/$(Configuration)/%(Filename).o + $(IntermediateOutputPath)/%(Filename).o @@ -25,7 +37,7 @@ DependsOnTargets="BuildJni_c" Inputs="@(ClCompile);@(ClInclude)" Outputs="%(ClCompile.Obj)"> - + <_Cl Include="@(ClCompile)"> gcc -std=c99 -fPIC @@ -86,7 +98,6 @@ - - net472 + net472;netcoreapp3.1 false true diff --git a/tests/Java.Interop-Tests/Java.Interop/CallVirtualFromConstructorDerived.cs b/tests/Java.Interop-Tests/Java.Interop/CallVirtualFromConstructorDerived.cs index 81bf077af..6c4fcc62d 100644 --- a/tests/Java.Interop-Tests/Java.Interop/CallVirtualFromConstructorDerived.cs +++ b/tests/Java.Interop-Tests/Java.Interop/CallVirtualFromConstructorDerived.cs @@ -12,7 +12,7 @@ public class CallVirtualFromConstructorDerived : CallVirtualFromConstructorBase [JniAddNativeMethodRegistrationAttribute] static void RegisterNativeMembers (JniNativeMethodRegistrationArguments args) { - args.Registrations.Add (new JniNativeMethodRegistration ("calledFromConstructor", "(I)V", (Action)CalledFromConstructorHandler)); + args.Registrations.Add (new JniNativeMethodRegistration ("calledFromConstructor", "(I)V", (CalledFromConstructorMarshalMethod)CalledFromConstructorHandler)); } public override JniPeerMembers JniPeerMembers { @@ -57,6 +57,7 @@ public static unsafe CallVirtualFromConstructorDerived NewInstance (int value) return JniEnvironment.Runtime.ValueManager.GetValue (ref o, JniObjectReferenceOptions.CopyAndDispose); } + delegate void CalledFromConstructorMarshalMethod (IntPtr jnienv, IntPtr n_self, int value); static void CalledFromConstructorHandler (IntPtr jnienv, IntPtr n_self, int value) { var envp = new JniTransition (jnienv); diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualBase.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualBase.java index dbfe0475d..5aeb99ec9 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualBase.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualBase.java @@ -6,13 +6,15 @@ public class CallNonvirtualBase implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.CallNonvirtualBase, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public CallNonvirtualBase () { if (CallNonvirtualBase.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.CallNonvirtualBase, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived.java index 19bf4871d..3e0b3156d 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived.java @@ -8,13 +8,15 @@ public class CallNonvirtualDerived extends CallNonvirtualBase implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.CallNonvirtualDerived, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public CallNonvirtualDerived () { if (CallNonvirtualDerived.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.CallNonvirtualDerived, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived2.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived2.java index fe18b4c9f..0eedf6c91 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived2.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallNonvirtualDerived2.java @@ -8,13 +8,15 @@ public class CallNonvirtualDerived2 extends CallNonvirtualDerived implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.CallNonvirtualDerived2, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public CallNonvirtualDerived2 () { if (CallNonvirtualDerived2.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.CallNonvirtualDerived2, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorBase.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorBase.java index 45d9f4883..5f3b9dd38 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorBase.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorBase.java @@ -6,13 +6,15 @@ public class CallVirtualFromConstructorBase implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.CallVirtualFromConstructorBase, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public CallVirtualFromConstructorBase (int value) { if (CallVirtualFromConstructorBase.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.CallVirtualFromConstructorBase, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "System.Int32", value ); diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorDerived.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorDerived.java index af081fe67..6902d43f0 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorDerived.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CallVirtualFromConstructorDerived.java @@ -8,7 +8,7 @@ public class CallVirtualFromConstructorDerived extends CallVirtualFromConstructorBase implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.InteropTests.CallVirtualFromConstructorDerived, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.InteropTests.CallVirtualFromConstructorDerived, Java.Interop-Tests"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( CallVirtualFromConstructorDerived.class, diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/CrossReferenceBridge.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/CrossReferenceBridge.java index 3b6e01073..a46e9966c 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/CrossReferenceBridge.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/CrossReferenceBridge.java @@ -6,13 +6,15 @@ public class CrossReferenceBridge implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.CrossReferenceBridge, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public CrossReferenceBridge () { if (CrossReferenceBridge.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.CrossReferenceBridge, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/GetThis.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/GetThis.java index 89cdc53f9..51d958cf2 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/GetThis.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/GetThis.java @@ -6,7 +6,7 @@ public class GetThis implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.InteropTests.GetThis, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.InteropTests.GetThis, Java.Interop-Tests"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( GetThis.class, @@ -20,7 +20,7 @@ public GetThis () { if (GetThis.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.GetThis, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/SelfRegistration.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/SelfRegistration.java index e76d2b016..c1503cc79 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/SelfRegistration.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/SelfRegistration.java @@ -6,13 +6,15 @@ public class SelfRegistration implements GCUserPeerable { + static final String assemblyQualifiedName = "Java.InteropTests.SelfRegistration, Java.Interop-Tests"; + ArrayList managedReferences = new ArrayList(); public SelfRegistration () { if (SelfRegistration.class == getClass ()) { com.xamarin.java_interop.ManagedPeer.construct ( this, - "Java.InteropTests.SelfRegistration, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", + assemblyQualifiedName, "" ); } diff --git a/tests/Java.Interop-Tests/java/com/xamarin/interop/TestType.java b/tests/Java.Interop-Tests/java/com/xamarin/interop/TestType.java index dd8c2c1f0..f812f48a1 100644 --- a/tests/Java.Interop-Tests/java/com/xamarin/interop/TestType.java +++ b/tests/Java.Interop-Tests/java/com/xamarin/interop/TestType.java @@ -6,7 +6,7 @@ public class TestType implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.InteropTests.TestType, Java.Interop-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.InteropTests.TestType, Java.Interop-Tests"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( TestType.class, diff --git a/tests/Java.Interop.Export-Tests/java/com/xamarin/interop/export/ExportType.java b/tests/Java.Interop.Export-Tests/java/com/xamarin/interop/export/ExportType.java index be8da5aa6..8e549580c 100644 --- a/tests/Java.Interop.Export-Tests/java/com/xamarin/interop/export/ExportType.java +++ b/tests/Java.Interop.Export-Tests/java/com/xamarin/interop/export/ExportType.java @@ -8,7 +8,7 @@ public class ExportType implements GCUserPeerable { - static final String assemblyQualifiedName = "Java.InteropTests.ExportTest, Java.Interop.Export-Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + static final String assemblyQualifiedName = "Java.InteropTests.ExportTest, Java.Interop.Export-Tests"; static { com.xamarin.java_interop.ManagedPeer.registerNativeMembers ( ExportType.class, diff --git a/tests/TestJVM/TestJVM.cs b/tests/TestJVM/TestJVM.cs index 4995e874d..fa61be91b 100644 --- a/tests/TestJVM/TestJVM.cs +++ b/tests/TestJVM/TestJVM.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Threading; +using Xamarin.Android.Tools; + using Java.Interop; namespace Java.InteropTests @@ -15,8 +17,8 @@ static JreRuntimeOptions CreateBuilder (string[] jars) { var dir = Path.GetDirectoryName (typeof (TestJVM).Assembly.Location); var builder = new JreRuntimeOptions () { - JvmLibraryPath = Environment.GetEnvironmentVariable ("JI_JVM_PATH"), - JniAddNativeMethodRegistrationAttributePresent = true, + JvmLibraryPath = GetJvmLibraryPath (), + JniAddNativeMethodRegistrationAttributePresent = true, }; if (jars != null) { foreach (var jar in jars) @@ -28,6 +30,16 @@ static JreRuntimeOptions CreateBuilder (string[] jars) return builder; } + static string GetJvmLibraryPath () + { + var env = Environment.GetEnvironmentVariable ("JI_JVM_PATH"); + if (!string.IsNullOrEmpty (env)) + return env; + var jdk = JdkInfo.GetKnownSystemJdkInfos () + .FirstOrDefault (); + return jdk?.JdkJvmPath; + } + Dictionary typeMappings; public TestJVM (string[] jars = null, Dictionary typeMappings = null) diff --git a/tests/TestJVM/TestJVM.csproj b/tests/TestJVM/TestJVM.csproj index 9b11e9ef5..ab52b760f 100644 --- a/tests/TestJVM/TestJVM.csproj +++ b/tests/TestJVM/TestJVM.csproj @@ -1,7 +1,7 @@ - net472 + net472;netcoreapp3.1 false @@ -23,6 +23,7 @@ + diff --git a/tests/invocation-overhead/invocation-overhead.cs b/tests/invocation-overhead/invocation-overhead.cs index 7f7768e91..b8ca515f2 100644 --- a/tests/invocation-overhead/invocation-overhead.cs +++ b/tests/invocation-overhead/invocation-overhead.cs @@ -366,55 +366,12 @@ public override string ToString () } } - -class DummyValueManager : JniRuntime.JniValueManager { - public override void WaitForGCBridgeProcessing () - { - } - public override void CollectPeers () - { - } - public override void AddPeer (IJavaPeerable reference) - { - } - public override void RemovePeer (IJavaPeerable reference) - { - } - public override void FinalizePeer (IJavaPeerable reference) - { - } - public override List GetSurfacedPeers () - { - return null; - } - public override IJavaPeerable PeekPeer (global::Java.Interop.JniObjectReference reference) - { - return null; - } - public override void ActivatePeer (IJavaPeerable self, global::Java.Interop.JniObjectReference reference, ConstructorInfo cinfo, object [] argumentValues) - { - throw new NotImplementedException (); - } -} - -class DummyObjectReferenceManager : JniRuntime.JniObjectReferenceManager { - public override int GlobalReferenceCount { - get {return 0;} - } - - public override int WeakGlobalReferenceCount { - get {return 0;} - } -} - class App { public static void Main () { var runtimeOptions = new JreRuntimeOptions (){ JvmLibraryPath = Environment.GetEnvironmentVariable ("JI_JVM_PATH"), - ValueManager = new DummyValueManager (), - ObjectReferenceManager = new DummyObjectReferenceManager (), }; var GlobalRuntime = runtimeOptions.CreateJreVM (); IntPtr _env = global::Java.Interop.JniEnvironment.EnvironmentPointer;