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

[Mono] Fix all the issues related to enabling WasmStripILAfterAOT #90436

Merged
merged 79 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
68dd32a
Enable IL trim for WASM by default
fanyang-mono Aug 11, 2023
7507121
Make ILStrip available for local build
fanyang-mono Aug 16, 2023
b02a8e5
Make all calling another method go through the logic to see if it cou…
fanyang-mono Aug 25, 2023
1f7b587
Add back accidentally removed line of code
fanyang-mono Aug 25, 2023
83cd21e
Update test to accommodate IL trim with WASM AOT
fanyang-mono Sep 5, 2023
1f2f152
Move jit_call_can_be_supported to mini-runtime, so it doesn't depends…
fanyang-mono Sep 6, 2023
d9027dd
Update var name
fanyang-mono Sep 7, 2023
481db67
Attempt to fix rebuild test failures
fanyang-mono Sep 11, 2023
aee3e0c
Attempt to fix the file open issue with unicode on windows
fanyang-mono Sep 12, 2023
ce6e2c0
Attempt to fix unicode issue #2
fanyang-mono Sep 12, 2023
b44c803
Enable g_fopen to have the capability of handling opening files with …
fanyang-mono Sep 13, 2023
159e7a1
Add comment
fanyang-mono Sep 13, 2023
dccc8bb
Update comment
fanyang-mono Sep 13, 2023
6ff2c63
Fix file indentation format
fanyang-mono Sep 13, 2023
ab352d4
Check if string contains non-ascii char
fanyang-mono Sep 13, 2023
ed07899
Remove unused callback
fanyang-mono Sep 13, 2023
98ad004
Remove redundant comment
fanyang-mono Sep 13, 2023
91edfdd
Update method name
fanyang-mono Sep 13, 2023
561dd40
Fixed some method not found issues and remove the optimization for g_…
fanyang-mono Sep 14, 2023
43aa032
Fix tailcall
fanyang-mono Sep 18, 2023
a4d901f
Disable tailcall optimization when calling a trimmed method
fanyang-mono Sep 19, 2023
a6f5bc2
Free method header
fanyang-mono Sep 19, 2023
b964fc4
Fix windows build error
fanyang-mono Sep 20, 2023
488676a
Free method header at the correct locatioin
fanyang-mono Sep 20, 2023
b3b03f5
Fix the condition of skipping tailcall
fanyang-mono Sep 21, 2023
e22b851
Fix test failure
fanyang-mono Sep 21, 2023
9964c82
Move JIT/AOT call invoke away from MINT_CALL, as it is not needed there.
fanyang-mono Sep 26, 2023
9bdceb1
Fix virtual tail call
fanyang-mono Oct 9, 2023
bf31655
Merge remote-tracking branch 'origin/main' into enable_il_trim_wasm_a…
fanyang-mono Oct 9, 2023
92773d3
Merge branch 'main' into enable_il_trim_wasm_always
fanyang-mono Oct 9, 2023
a6fa8c6
Address review feedback
fanyang-mono Oct 10, 2023
97ee332
Merge branch 'main' into enable_il_trim_wasm_always
fanyang-mono Oct 10, 2023
f5860d7
Put the trimmed assemblies in a new folder, output an updated list of…
fanyang-mono Oct 11, 2023
523bd20
Put trimmed assemblies in IntermediateOutputPath
fanyang-mono Oct 12, 2023
a39f0ee
Remove TrimmedAssemblies
fanyang-mono Oct 12, 2023
1ee9c57
Create trimmed assembly folder before the parallel run
fanyang-mono Oct 12, 2023
872c2ca
Try to fix the issue with missing item
fanyang-mono Oct 12, 2023
e51edf7
Fix parallelism issue
fanyang-mono Oct 12, 2023
b6fa669
Merge branch 'main' into enable_il_trim_wasm_always
fanyang-mono Oct 12, 2023
d6cb0ac
Only start the trim when the assembly is newer than the output
fanyang-mono Oct 16, 2023
2687449
Add assembly item to the list, when
fanyang-mono Oct 16, 2023
a133e9d
Add some logging
fanyang-mono Oct 18, 2023
ae5c260
Fixed runtimeconfig.json file path issue and disabed failed tests
fanyang-mono Oct 18, 2023
58ec329
Update parameter name
fanyang-mono Oct 18, 2023
288e186
Fix wasi build
fanyang-mono Oct 19, 2023
482ce8f
Use the correct parameter
fanyang-mono Oct 20, 2023
725dbfd
Merge branch 'main' into enable_il_trim_wasm_always
fanyang-mono Oct 20, 2023
11929f7
Fix runtime test failure
fanyang-mono Oct 20, 2023
968da46
Merge remote-tracking branch 'origin/main' into enable_il_trim_wasm_a…
radical Oct 23, 2023
a064c3a
WasmAppBuilder: runtimeconfig.json path can be null
radical Oct 23, 2023
117e6b3
cleanup
radical Oct 23, 2023
b15ef5b
ILStrip: fix typo in id name
radical Oct 23, 2023
cb975b8
Cleanup
radical Oct 23, 2023
1743fb9
ILStrip: ensure output assemblies are in the same order as the input.…
radical Oct 23, 2023
4919f5a
more cleanup
radical Oct 23, 2023
f9d07b1
Re-enable disabled tests
radical Oct 23, 2023
9de167c
Change the default value for WasmStripILAfterAOT to false
fanyang-mono Oct 27, 2023
1c9e04d
Fix the issue with changing the value of WasmStripILAfterAOT between …
fanyang-mono Nov 2, 2023
7764b25
Move the location of file deleting
fanyang-mono Nov 2, 2023
21a066a
Use WasmAssembliesFinal or ResolvedFileToPublish during publish in Wa…
maraf Nov 3, 2023
aeab3ce
Copy metadata in AOT compiler and when creating WasmAssembliesToBundl…
maraf Nov 6, 2023
e117b79
Add _WasmSatelliteAssemblies to WasmAssembliesFinal
maraf Nov 6, 2023
3f630a1
Add a wasm template test
fanyang-mono Nov 6, 2023
12cff3d
Include all non-dll ResolvedFileToPublish for ComputeWasmPublishAssets
maraf Nov 6, 2023
17085d9
Merge remote-tracking branch 'upstream/main' into fan/enable_il_trim_…
maraf Nov 7, 2023
ed84935
Add a blazor template test
fanyang-mono Nov 7, 2023
f2011f8
Address review feedback
fanyang-mono Nov 8, 2023
88d537b
Update src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs
fanyang-mono Nov 8, 2023
c4c3155
Update parameter name
fanyang-mono Nov 8, 2023
00b1f21
Update usage of parameter
fanyang-mono Nov 8, 2023
7b76c7e
Revert EmccCompile change
fanyang-mono Nov 9, 2023
977f49d
Merge remote-tracking branch 'origin/main' into enable_il_trim_wasm_a…
radical Nov 9, 2023
ada4f8b
MonoAOTCompiler: revert rebuilding when WasmStripILAfterAOT value cha…
radical Nov 10, 2023
4557eb4
Compress -> GZipCompress, and cleanup
radical Nov 10, 2023
9a7c37d
rework the tests
radical Nov 10, 2023
562d845
ILStrip.cs: Emit a message about stripping to make it obvious to the …
radical Nov 10, 2023
740bb45
WasmApp.targets: update comment
radical Nov 10, 2023
a93b5d1
Change default value to false and update test
fanyang-mono Nov 10, 2023
5fc92ca
Merge remote-tracking branch 'origin/main' into enable_il_trim_wasm_a…
fanyang-mono Nov 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,44 @@ public static void TestMethodBody()
{
MethodBase mbase = typeof(MethodBaseTests).GetMethod("MyOtherMethod", BindingFlags.Static | BindingFlags.Public);
MethodBody mb = mbase.GetMethodBody();
var codeSize = mb.GetILAsByteArray().Length;
Assert.True(mb.InitLocals); // local variables are initialized
#if DEBUG
Assert.Equal(2, mb.MaxStackSize);
Assert.Equal(3, mb.LocalVariables.Count);

foreach (LocalVariableInfo lvi in mb.LocalVariables)
if (codeSize == 0)
{
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
if (lvi.LocalIndex == 2) { Assert.Equal(typeof(bool), lvi.LocalType); }
}
// This condition is needed for running this test under WASM AOT mode.
// Because IL trim is enabled be default for WASM apps whenever AOT is enabled.
// And the method body of "MyOtherMethod" will be trimmed.
#if DEBUG
Assert.Equal(2, mb.MaxStackSize);
#else
Assert.Equal(1, mb.MaxStackSize);
Assert.Equal(2, mb.LocalVariables.Count);

foreach (LocalVariableInfo lvi in mb.LocalVariables)
{
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
Assert.Equal(1, mb.MaxStackSize);
#endif
Assert.Equal(0, mb.LocalVariables.Count);
}
else
{
#if DEBUG
Assert.Equal(2, mb.MaxStackSize);
Assert.Equal(3, mb.LocalVariables.Count);

foreach (LocalVariableInfo lvi in mb.LocalVariables)
{
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
if (lvi.LocalIndex == 2) { Assert.Equal(typeof(bool), lvi.LocalType); }
}
#else
Assert.Equal(1, mb.MaxStackSize);
Assert.Equal(2, mb.LocalVariables.Count);

foreach (LocalVariableInfo lvi in mb.LocalVariables)
{
if (lvi.LocalIndex == 0) { Assert.Equal(typeof(int), lvi.LocalType); }
if (lvi.LocalIndex == 1) { Assert.Equal(typeof(string), lvi.LocalType); }
}
#endif
}
}

private static int MyAnotherMethod(int x)
Expand Down
25 changes: 25 additions & 0 deletions src/mono/mono/eglib/gfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,28 @@ g_file_error_from_errno (gint err_no)
return G_FILE_ERROR_FAILED;
}
}

FILE *
g_fopen (const char *path, const char *mode)
{
FILE *fp;

if (!path)
return NULL;

#ifndef HOST_WIN32
fp = fopen (path, mode);
#else
gunichar2 *wPath = g_utf8_to_utf16 (path, -1, 0, 0, 0);
gunichar2 *wMode = g_utf8_to_utf16 (mode, -1, 0, 0, 0);

if (!wPath || !wMode)
return NULL;

fp = _wfopen ((wchar_t *) wPath, (wchar_t *) wMode);
g_free (wPath);
g_free (wMode);
#endif

return fp;
}
1 change: 1 addition & 0 deletions src/mono/mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ typedef enum {

G_ENUM_FUNCTIONS (GFileTest)

FILE * g_fopen (const char *path, const char *mode);
gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GError **gerror);
GFileError g_file_error_from_errno (gint err_no);
gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **gerror);
Expand Down
13 changes: 9 additions & 4 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9885,10 +9885,15 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method)
mono_atomic_inc_i32 (&acfg->stats.ccount);

if (acfg->aot_opts.trimming_eligible_methods_outfile && acfg->trimming_eligible_methods_outfile != NULL) {
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)) {
// 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.
if (!mono_method_is_generic_impl (method) && method->token != 0 && !cfg->deopt && !cfg->interp_entry_only) {
// 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.
// 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.
fprintf (acfg->trimming_eligible_methods_outfile, "%x\n", method->token);
gboolean skip_trim = FALSE;
if (acfg->aot_opts.interp) {
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));
}
if (!skip_trim)
fprintf (acfg->trimming_eligible_methods_outfile, "%x\n", method->token);
}
}
}
Expand Down Expand Up @@ -14917,7 +14922,7 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
}

if (acfg->aot_opts.trimming_eligible_methods_outfile && acfg->dedup_phase != DEDUP_COLLECT) {
acfg->trimming_eligible_methods_outfile = fopen (acfg->aot_opts.trimming_eligible_methods_outfile, "w+");
acfg->trimming_eligible_methods_outfile = g_fopen (acfg->aot_opts.trimming_eligible_methods_outfile, "w");
if (!acfg->trimming_eligible_methods_outfile)
aot_printerrf (acfg, "Unable to open trimming-eligible-methods-outfile specified file %s\n", acfg->aot_opts.trimming_eligible_methods_outfile);
else {
Expand Down
1 change: 0 additions & 1 deletion src/mono/mono/mini/ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ typedef gpointer MonoInterpFrameHandle;
MONO_EE_CALLBACK (void, entry_llvmonly, (gpointer res, gpointer *args, gpointer imethod)) \
MONO_EE_CALLBACK (gpointer, get_interp_method, (MonoMethod *method)) \
MONO_EE_CALLBACK (MonoJitInfo*, compile_interp_method, (MonoMethod *method, MonoError *error)) \
MONO_EE_CALLBACK (gboolean, jit_call_can_be_supported, (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only)) \

typedef struct _MonoEECallbacks {

Expand Down
6 changes: 0 additions & 6 deletions src/mono/mono/mini/interp-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,6 @@ stub_compile_interp_method (MonoMethod *method, MonoError *error)
return NULL;
}

static gboolean
stub_jit_call_can_be_supported (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only)
{
return TRUE;
}

#undef MONO_EE_CALLBACK
#define MONO_EE_CALLBACK(ret, name, sig) stub_ ## name,

Expand Down
3 changes: 0 additions & 3 deletions src/mono/mono/mini/interp/interp-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ mono_mint_type (MonoType *type);
int
mono_interp_type_size (MonoType *type, int mt, int *align_p);

gboolean
interp_jit_call_can_be_supported (MonoMethod *method, MonoMethodSignature *sig, gboolean is_llvm_only);

#if HOST_BROWSER

gboolean
Expand Down
Loading
Loading