From b921288f2c6def3df19095996c355cc6dcb91472 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 16 Dec 2024 15:09:24 -0600 Subject: [PATCH 1/2] [monodroid] remove `_monodroid_get_identity_hash_code` In a NativeAOT context, we don't have `libmonodroid.so` *at all*. This makes methods like `JNIEnv.GetIdentityHashCode()` non-functional, as it p/invokes into `_monodroid_get_identity_hash_code`. Remove `_monodroid_get_identity_hash_code`, in favor of: return JniEnvironment.References.GetIdentityHashCode (new JniObjectReference (v)); Which should have negligible performance impact and works without `libmonodroid.so`. --- src/Mono.Android/Android.Runtime/JNIEnv.cs | 2 +- src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs | 3 --- src/native/monodroid/internal-pinvokes.cc | 7 ------- src/native/pinvoke-override/generate-pinvoke-tables.cc | 1 - src/native/pinvoke-override/pinvoke-tables.include | 6 ++---- src/native/runtime-base/internal-pinvokes.hh | 1 - 6 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Mono.Android/Android.Runtime/JNIEnv.cs b/src/Mono.Android/Android.Runtime/JNIEnv.cs index 870d944a0e5..cde07569a30 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnv.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnv.cs @@ -39,7 +39,7 @@ static Type MakeArrayType (Type type) => internal static IntPtr IdentityHash (IntPtr v) { - return RuntimeNativeMethods._monodroid_get_identity_hash_code (Handle, v); + return JniEnvironment.References.GetIdentityHashCode (new JniObjectReference (v)); } public static void CheckHandle (IntPtr jnienv) diff --git a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs index da635032800..8c3edcf1045 100644 --- a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs +++ b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs @@ -35,9 +35,6 @@ internal static class RuntimeNativeMethods [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] internal extern static void monodroid_free (IntPtr ptr); - [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] - internal extern static IntPtr _monodroid_get_identity_hash_code (IntPtr env, IntPtr value); - [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] internal static extern int _monodroid_gref_get (); diff --git a/src/native/monodroid/internal-pinvokes.cc b/src/native/monodroid/internal-pinvokes.cc index 81367aaea29..051d2905f61 100644 --- a/src/native/monodroid/internal-pinvokes.cc +++ b/src/native/monodroid/internal-pinvokes.cc @@ -138,13 +138,6 @@ monodroid_clear_gdb_wait () MonodroidRuntime::set_monodroid_gdb_wait (false); } -void* -_monodroid_get_identity_hash_code (JNIEnv *env, void *v) -{ - intptr_t rv = env->CallStaticIntMethod (MonodroidRuntime::get_java_class_System (), MonodroidRuntime::get_java_class_method_System_identityHashCode (), v); - return (void*) rv; -} - void* _monodroid_timezone_get_default_id () { diff --git a/src/native/pinvoke-override/generate-pinvoke-tables.cc b/src/native/pinvoke-override/generate-pinvoke-tables.cc index 9fb9cc70677..dcd71d6b415 100644 --- a/src/native/pinvoke-override/generate-pinvoke-tables.cc +++ b/src/native/pinvoke-override/generate-pinvoke-tables.cc @@ -47,7 +47,6 @@ const std::vector internal_pinvoke_names = { "_monodroid_gc_wait_for_bridge_processing", "_monodroid_get_dns_servers", "monodroid_get_dylib", - "_monodroid_get_identity_hash_code", "_monodroid_getifaddrs", "monodroid_get_log_categories", "monodroid_get_namespaced_system_property", diff --git a/src/native/pinvoke-override/pinvoke-tables.include b/src/native/pinvoke-override/pinvoke-tables.include index dc4f761d8c8..58ae7876b96 100644 --- a/src/native/pinvoke-override/pinvoke-tables.include +++ b/src/native/pinvoke-override/pinvoke-tables.include @@ -11,12 +11,11 @@ namespace { #if INTPTR_MAX == INT64_MAX //64-bit internal p/invoke table - std::array internal_pinvokes {{ + std::array internal_pinvokes {{ {0x452e23128e42f0a, "monodroid_get_log_categories", reinterpret_cast(&monodroid_get_log_categories)}, {0xa50ce5de13bf8b5, "_monodroid_timezone_get_default_id", reinterpret_cast(&_monodroid_timezone_get_default_id)}, {0x19055d65edfd668e, "_monodroid_get_network_interface_up_state", reinterpret_cast(&_monodroid_get_network_interface_up_state)}, {0x2b3b0ca1d14076da, "monodroid_get_dylib", reinterpret_cast(&monodroid_get_dylib)}, - {0x2fbe68718cf2510d, "_monodroid_get_identity_hash_code", reinterpret_cast(&_monodroid_get_identity_hash_code)}, {0x3ade4348ac8ce0fa, "_monodroid_freeifaddrs", reinterpret_cast(&_monodroid_freeifaddrs)}, {0x3b2467e7eadd4a6a, "_monodroid_lref_log_new", reinterpret_cast(&_monodroid_lref_log_new)}, {0x3b8097af56b5361f, "monodroid_log_traces", reinterpret_cast(&monodroid_log_traces)}, @@ -551,10 +550,9 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x18 constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; #else //32-bit internal p/invoke table - std::array internal_pinvokes {{ + std::array internal_pinvokes {{ {0xb7a486a, "monodroid_TypeManager_get_java_class_name", reinterpret_cast(&monodroid_TypeManager_get_java_class_name)}, {0xf562bd9, "monodroid_embedded_assemblies_set_assemblies_prefix", reinterpret_cast(&monodroid_embedded_assemblies_set_assemblies_prefix)}, - {0x1a8eab17, "_monodroid_get_identity_hash_code", reinterpret_cast(&_monodroid_get_identity_hash_code)}, {0x227a2636, "monodroid_get_namespaced_system_property", reinterpret_cast(&monodroid_get_namespaced_system_property)}, {0x2aea7c33, "_monodroid_max_gref_get", reinterpret_cast(&_monodroid_max_gref_get)}, {0x30b9487b, "_monodroid_get_dns_servers", reinterpret_cast(&_monodroid_get_dns_servers)}, diff --git a/src/native/runtime-base/internal-pinvokes.hh b/src/native/runtime-base/internal-pinvokes.hh index b73e390cccf..674fe8bf889 100644 --- a/src/native/runtime-base/internal-pinvokes.hh +++ b/src/native/runtime-base/internal-pinvokes.hh @@ -36,7 +36,6 @@ void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char * void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); void _monodroid_gc_wait_for_bridge_processing (); void monodroid_clear_gdb_wait (); -void* _monodroid_get_identity_hash_code (JNIEnv *env, void *v); void* _monodroid_timezone_get_default_id (); void _monodroid_counters_dump ([[maybe_unused]] const char *format, [[maybe_unused]] va_list args); xamarin::android::managed_timing_sequence* monodroid_timing_start (const char *message); From b70c8129e5b446d6cf0a5e0dfc91475208f4baf8 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 16 Dec 2024 15:53:39 -0600 Subject: [PATCH 2/2] Update pinvoke-tables.include --- src/native/pinvoke-override/pinvoke-tables.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/pinvoke-override/pinvoke-tables.include b/src/native/pinvoke-override/pinvoke-tables.include index 58ae7876b96..f335ae5c835 100644 --- a/src/native/pinvoke-override/pinvoke-tables.include +++ b/src/native/pinvoke-override/pinvoke-tables.include @@ -1089,6 +1089,6 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x93 constexpr hash_t system_globalization_native_library_hash = 0xa66f1e5a; #endif -constexpr size_t internal_pinvokes_count = 47; +constexpr size_t internal_pinvokes_count = 46; constexpr size_t dotnet_pinvokes_count = 477; } // end of anonymous namespace