Skip to content

Commit 085ddb7

Browse files
fanyang-monoradicalmaraf
authored
[Mono] Fix all the issues related to enabling WasmStripILAfterAOT (dotnet#90436)
* Enable IL trim for WASM by default * Make ILStrip available for local build * Make all calling another method go through the logic to see if it could call an AOT'ed version of it before trying to interp compile it * Add back accidentally removed line of code * Update test to accommodate IL trim with WASM AOT * Move jit_call_can_be_supported to mini-runtime, so it doesn't depends on the value of mono_use_interpreter * Update var name * Attempt to fix rebuild test failures * Attempt to fix the file open issue with unicode on windows * Attempt to fix unicode issue #2 * Enable g_fopen to have the capability of handling opening files with unicode name on all platforms * Add comment * Update comment * Fix file indentation format * Check if string contains non-ascii char * Remove unused callback * Remove redundant comment * Update method name * Fixed some method not found issues and remove the optimization for g_fopen * Fix tailcall * Disable tailcall optimization when calling a trimmed method * Free method header * Fix windows build error * Free method header at the correct locatioin * Fix the condition of skipping tailcall * Fix test failure * Move JIT/AOT call invoke away from MINT_CALL, as it is not needed there. * Fix virtual tail call * Address review feedback * Put the trimmed assemblies in a new folder, output an updated list of assemblies and update _WasmAssembliesInternal with the new list * Put trimmed assemblies in IntermediateOutputPath * Remove TrimmedAssemblies * Create trimmed assembly folder before the parallel run * Try to fix the issue with missing item * Fix parallelism issue * Only start the trim when the assembly is newer than the output * Add assembly item to the list, when * Add some logging * Fixed runtimeconfig.json file path issue and disabed failed tests * Update parameter name * Fix wasi build * Use the correct parameter * Fix runtime test failure * WasmAppBuilder: runtimeconfig.json path can be null * cleanup * ILStrip: fix typo in id name * Cleanup * ILStrip: ensure output assemblies are in the same order as the input. This is required for incremental builds. * more cleanup * Re-enable disabled tests * Change the default value for WasmStripILAfterAOT to false * Fix the issue with changing the value of WasmStripILAfterAOT between incremental builds * Move the location of file deleting * Use WasmAssembliesFinal or ResolvedFileToPublish during publish in WasmSDK * Copy metadata in AOT compiler and when creating WasmAssembliesToBundle from ResolvedFileToPublish * Add _WasmSatelliteAssemblies to WasmAssembliesFinal * Add a wasm template test * Include all non-dll ResolvedFileToPublish for ComputeWasmPublishAssets * Add a blazor template test * Address review feedback * Update src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs Co-authored-by: Ankit Jain <[email protected]> * Update parameter name * Update usage of parameter * Revert EmccCompile change * MonoAOTCompiler: revert rebuilding when WasmStripILAfterAOT value changes * Compress -> GZipCompress, and cleanup * rework the tests - to support webcil case - run blazor app - add cases for the default setting, and the opposite - cleanup * ILStrip.cs: Emit a message about stripping to make it obvious to the user * WasmApp.targets: update comment * Change default value to false and update test --------- Co-authored-by: Ankit Jain <[email protected]> Co-authored-by: Marek Fišera <[email protected]>
1 parent 0e6e35f commit 085ddb7

File tree

23 files changed

+475
-184
lines changed

23 files changed

+475
-184
lines changed

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,44 @@ public static void TestMethodBody()
5555
{
5656
MethodBase mbase = typeof(MethodBaseTests).GetMethod("MyOtherMethod", BindingFlags.Static | BindingFlags.Public);
5757
MethodBody mb = mbase.GetMethodBody();
58+
var codeSize = mb.GetILAsByteArray().Length;
5859
Assert.True(mb.InitLocals); // local variables are initialized
59-
#if DEBUG
60-
Assert.Equal(2, mb.MaxStackSize);
61-
Assert.Equal(3, mb.LocalVariables.Count);
6260

63-
foreach (LocalVariableInfo lvi in mb.LocalVariables)
61+
if (codeSize == 0)
6462
{
65-
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
66-
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
67-
if (lvi.LocalIndex == 2) { Assert.Equal(typeof(bool), lvi.LocalType); }
68-
}
63+
// This condition is needed for running this test under WASM AOT mode.
64+
// Because IL trim is enabled be default for WASM apps whenever AOT is enabled.
65+
// And the method body of "MyOtherMethod" will be trimmed.
66+
#if DEBUG
67+
Assert.Equal(2, mb.MaxStackSize);
6968
#else
70-
Assert.Equal(1, mb.MaxStackSize);
71-
Assert.Equal(2, mb.LocalVariables.Count);
72-
73-
foreach (LocalVariableInfo lvi in mb.LocalVariables)
74-
{
75-
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
76-
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
69+
Assert.Equal(1, mb.MaxStackSize);
70+
#endif
71+
Assert.Equal(0, mb.LocalVariables.Count);
7772
}
73+
else
74+
{
75+
#if DEBUG
76+
Assert.Equal(2, mb.MaxStackSize);
77+
Assert.Equal(3, mb.LocalVariables.Count);
78+
79+
foreach (LocalVariableInfo lvi in mb.LocalVariables)
80+
{
81+
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
82+
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
83+
if (lvi.LocalIndex == 2) { Assert.Equal(typeof(bool), lvi.LocalType); }
84+
}
85+
#else
86+
Assert.Equal(1, mb.MaxStackSize);
87+
Assert.Equal(2, mb.LocalVariables.Count);
88+
89+
foreach (LocalVariableInfo lvi in mb.LocalVariables)
90+
{
91+
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
92+
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
93+
}
7894
#endif
95+
}
7996
}
8097

8198
private static int MyAnotherMethod(int x)

src/mono/mono/eglib/gfile.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,28 @@ g_file_error_from_errno (gint err_no)
104104
return G_FILE_ERROR_FAILED;
105105
}
106106
}
107+
108+
FILE *
109+
g_fopen (const char *path, const char *mode)
110+
{
111+
FILE *fp;
112+
113+
if (!path)
114+
return NULL;
115+
116+
#ifndef HOST_WIN32
117+
fp = fopen (path, mode);
118+
#else
119+
gunichar2 *wPath = g_utf8_to_utf16 (path, -1, 0, 0, 0);
120+
gunichar2 *wMode = g_utf8_to_utf16 (mode, -1, 0, 0, 0);
121+
122+
if (!wPath || !wMode)
123+
return NULL;
124+
125+
fp = _wfopen ((wchar_t *) wPath, (wchar_t *) wMode);
126+
g_free (wPath);
127+
g_free (wMode);
128+
#endif
129+
130+
return fp;
131+
}

src/mono/mono/eglib/glib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ typedef enum {
962962

963963
G_ENUM_FUNCTIONS (GFileTest)
964964

965+
FILE * g_fopen (const char *path, const char *mode);
965966
gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **gerror);
966967
GFileError g_file_error_from_errno (gint err_no);
967968
gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **gerror);

src/mono/mono/mini/aot-compiler.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9885,10 +9885,15 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method)
98859885
mono_atomic_inc_i32 (&acfg->stats.ccount);
98869886

98879887
if (acfg->aot_opts.trimming_eligible_methods_outfile && acfg->trimming_eligible_methods_outfile != NULL) {
9888-
if (!mono_method_is_generic_impl (method) && method->token != 0 && !cfg->deopt && !cfg->interp_entry_only && mini_get_interp_callbacks ()->jit_call_can_be_supported (method, mono_method_signature_internal (method), acfg->aot_opts.llvm_only)) {
9889-
// The call back to jit_call_can_be_supported is necessary for WASM, because it would still interprete some methods sometimes even though they were already AOT'ed.
9888+
if (!mono_method_is_generic_impl (method) && method->token != 0 && !cfg->deopt && !cfg->interp_entry_only) {
9889+
// The call to mono_jit_call_can_be_supported_by_interp is necessary for WASM, because it would still interprete some methods sometimes even though they were already AOT'ed.
98909890
// When that happens, interpreter needs to have the capability to call the AOT'ed version of that method, since the method body has already been trimmed.
9891-
fprintf (acfg->trimming_eligible_methods_outfile, "%x\n", method->token);
9891+
gboolean skip_trim = FALSE;
9892+
if (acfg->aot_opts.interp) {
9893+
skip_trim = (!mono_jit_call_can_be_supported_by_interp (method, mono_method_signature_internal (method), acfg->aot_opts.llvm_only) || (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED));
9894+
}
9895+
if (!skip_trim)
9896+
fprintf (acfg->trimming_eligible_methods_outfile, "%x\n", method->token);
98929897
}
98939898
}
98949899
}
@@ -14917,7 +14922,7 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1491714922
}
1491814923

1491914924
if (acfg->aot_opts.trimming_eligible_methods_outfile && acfg->dedup_phase != DEDUP_COLLECT) {
14920-
acfg->trimming_eligible_methods_outfile = fopen (acfg->aot_opts.trimming_eligible_methods_outfile, "w+");
14925+
acfg->trimming_eligible_methods_outfile = g_fopen (acfg->aot_opts.trimming_eligible_methods_outfile, "w");
1492114926
if (!acfg->trimming_eligible_methods_outfile)
1492214927
aot_printerrf (acfg, "Unable to open trimming-eligible-methods-outfile specified file %s\n", acfg->aot_opts.trimming_eligible_methods_outfile);
1492314928
else {

src/mono/mono/mini/ee.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ typedef gpointer MonoInterpFrameHandle;
6565
MONO_EE_CALLBACK (void, entry_llvmonly, (gpointer res, gpointer *args, gpointer imethod)) \
6666
MONO_EE_CALLBACK (gpointer, get_interp_method, (MonoMethod *method)) \
6767
MONO_EE_CALLBACK (MonoJitInfo*, compile_interp_method, (MonoMethod *method, MonoError *error)) \
68-
MONO_EE_CALLBACK (gboolean, jit_call_can_be_supported, (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only)) \
6968

7069
typedef struct _MonoEECallbacks {
7170

src/mono/mono/mini/interp-stubs.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,6 @@ stub_compile_interp_method (MonoMethod *method, MonoError *error)
252252
return NULL;
253253
}
254254

255-
static gboolean
256-
stub_jit_call_can_be_supported (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only)
257-
{
258-
return TRUE;
259-
}
260-
261255
#undef MONO_EE_CALLBACK
262256
#define MONO_EE_CALLBACK(ret, name, sig) stub_ ## name,
263257

src/mono/mono/mini/interp/interp-internals.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ mono_mint_type (MonoType *type);
320320
int
321321
mono_interp_type_size (MonoType *type, int mt, int *align_p);
322322

323-
gboolean
324-
interp_jit_call_can_be_supported (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only);
325-
326323
#if HOST_BROWSER
327324

328325
gboolean

0 commit comments

Comments
 (0)