From fa12e806894a421a2a9daeaa244e56afac9f129d Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 17 Feb 2021 14:40:43 -0500 Subject: [PATCH 1/4] [net6] use MONO_AOT_MODE_INTERP_ONLY This depends on a fix to https://github.com/mono/mono/issues/18893 (make interp only mode distinct from MONO_AOT_MODE_LAST) which was done in https://github.com/mono/mono/pull/20159 but only for .NET 6, not previous Mono releases. Fixes https://github.com/xamarin/xamarin-android/issues/5633 --- src/monodroid/jni/android-system.cc | 4 ++++ src/monodroid/jni/android-system.hh | 10 ++++++++++ src/monodroid/jni/monodroid-glue.cc | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/src/monodroid/jni/android-system.cc b/src/monodroid/jni/android-system.cc index 5814e3c5c40..42721ff6115 100644 --- a/src/monodroid/jni/android-system.cc +++ b/src/monodroid/jni/android-system.cc @@ -657,8 +657,12 @@ AndroidSystem::setup_environment () break; case 'i': +#if !defined (NET6) aotMode = MonoAotMode::MONO_AOT_MODE_LAST; aot_mode_last_is_interpreter = true; +#else + aotMode = MonoAotMode::MONO_AOT_MODE_INTERP_ONLY; +#endif break; default: diff --git a/src/monodroid/jni/android-system.hh b/src/monodroid/jni/android-system.hh index a1dfc7a7602..1d85e9c5fd5 100644 --- a/src/monodroid/jni/android-system.hh +++ b/src/monodroid/jni/android-system.hh @@ -101,14 +101,22 @@ namespace xamarin::android::internal bool is_interpreter_enabled () const { +#if !defined (NET6) // HACK! See below return get_mono_aot_mode () == MonoAotMode::MONO_AOT_MODE_LAST && is_aot_mode_last_really_interpreter_mode (); +#else + return get_mono_aot_mode () == MonoAotMode::MONO_AOT_MODE_INTERP_ONLY; +#endif } // Hack, see comment for `aot_mode_last_is_interpreter` at the bottom of the class declaration bool is_aot_mode_last_really_interpreter_mode () const { +#if !defined(NET6) return aot_mode_last_is_interpreter; +#else + return false; +#endif } void set_running_in_emulator (bool yesno) @@ -151,6 +159,7 @@ namespace xamarin::android::internal MonoAotMode aotMode = MonoAotMode::MONO_AOT_MODE_NONE; bool running_in_emulator = false; +#if !defined (NET6) // This is a hack because of the way Mono currently switches the full interpreter (no JIT) mode. In Mono // **internal** headers there's an AOT mode macro, `MONO_EE_MODE_INTERP`, whose value is exactly the same as // MonoAotMode::MONO_AOT_MODE_LAST. However, we use `MonoAotMode::MONO_AOT_MODE_LAST` as a sentinel to indicate @@ -161,6 +170,7 @@ namespace xamarin::android::internal // See also: https://github.com/mono/mono/issues/18893 // bool aot_mode_last_is_interpreter = false; +#endif }; } #endif // !__ANDROID_SYSTEM_H diff --git a/src/monodroid/jni/monodroid-glue.cc b/src/monodroid/jni/monodroid-glue.cc index ab5c632ab5e..74e8474fad5 100644 --- a/src/monodroid/jni/monodroid-glue.cc +++ b/src/monodroid/jni/monodroid-glue.cc @@ -1807,6 +1807,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl MonoAotMode mode = MonoAotMode::MONO_AOT_MODE_NONE; if (androidSystem.is_mono_aot_enabled ()) { mode = androidSystem.get_mono_aot_mode (); +#if !defined (NET6) if (mode == MonoAotMode::MONO_AOT_MODE_LAST) { // Hack. See comments in android-system.hh if (!androidSystem.is_interpreter_enabled ()) { @@ -1821,6 +1822,13 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl log_info (LOG_DEFAULT, "Enabling Mono Interpreter"); } } +#else + if (mode != MonoAotMode::MONO_AOT_MODE_INTERP_ONLY) { + log_info (LOG_DEFAULT, "Enabling AOT mode in Mono"); + } else { + log_info (LOG_DEFAULT, "Enabling Mono Interpreter"); + } +#endif } mono_jit_set_aot_mode (mode); From bc358090491b15438bbc06ef37745ae9d2a13c82 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 3 Mar 2021 18:03:08 -0500 Subject: [PATCH 2/4] comments on #endif --- src/monodroid/jni/android-system.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monodroid/jni/android-system.cc b/src/monodroid/jni/android-system.cc index 42721ff6115..f9f4c0f4003 100644 --- a/src/monodroid/jni/android-system.cc +++ b/src/monodroid/jni/android-system.cc @@ -660,9 +660,9 @@ AndroidSystem::setup_environment () #if !defined (NET6) aotMode = MonoAotMode::MONO_AOT_MODE_LAST; aot_mode_last_is_interpreter = true; -#else +#else // defined (NET6) aotMode = MonoAotMode::MONO_AOT_MODE_INTERP_ONLY; -#endif +#endif // !defined (NET6) break; default: From 56c50bf959de3e308ef9a6bf4ebe53c68b75876f Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 3 Mar 2021 18:04:17 -0500 Subject: [PATCH 3/4] Comments on #endif --- src/monodroid/jni/android-system.hh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/monodroid/jni/android-system.hh b/src/monodroid/jni/android-system.hh index 1d85e9c5fd5..5c7e0685cdf 100644 --- a/src/monodroid/jni/android-system.hh +++ b/src/monodroid/jni/android-system.hh @@ -104,9 +104,9 @@ namespace xamarin::android::internal #if !defined (NET6) // HACK! See below return get_mono_aot_mode () == MonoAotMode::MONO_AOT_MODE_LAST && is_aot_mode_last_really_interpreter_mode (); -#else +#else // defined (NET6) return get_mono_aot_mode () == MonoAotMode::MONO_AOT_MODE_INTERP_ONLY; -#endif +#endif // !defined (NET6) } // Hack, see comment for `aot_mode_last_is_interpreter` at the bottom of the class declaration @@ -114,9 +114,9 @@ namespace xamarin::android::internal { #if !defined(NET6) return aot_mode_last_is_interpreter; -#else +#else // defined (NET6) return false; -#endif +#endif // !defined (NET6) } void set_running_in_emulator (bool yesno) @@ -170,7 +170,7 @@ namespace xamarin::android::internal // See also: https://github.com/mono/mono/issues/18893 // bool aot_mode_last_is_interpreter = false; -#endif +#endif // !defined (NET6) }; } #endif // !__ANDROID_SYSTEM_H From cbadda24603b3be20aa11a0eb8c9266d6359c6bb Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 3 Mar 2021 18:05:15 -0500 Subject: [PATCH 4/4] comments on #endif --- src/monodroid/jni/monodroid-glue.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monodroid/jni/monodroid-glue.cc b/src/monodroid/jni/monodroid-glue.cc index 74e8474fad5..6988af5ec97 100644 --- a/src/monodroid/jni/monodroid-glue.cc +++ b/src/monodroid/jni/monodroid-glue.cc @@ -1822,13 +1822,13 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl log_info (LOG_DEFAULT, "Enabling Mono Interpreter"); } } -#else +#else // defined (NET6) if (mode != MonoAotMode::MONO_AOT_MODE_INTERP_ONLY) { log_info (LOG_DEFAULT, "Enabling AOT mode in Mono"); } else { log_info (LOG_DEFAULT, "Enabling Mono Interpreter"); } -#endif +#endif // !defined (NET6) } mono_jit_set_aot_mode (mode);