From 6682f325bc40d07a96a37863fb780a79bdb54c32 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 18 Nov 2020 19:52:28 -0500 Subject: [PATCH 1/4] Enables the interpreter on iOS To enable on tests, you can pass MonoForceInterpreter=true as an extra MSBuild property. AppleAppBuilder will also have a ForceInterpreter property on it in order to flow down to device / simulator. Additionally, removed eventpipe from iOS when TargetsiOSSimulator == true as it was asserting for debug builds. --- eng/testing/tests.mobile.targets | 1 + src/mono/mono.proj | 9 +++------ src/mono/netcore/sample/iOS/Program.csproj | 1 + .../AppleAppBuilder/AppleAppBuilder.cs | 14 ++++++++++++-- .../AppleAppBuilder/Templates/runtime.m | 9 ++++++--- .../tasks/mobile.tasks/AppleAppBuilder/Xcode.cs | 14 ++++++++++++-- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 48ebda72e48bd4..ef94fd017269ac 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -116,6 +116,7 @@ MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0" Assemblies="@(BundleAssemblies)" MainLibraryFileName="AppleTestRunner.dll" + ForceInterpreter="$(MonoForceInterpreter)" UseConsoleUITemplate="True" GenerateXcodeProject="True" BuildAppBundle="True" diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 7726c9b21b235f..a5f91925e81686 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -222,14 +222,11 @@ - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=com,remoting,shared_perfcounters,gac"/> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=com,remoting,shared_perfcounters,eventpipe,gac"/> - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,interpreter,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac,eventpipe" /> - <_MonoCMakeArgs Include="-DENABLE_INTERP_LIB=1"/> - <_MonoCMakeArgs Include="-DDISABLE_ICALL_TABLES=1"/> - <_MonoCMakeArgs Include="-DENABLE_ICALL_EXPORT=0"/> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac,eventpipe" /> <_MonoCMakeArgs Include="-DENABLE_VISIBILITY_HIDDEN=1"/> <_MonoCMakeArgs Include="-DENABLE_LAZY_GC_THREAD_CREATION=1"/> <_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=0"/> @@ -419,7 +416,7 @@ <_MonoRuntimeFilePath Condition="'$(TargetsBrowser)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.a <_MonoRuntimeFilePath Condition="'$(_MonoRuntimeFilePath)' == ''">$(MonoObjDir)out\lib\libmonosgen-2.0.so <_MonoRuntimeStaticFilePath Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsAndroid)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.a - <_MonoIncludeInterpStaticFiles Condition="'$(TargetsBrowser)' == 'true' or ('$(TargetsiOS)' == 'true' and '$(TargetsiOSSimulator)' != 'true')">true + <_MonoIncludeInterpStaticFiles Condition="'$(TargetsBrowser)' == 'true'">true <_MonoAotCrossFilePath >$(MonoObjDir)cross\out\bin\mono-sgen diff --git a/src/mono/netcore/sample/iOS/Program.csproj b/src/mono/netcore/sample/iOS/Program.csproj index 1a7d5513bf140c..60d9604b722686 100644 --- a/src/mono/netcore/sample/iOS/Program.csproj +++ b/src/mono/netcore/sample/iOS/Program.csproj @@ -72,6 +72,7 @@ OutputDirectory="$(AppDir)" Optimized="$(Optimized)" UseAotForSimulator="$(UseAotForSimulator)" + ForceInterpreter="$(MonoForceInterpreter)" AppDir="$(MSBuildThisFileDirectory)$(PublishDir)"> diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs b/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs index 70666510629534..24723adc9fe7a0 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -101,6 +101,11 @@ public class AppleAppBuilderTask : Task /// public bool UseAotForSimulator { get; set; } + /// + /// Forces the runtime to use the interpreter + /// + public bool ForceInterpreter { get; set; } + /// /// Path to xcode project /// @@ -149,15 +154,20 @@ public override bool Execute() } } - if ((isDevice || UseAotForSimulator) && !assemblerFiles.Any()) + if (((!ForceInterpreter && (isDevice || UseAotForSimulator)) && !assemblerFiles.Any())) { throw new InvalidOperationException("Need list of AOT files for device builds."); } + if (ForceInterpreter && UseAotForSimulator) + { + throw new InvalidOperationException("Interpreter and AOT cannot be enabled at the same time"); + } + if (GenerateXcodeProject) { XcodeProjectPath = Xcode.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, - AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, UseAotForSimulator, Optimized, NativeMainSource); + AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, UseAotForSimulator, ForceInterpreter, Optimized, NativeMainSource); if (BuildAppBundle) { diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m index ba8b39c54533ba..70afd67e916cc0 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Templates/runtime.m @@ -196,7 +196,7 @@ //%DllMap% } -#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) +#if FORCE_INTERPRETER || (TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR)) void mono_jit_set_aot_mode (MonoAotMode mode); void register_aot_modules (void); #endif @@ -228,7 +228,10 @@ // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES monovm_initialize(0, NULL, NULL); -#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) +#if FORCE_INTERPRETER + os_log_info (OS_LOG_DEFAULT, "INTERP Enabled"); + mono_jit_set_aot_mode (MONO_AOT_MODE_INTERP_ONLY); +#elif TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) register_dllmap (); // register modules register_aot_modules (); @@ -249,7 +252,7 @@ } mono_jit_init_version ("dotnet.ios", "mobile"); -#if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) +#if !FORCE_INTERPRETER && TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || USE_AOT_FOR_SIMULATOR) // device runtimes are configured to use lazy gc thread creation MONO_ENTER_GC_UNSAFE; mono_gc_init_finalizer_thread (); diff --git a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs index 2184137982d187..41b19753b93aa6 100644 --- a/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs +++ b/tools-local/tasks/mobile.tasks/AppleAppBuilder/Xcode.cs @@ -21,6 +21,7 @@ public static string GenerateXCode( bool preferDylibs, bool useConsoleUiTemplate, bool useAotForSimulator, + bool forceInterpreter, bool stripDebugSymbols, string? nativeMainSource = null) { @@ -86,8 +87,17 @@ public static string GenerateXCode( cmakeLists = cmakeLists.Replace("%NativeLibrariesToLink%", toLink); cmakeLists = cmakeLists.Replace("%AotSources%", aotSources); cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); - cmakeLists = cmakeLists.Replace("%Defines%", - useAotForSimulator ? "add_definitions(-DUSE_AOT_FOR_SIMULATOR=1)" : ""); + + string defines = ""; + if (forceInterpreter) + { + defines = "add_definitions(-DFORCE_INTERPRETER=1)"; + } + else if (useAotForSimulator) + { + defines = "add_definitions(-DUSE_AOT_FOR_SIMULATOR=1)"; + } + cmakeLists = cmakeLists.Replace("%Defines%", defines); string plist = Utils.GetEmbeddedResource("Info.plist.template") .Replace("%BundleIdentifier%", projectName); From e0939959fc1ace14bbdcea4cc2f6dd9c957e845e Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 19 Nov 2020 09:10:04 -0500 Subject: [PATCH 2/4] Enable eventpipe and remove assert on event pipe listener. That will enable the debug configuration to work for the time being --- src/mono/mono.proj | 2 +- src/native/eventpipe/ds-ipc-posix.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index a5f91925e81686..d8bc2918024408 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -222,7 +222,7 @@ - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=com,remoting,shared_perfcounters,eventpipe,gac"/> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=com,remoting,shared_perfcounters,gac"/> diff --git a/src/native/eventpipe/ds-ipc-posix.c b/src/native/eventpipe/ds-ipc-posix.c index daa7d4220fe1f4..7adf3507544903 100644 --- a/src/native/eventpipe/ds-ipc-posix.c +++ b/src/native/eventpipe/ds-ipc-posix.c @@ -120,7 +120,6 @@ ipc_init_listener ( result_bind = bind (server_socket, server_address, server_address_len); DS_EXIT_BLOCKING_PAL_SECTION; - EP_ASSERT (result_bind != -1); if (result_bind == -1) { if (callback) callback (strerror (errno), errno); From 6a194ad8630bd41f8133ef7bac84027c3ddc2eab Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 19 Nov 2020 09:51:05 -0500 Subject: [PATCH 3/4] Enable eventpipe on ios devices too --- src/mono/mono.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index d8bc2918024408..898a4b59a45937 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -226,7 +226,7 @@ - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac,eventpipe" /> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac" /> <_MonoCMakeArgs Include="-DENABLE_VISIBILITY_HIDDEN=1"/> <_MonoCMakeArgs Include="-DENABLE_LAZY_GC_THREAD_CREATION=1"/> <_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=0"/> From bc56a7fd047ef9a786734c16bb904928156efcdf Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 19 Nov 2020 10:56:20 -0500 Subject: [PATCH 4/4] Turns out we needed to remove eventpipe from devices b/c of older sdk build failures --- src/mono/mono.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 898a4b59a45937..d8bc2918024408 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -226,7 +226,7 @@ - <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac" /> + <_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,com,jit,portability,assembly_remapping,attach,verifier,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters,gac,eventpipe" /> <_MonoCMakeArgs Include="-DENABLE_VISIBILITY_HIDDEN=1"/> <_MonoCMakeArgs Include="-DENABLE_LAZY_GC_THREAD_CREATION=1"/> <_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=0"/>