Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[monodroid] Use MONO_AOT_MODE_INTERP_ONLY when available #5635

Merged
merged 4 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/monodroid/jni/android-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/monodroid/jni/android-system.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
8 changes: 8 additions & 0 deletions src/monodroid/jni/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()) {
Expand All @@ -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);

Expand Down