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

[mtouch] add mixed-mode support #4751

Merged
merged 8 commits into from
Sep 11, 2018
6 changes: 6 additions & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Tasks/MTouchTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public GccOptions ()
[Required]
public bool UseInterpreter { get; set; }

[Required]
public bool UseInterpreterMixed { get; set; }

[Required]
public bool LinkerDumpDependencies { get; set; }

Expand Down Expand Up @@ -408,6 +411,9 @@ protected override string GenerateCommandLineCommands ()
if (UseInterpreter)
args.Add ("--interpreter");

if (UseInterpreterMixed)
args.Add ("--interp-mixed");

switch (LinkMode.ToLowerInvariant ()) {
case "sdkonly": args.AddLine ("--linksdkonly"); break;
case "none": args.AddLine ("--nolink"); break;
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<MtouchProjectDirectory>$(MSBuildProjectDirectory)</MtouchProjectDirectory>
<MtouchEnableSGenConc Condition="'$(MtouchEnableSGenConc)' == ''">False</MtouchEnableSGenConc>
<MtouchUseInterpreter Condition="'$(MtouchUseInterpreter)' == ''">False</MtouchUseInterpreter>
<MtouchUseInterpreterMixed Condition="'$(MtouchUseInterpreterMixed)' == ''">False</MtouchUseInterpreterMixed>
<MtouchVerbosity Condition="$(MtouchVerbosity) == ''">2</MtouchVerbosity>

<IsMacEnabled>true</IsMacEnabled>
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
EnableBitcode="$(MtouchEnableBitcode)"
EnableSGenConc="$(MtouchEnableSGenConc)"
UseInterpreter="$(MtouchUseInterpreter)"
UseInterpreterMixed="$(MtouchUseInterpreterMixed)"
AppExtensionReferences="@(_ResolvedAppExtensionReferences)"
ArchiveSymbols="$(MonoSymbolArchive)"
Verbosity="$(MtouchVerbosity)"
Expand Down
3 changes: 3 additions & 0 deletions tests/xharness/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ IEnumerable<TestData> GetTestData (RunTestTask test)
yield return new TestData { Variation = "Release (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all", Debug = false, Profiling = false, Defines = "OPTIMIZEALL" };
yield return new TestData { Variation = "Debug (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all", Debug = true, Profiling = false, Defines = "OPTIMIZEALL" };
yield return new TestData { Variation = "Debug (interpreter)", MTouchExtraArgs = "--interpreter", Debug = true, Profiling = false, Ignored = true, };
yield return new TestData { Variation = "Debug (interp-mixed)", MTouchExtraArgs = "--interp-mixed", Debug = true, Profiling = false, Ignored = true, };
break;
case "mscorlib":
yield return new TestData { Variation = "Debug (interpreter)", MTouchExtraArgs = "--interpreter", Debug = true, Profiling = false, Ignored = true, Undefines = "FULL_AOT_RUNTIME" };
yield return new TestData { Variation = "Debug (interp-mixed)", MTouchExtraArgs = "--interp-mixed", Debug = true, Profiling = false, Ignored = true, Undefines = "FULL_AOT_RUNTIME" };
break;
case "mini":
yield return new TestData { Variation = "Debug (interpreter)", MTouchExtraArgs = "--interpreter", Debug = true, Profiling = false, Undefines = "FULL_AOT_RUNTIME" };
yield return new TestData { Variation = "Debug (interp-mixed)", MTouchExtraArgs = "--interp-mixed", Debug = true, Profiling = false, Undefines = "FULL_AOT_RUNTIME" };
break;
}
break;
Expand Down
1 change: 1 addition & 0 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public partial class Application
public bool? EnableCoopGC;
public bool EnableSGenConc;
public bool UseInterpreter;
public bool UseInterpreterMixed;
public MarshalObjectiveCExceptionMode MarshalObjectiveCExceptions;
public MarshalManagedExceptionMode MarshalManagedExceptions;

Expand Down
5 changes: 3 additions & 2 deletions tools/mtouch/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public bool UseDlsym (string assembly)
if (EnableLLVMOnlyBitCode)
return false;

if (UseInterpreter)
if (UseInterpreter || UseInterpreterMixed)
return true;

switch (Platform) {
Expand Down Expand Up @@ -2124,7 +2124,8 @@ public void StripNativeCode ()

public void BundleAssemblies ()
{
var strip = !UseInterpreter && ManagedStrip && IsDeviceBuild && !EnableDebug && !PackageManagedDebugSymbols;
/* TODO: must be more fine-grained for UseInterpreterMixed case */
var strip = !UseInterpreter && !UseInterpreterMixed && ManagedStrip && IsDeviceBuild && !EnableDebug && !PackageManagedDebugSymbols;

var grouped = Targets.SelectMany ((Target t) => t.Assemblies).GroupBy ((Assembly asm) => asm.Identity);
foreach (var @group in grouped) {
Expand Down
5 changes: 5 additions & 0 deletions tools/mtouch/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public bool IsAOTCompiled {
/* interpreter only requires a few stubs that are attached
* to mscorlib.dll, other assemblies won't be AOT compiled */
return FileName == "mscorlib.dll";
if (App.UseInterpreterMixed)
/* TODO: for now, only (fully) AOT compile mscorlib.dll. We
* need an additional option to drive what assemblies
* should be AOT compiled */
return FileName == "mscorlib.dll";
return true;
}
}
Expand Down
7 changes: 6 additions & 1 deletion tools/mtouch/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,11 @@ void AOTCompile ()
if (App.UseInterpreter)
return;

if (App.UseInterpreterMixed)
/* TODO: not sure? we might have to continue here, depending on
* the set of assemblies are AOT'd? */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, that condition is can't work if we're mixing

return;

// Code in one assembly (either in a P/Invoke or a third-party library) can depend on a third-party library in another assembly.
// This means that we must always build assemblies only when all their dependent assemblies have been built, so that
// we can link (natively) with the frameworks/dylibs for those dependent assemblies.
Expand Down Expand Up @@ -1484,7 +1489,7 @@ public void NativeLink (BuildTasks build_tasks)
}
}

if (App.UseInterpreter) {
if (App.UseInterpreter || App.UseInterpreterMixed) {
string libinterp = Path.Combine (libdir, "libmono-ee-interp.a");
linker_flags.AddLinkWith (libinterp);
string libicalltable = Path.Combine (libdir, "libmono-icall-table.a");
Expand Down
10 changes: 7 additions & 3 deletions tools/mtouch/mtouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ public static string GetAotArguments (Application app, string filename, Abi abi,
bool enable_debug_symbols = app.PackageManagedDebugSymbols;
bool llvm_only = app.EnableLLVMOnlyBitCode;
bool interp = app.UseInterpreter;
bool interp_mixed = app.UseInterpreterMixed;
bool is32bit = (abi & Abi.Arch32Mask) > 0;
string arch = abi.AsArchString ();

Expand All @@ -476,6 +477,8 @@ public static string GetAotArguments (Application app, string filename, Abi abi,
args.Append ("llvmonly,");
else if (interp)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add an assert here, interp should only be true of fname == "mscorlib.dll" is true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mean that interp_full should only be true if name == "mscorlib.dll"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, other assemblies than mscorlib.dll are vaild with --aot=interp,full too, as it will add wrappers specific to signatures seen during AOT compilation that are necessary for the AOT<>interpreter transitions.

However, --aot=interp only makes sense for mscorlib.dll. At least that's how it's supposed to work, I should double check that on the mono side: mono/mono#10543

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see your point, for other interpreted assemblies this method (GetAotArguments) shouldn't be called at all.

args.Append ("interp,");
else if (interp_mixed)
args.Append ("interp,full,");
else
args.Append ("full,");

Expand Down Expand Up @@ -641,7 +644,7 @@ public static string GenerateMain (Application app, IEnumerable<Assembly> assemb
sw.WriteLine ("xamarin_profiler_symbol_def xamarin_profiler_symbol = NULL;");
}

if (app.UseInterpreter) {
if (app.UseInterpreter || app.UseInterpreterMixed) {
sw.WriteLine ("extern \"C\" { void mono_ee_interp_init (const char *); }");
sw.WriteLine ("extern \"C\" { void mono_icall_table_init (void); }");
sw.WriteLine ("extern \"C\" { void mono_marshal_ilgen_init (void); }");
Expand All @@ -657,7 +660,7 @@ public static string GenerateMain (Application app, IEnumerable<Assembly> assemb

if (app.EnableLLVMOnlyBitCode)
sw.WriteLine ("\tmono_jit_set_aot_mode (MONO_AOT_MODE_LLVMONLY);");
else if (app.UseInterpreter) {
else if (app.UseInterpreter || app.UseInterpreterMixed) {
sw.WriteLine ("\tmono_icall_table_init ();");
sw.WriteLine ("\tmono_marshal_ilgen_init ();");
sw.WriteLine ("\tmono_method_builder_ilgen_init ();");
Expand Down Expand Up @@ -866,7 +869,7 @@ public static bool CanWeSymlinkTheApplication (Application app)
if (app.EnableSGenConc)
return false;

if (app.UseInterpreter)
if (app.UseInterpreter || app.UseInterpreterMixed)
return false;

if (app.Registrar == RegistrarMode.Static)
Expand Down Expand Up @@ -1248,6 +1251,7 @@ static Application ParseArguments (string [] args, out Action a)
}
},
{ "interpreter", "Enable the *experimental* interpreter.", v => { app.UseInterpreter = true; }},
{ "interp-mixed", "Enable the *experimental* interpreter mixed with AOT mode.", v => { app.UseInterpreterMixed = true; }},
{ "http-message-handler=", "Specify the default HTTP message handler for HttpClient", v => { http_message_handler = v; }},
{ "output-format=", "Specify the output format for some commands. Possible values: Default, XML", v =>
{
Expand Down