Skip to content

Commit

Permalink
[monodroid, Xamarin.Android.Build.Tasks] Interpreter support (dotnet#…
Browse files Browse the repository at this point in the history
…4618)

Context: https://www.mono-project.com/news/2017/11/13/mono-interpreter/

Add *experimental* support to use [Mono's IL interpreter][0] instead
of using the JIT or (Hybrid)AOT backends by setting the
`$(_AndroidUseInterpreter)` MSBuild property to True.

This is a proof-of-concept to explore how the interpreter backend
performs compared to the JIT backend at various tasks.  It is not
currently intended for production use.

Note that Mono's IL interpreter does *not* currently support running
on x86 targets.  Issue an XA0124 error if the interpreter is enabled
when targeting x86 devices.

One "interesting" -- but not explored -- result is that startup time
is [*reduced* when using the interpreter][1]; on a Pixel 3 XL launching
a arm64-v8a build of `tests/Xamarin.Forms-Performance-Integration`:

| Description | native-to-managed | Runtime.init | ActivityDisplayed |
|------------:|------------------:|-------------:|------------------:|
| JIT         |         53.660 ms |    92.821 ms |        1091.30 ms |
| Interpreter |         32.019 ms |   112.288 ms |         897.50 ms |

Here, native-to-managed time and ActivityDisplayed times are reduced,
while `Runtime.init()` time is increased.

We did not explore why this would be the case, or what other
performance changes would be present after app startup.

[0]: https://www.mono-project.com/news/2017/11/13/mono-interpreter/
[1]: https://gist.github.com/grendello/3510f2c0621eb360cd063d6c00b4b1e8#file-results-md
  • Loading branch information
grendello committed Apr 28, 2020
1 parent a9bbb62 commit 42822e0
Show file tree
Hide file tree
Showing 36 changed files with 245 additions and 35 deletions.
1 change: 1 addition & 0 deletions Documentation/guides/messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ms.date: 01/24/2020
+ [XA0121](xa0121.md): Assembly '{assembly}' is using '[assembly: Java.Interop.JavaLibraryReferenceAttribute]', which is no longer supported. Use a newer version of this NuGet package or notify the library author.
+ [XA0122](xa0122.md): Assembly '{assembly}' is using a deprecated attribute '[assembly: Java.Interop.DoNotPackageAttribute]'. Use a newer version of this NuGet package or notify the library author.
+ XA0123: Removing {issue} from {propertyName}. Lint {version} does not support this check.
+ [XA0124](xa0124.md): Interpreter is not supported by the x86 ABI

## XA1xxx: Project related

Expand Down
18 changes: 18 additions & 0 deletions Documentation/guides/messages/xa0124.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Xamarin.Android error XA0124
description: XA0124 error code
ms.date: 04/28/2020
---
# Xamarin.Android error XA0124

## Issue

Mono Interpreter does not support running on x86 devices.

## Solution

When attempting to use the interpreter, please make sure to disable
the `x86` target by removing it from the `$(AndroidSupportedAbis)`
MSBuild property in your project file. This can be done conditionally
**only** when using the interpreter.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CreateAndroidEmulator : Task

public string TargetId {get; set;}

public string ImageName {get; set;} = "XamarinAndroidTestRunner";
public string ImageName {get; set;} = "XamarinAndroidTestRunner64";

public string DataPartitionSizeMB {get; set;} = "2048";
public string RamSizeMB {get; set;} = "2048";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Xamarin.Android.Tools.BootstrapTasks
public class RunAndroidEmulatorCheckBootTimes : Task
{
public string CheckBootTimesPath { get; set; }
public string DeviceName { get; set; } = "XamarinAndroidTestRunner";
public string DeviceName { get; set; } = "XamarinAndroidTestRunner64";

public override bool Execute ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class StartAndroidEmulator : Task

public string AndroidSdkHome {get; set;}
public string Port {get; set;}
public string ImageName {get; set;} = "XamarinAndroidTestRunner";
public string ImageName {get; set;} = "XamarinAndroidTestRunner64";
public string ToolPath {get; set;}
public string ToolExe {get; set;}

Expand Down
5 changes: 3 additions & 2 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<UsingTask AssemblyFile="$(PrepTasksAssembly)" TaskName="Xamarin.Android.BuildTools.PrepTasks.ProcessApkSizes" />

<PropertyGroup>
<_TestImageName>XamarinAndroidTestRunner</_TestImageName>
<_TestImageName>XamarinAndroidTestRunner64</_TestImageName>
<_AdbEmulatorPort>5570</_AdbEmulatorPort>
<_ApkSizesReferenceDirectory>$(MSBuildThisFileDirectory)..\..\tests\apk-sizes-reference</_ApkSizesReferenceDirectory>
</PropertyGroup>
Expand Down Expand Up @@ -44,7 +44,7 @@
</Xamarin.Android.Tools.BootstrapTasks.CheckAdbTarget>
<CreateAndroidEmulator
Condition=" '$(_ValidAdbTarget)' != 'True' "
AndroidAbi="x86"
AndroidAbi="x86_64"
AndroidSdkHome="$(AndroidSdkDirectory)"
JavaSdkHome="$(JavaSdkDirectory)"
SdkVersion="29"
Expand Down Expand Up @@ -342,6 +342,7 @@
<Target Name="CheckBootTimes"
DependsOnTargets="AcquireAndroidTarget;ReleaseAndroidTarget">
<RunAndroidEmulatorCheckBootTimes
DeviceName="$(_TestImageName)"
CheckBootTimesPath="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\check-boot-times.exe"
/>
</Target>
Expand Down
9 changes: 7 additions & 2 deletions build-tools/xaprepare/xaprepare/Application/MonoJitRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ class MonoJitRuntime : MonoRuntime
{
public override string Flavor => "Android JIT";

public MonoJitRuntime (string abiName, Func<Context, bool> enabledCheck)
public MonoJitRuntime (string abiName, bool interpreter, Func<Context, bool> enabledCheck)
: base (abiName, enabledCheck)
{}
{
if (interpreter) {
MonoSdksPrefix = "interpreter-";
DisplayName = $"{abiName} (interpreter)";
}
}

public override void Init (Context context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static List<Runtime> GetEnabledRuntimes (Runtimes allRuntimes, bool enabl
foreach (Runtime runtime in allRuntimes.Items.Where (r => r is MonoJitRuntime && r.Enabled)) {
enabledRuntimes.Add (runtime);
if (enableLogging)
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.Name}");
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.DisplayName}");
}

if (enableLogging) {
Expand All @@ -50,7 +50,7 @@ public static List<Runtime> GetEnabledRuntimes (Runtimes allRuntimes, bool enabl
foreach (Runtime runtime in allRuntimes.Items.Where (r => r is MonoHostRuntime && r.Enabled)) {
enabledRuntimes.Add (runtime);
if (enableLogging)
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.Name}");
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.DisplayName}");
}

bool anyCrossEnabled = false;
Expand All @@ -62,7 +62,7 @@ public static List<Runtime> GetEnabledRuntimes (Runtimes allRuntimes, bool enabl
anyCrossEnabled = true;
enabledRuntimes.Add (runtime);
if (enableLogging)
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.Name}");
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.DisplayName}");
}

if (enableLogging && !anyCrossEnabled)
Expand All @@ -77,7 +77,7 @@ public static List<Runtime> GetEnabledRuntimes (Runtimes allRuntimes, bool enabl
anyCrossEnabled = true;
enabledRuntimes.Add (runtime);
if (enableLogging)
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.Name}");
Log.Instance.StatusLine ($" {context.Characters.Bullet} {runtime.DisplayName}");
}
if (enableLogging && !anyCrossEnabled)
Log.Instance.StatusLine ($" NONE", ConsoleColor.DarkCyan);
Expand Down
9 changes: 9 additions & 0 deletions build-tools/xaprepare/xaprepare/Application/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Xamarin.Android.Prepare
{
abstract class Runtime : AppObject
{
string displayName;
Func<Context, bool> enabledCheck;

/// <summary>
Expand All @@ -24,6 +25,14 @@ abstract class Runtime : AppObject
public string InstallPath { get; protected set; }
public string Name { get; protected set; }

/// <summary>
/// Name of the runtime for display purposes. If not set explicitly, it is the same as <see cref="Name"/>
/// </summary>
public string DisplayName {
get => String.IsNullOrEmpty (displayName) ? Name : displayName;
set => displayName = value;
}

/// <summary>
/// Purely cosmetic thing - the kind of runtime (LLVM, JIT etc), for progress reporting.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public AndroidToolchain ()
new AndroidToolchainComponent ("docs-24_r01", destDir: "docs", pkgRevision: "1"),
new AndroidToolchainComponent ("android_m2repository_r47", destDir: Path.Combine ("extras", "android", "m2repository"), pkgRevision: "47.0.0"),
new AndroidToolchainComponent ("x86-29_r06", destDir: Path.Combine ("system-images", "android-29", "default", "x86"), relativeUrl: new Uri ("sys-img/android/", UriKind.Relative), pkgRevision: "6"),
new AndroidToolchainComponent ($"x86_64-29_r07-{osTag}", destDir: Path.Combine ("system-images", "android-29", "default", "x86_64"), relativeUrl: new Uri ("sys-img/android/", UriKind.Relative), pkgRevision: "7"),
new AndroidToolchainComponent ($"android-ndk-r{AndroidNdkVersion}-{osTag}-x86_64", destDir: AndroidNdkDirectory, pkgRevision: AndroidPkgRevision),
new AndroidToolchainComponent ($"build-tools_r{XABuildToolsVersion}-{altOsTag}", destDir: Path.Combine ("build-tools", XABuildToolsFolder), isMultiVersion: true),
new AndroidToolchainComponent ($"platform-tools_r{XAPlatformToolsVersion}-{osTag}", destDir: "platform-tools", pkgRevision: XAPlatformToolsVersion),
Expand Down
28 changes: 28 additions & 0 deletions build-tools/xaprepare/xaprepare/ConfigAndData/Runtimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,49 @@ partial class Runtimes
public readonly List<Runtime> Items = new List <Runtime> {
new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidArmV7a,
interpreter: false,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidArmV7a)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidArmV7a,
interpreter: true,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidArmV7a)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidArmV8a,
interpreter: false,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidArmV8a)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidArmV8a,
interpreter: true,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidArmV8a)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidX86,
interpreter: false,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidX86)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidX86,
interpreter: true,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidX86)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidX86_64,
interpreter: false,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidX86_64)
),

new MonoJitRuntime (
abiName: AbiNames.TargetJit.AndroidX86_64,
interpreter: true,
enabledCheck: (Context ctx) => ctx.IsTargetJitAbiEnabled (AbiNames.TargetJit.AndroidX86_64)
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ async Task<bool> InstallRuntimes (Context context, List<Runtime> enabledRuntimes

StatusStep (context, "Installing runtimes");
foreach (Runtime runtime in enabledRuntimes) {
StatusSubStep (context, $"Installing {runtime.Flavor} runtime {runtime.Name}");
StatusSubStep (context, $"Installing {runtime.Flavor} runtime {runtime.DisplayName}");

string src, dst;
bool skipFile;
Expand Down Expand Up @@ -355,12 +355,12 @@ bool StripFile (Runtime runtime, RuntimeFile rtf, string filePath)
return true;

if (String.IsNullOrEmpty (monoRuntime.Strip)) {
Log.WarningLine ($"Binary stripping impossible, runtime {monoRuntime.Name} doesn't define the strip command");
Log.WarningLine ($"Binary stripping impossible, runtime {monoRuntime.DisplayName} doesn't define the strip command");
return true;
}

if (context.OS.IsWindows && (context.IsWindowsCrossAotAbi (monoRuntime.Name) || context.IsMingwHostAbi (monoRuntime.Name))) {
Log.WarningLine ($"Unable to strip '{monoRuntime.Name}' on Windows.");
Log.WarningLine ($"Unable to strip '{monoRuntime.DisplayName}' on Windows.");
return true;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</comment>
</data>
<data name="XA0124" xml:space="preserve">
<value>Interpreter is not supported by the x86 ABI</value>
</data>
<data name="XA1000" xml:space="preserve">
<value>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</value>
<comment>{0} - The file name
Expand Down Expand Up @@ -741,4 +744,4 @@ In this message, the term "handheld app" means "app for handheld devices."
<data name="XA5302" xml:space="preserve">
<value>Two processes may be building this project at once. Lock file exists at path: {0}</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Při parsování {0} došlo k problému. Pravděpodobnou příčinou je neúplný nebo neplatný kód XML. Výjimka: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Problem beim Analysieren von "{0}". Dies ist wahrscheinlich auf eine unvollständige oder ungültige XML-Datei zurückzuführen. Ausnahme: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Hubo un problema al analizar {0}. Probablemente se deba a un elemento XML incompleto o no válido. Excepción: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Un problème s'est produit durant l'analyse de {0}. Cela est probablement dû à du code XML incomplet ou non valide. Exception : {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Si è verificato un problema durante l'analisi di {0}, probabilmente a causa di codice XML incompleto o non valido. Eccezione: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">{0} の解析で問題が発生しました。不完全または無効な XML が原因である可能性があります。例外: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">{0}을(를) 구문 분석하는 중 문제가 발생했습니다. XML이 불완전하거나 잘못된 것 같습니다. 예외: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Wystąpił problem podczas analizowania pliku {0}. Prawdopodobnie jest to spowodowane niekompletnym lub nieprawidłowym kodem XML. Wyjątek: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Ocorreu um problema ao analisar {0}. Isso provavelmente se deve a XML incompleto ou inválido. Exceção: {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ When it appears in the middle of a sentence, "lint" is not capitalized.
{1} - The literal name of the MSBuild property
{2} - The lint version number</note>
</trans-unit>
<trans-unit id="XA0124">
<source>Interpreter is not supported by the x86 ABI</source>
<target state="new">Interpreter is not supported by the x86 ABI</target>
<note />
</trans-unit>
<trans-unit id="XA1000">
<source>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</source>
<target state="translated">Возникла проблема при синтаксическом анализе {0}. Возможная причина: неполный или недопустимый код XML. Исключение: {1}</target>
Expand Down
Loading

0 comments on commit 42822e0

Please sign in to comment.