-
Notifications
You must be signed in to change notification settings - Fork 516
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
Reenable dedup optimization for all AOT modes #20936
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this! Looking good! 👍
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
This reverts commit 3d5c55e.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
/sudo backport net9.0 |
/sudo backport release/8.0.1xx-xcode15.4 |
Backport Job to branch net9.0 Created! The magic is happening here |
Backport Job to branch release/8.0.1xx-xcode15.4 Created! The magic is happening here |
Hooray! Backport succeeded! Please see https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9941761 for more details. |
Hooray! Backport succeeded! Please see https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9941764 for more details. |
This comment has been minimized.
This comment has been minimized.
💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11) passed 💻✅ All tests on macOS M1 - Mac Big Sur (11) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
💻 [CI Build] Windows Integration Tests passed 💻✅ All Windows Integration Tests passed. Pipeline on Agent |
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 168 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
…odes (#20940) ## Description As part of the fix for: dotnet/runtime#99248 we disabled dedup optimization in partial/hybrid AOT mode (when both interpreter and AOT compiler are enabled). This change got backported to .NET 8 and with the latest servicing release regressed build times and app sizes significantly as reported in: #20848 However, it turns out that disabling dedup optimization is not required to fix dotnet/runtime#99248 but instead we should correct the Xamarin SDK integration with this optimization which this PR is doing. The following section describes the initial problem in more details. ## Overview of AOT modes and dedup optimization When the repro project from dotnet/runtime#99248 is built with dedup enabled in hybrid AOT+interpreter mode, the app crashes with: ``` 024-07-23 14:32:37.524110+0200 IvansApp[12711:20244208] debug: AOT NOT FOUND: (wrapper other) object:gsharedvt_out_sig (intptr). 2024-07-23 14:32:37.524120+0200 IvansApp[12711:20244208] error: * Assertion at /Users/ivan/repos/runtime-mono-iOS/src/mono/mono/mini/interp/interp.c:2667, condition `is_ok (error)' not met, function:init_jit_call_info, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information. ``` To track down why these wrappers which are used to transition from interpreter to AOT code, are not generated we need to understand when they are compiled in different AOT modes with and without dedup optimization enabled: - In full AOT setup - all assemblies AOT compiled - `gsharedvt_out_sig` methods are never generated - In hybrid AOT + interpreter setup - all assemblies AOT compiled: `MtouchInterpreter=-all` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT images of every assembly (to enable interpreter calling into each specific assembly - here wrappers with same signatures are duplicated) - Dedup ON: - `gsharedvt_out_sig` methods are generated only in `aot-instances` AOT image - during AOT compilation of individual assemblies generation of `gsharedvt_out_sig` is skipped - during AOT compilation of `aot-instances` assembly we collect all `gsharedvt_out_sig` variants from the full program scope and generate code for them in `aot-instances` AOT image - In hybrid AOT + interpreter setup - all assemblies interpreted except a given assembly: `MtouchInterpreter=all,-MyAssembly` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT image of `MyAssembly` (to enable interpreter calling into it) - Dedup ON: <- $${\color{red} ISSUE }$$ - `gsharedvt_out_sig` methods *should* be generated only in `aot-instances` AOT image, but the `aot-instances` image is missing - explanation: - what happens is that generation of `gsharedvt_out_sig` is skipped during AOT compilation of `MyAssembly` (as expected). - But, the build does not mark `aot-instances` assembly as the one that should be AOT compiled. - The reason for this is that we have a global `_IsDedupEnabled` flag, but when custom linker step analysis `aot-instances.dll` it does not see it as an assembly which should not be interpreted. - To explain that better: we mark *all* assemblies as to be interpreted (via: `MtouchInterpreter=all`), but exclude only `MyAssembly` (via: `MtouchInterpreter=all,-MyAssembly`). - So when custom linker step processes `aot-instaces.dll` it treats it as an assembly to be interpreted, so it does not mark it for AOT compilation. - This further results with `aot-instances` AOT image missing, and all the methods which we skipped during AOT compilation never get generated. ## The fix To fix this and address regressions reported in: #20848 we are reenabling dedup optimization whenever AOT compilation is requested and fixing the issue where the custom linker step for generating AOT parameters always treates the dedup assembly as the one to be AOTed. Once approved this should be backported to .NET 8 as servicing releases are also affected with it. Backport of #20936 --------- Co-authored-by: Ivan Povazan <[email protected]> Co-authored-by: GitHub Actions Autoformatter <[email protected]>
Backport of #20936 --- ## Description As part of the fix for: dotnet/runtime#99248 we disabled dedup optimization in partial/hybrid AOT mode (when both interpreter and AOT compiler are enabled). This change got backported to .NET 8 and with the latest servicing release regressed build times and app sizes significantly as reported in: #20848 However, it turns out that disabling dedup optimization is not required to fix dotnet/runtime#99248 but instead we should correct the Xamarin SDK integration with this optimization which this PR is doing. The following section describes the initial problem in more details. ## Overview of AOT modes and dedup optimization When the repro project from dotnet/runtime#99248 is built with dedup enabled in hybrid AOT+interpreter mode, the app crashes with: ``` 024-07-23 14:32:37.524110+0200 IvansApp[12711:20244208] debug: AOT NOT FOUND: (wrapper other) object:gsharedvt_out_sig (intptr). 2024-07-23 14:32:37.524120+0200 IvansApp[12711:20244208] error: * Assertion at /Users/ivan/repos/runtime-mono-iOS/src/mono/mono/mini/interp/interp.c:2667, condition `is_ok (error)' not met, function:init_jit_call_info, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information. ``` To track down why these wrappers which are used to transition from interpreter to AOT code, are not generated we need to understand when they are compiled in different AOT modes with and without dedup optimization enabled: - In full AOT setup - all assemblies AOT compiled - `gsharedvt_out_sig` methods are never generated - In hybrid AOT + interpreter setup - all assemblies AOT compiled: `MtouchInterpreter=-all` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT images of every assembly (to enable interpreter calling into each specific assembly - here wrappers with same signatures are duplicated) - Dedup ON: - `gsharedvt_out_sig` methods are generated only in `aot-instances` AOT image - during AOT compilation of individual assemblies generation of `gsharedvt_out_sig` is skipped - during AOT compilation of `aot-instances` assembly we collect all `gsharedvt_out_sig` variants from the full program scope and generate code for them in `aot-instances` AOT image - In hybrid AOT + interpreter setup - all assemblies interpreted except a given assembly: `MtouchInterpreter=all,-MyAssembly` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT image of `MyAssembly` (to enable interpreter calling into it) - Dedup ON: <- $${\color{red} ISSUE }$$ - `gsharedvt_out_sig` methods *should* be generated only in `aot-instances` AOT image, but the `aot-instances` image is missing - explanation: - what happens is that generation of `gsharedvt_out_sig` is skipped during AOT compilation of `MyAssembly` (as expected). - But, the build does not mark `aot-instances` assembly as the one that should be AOT compiled. - The reason for this is that we have a global `_IsDedupEnabled` flag, but when custom linker step analysis `aot-instances.dll` it does not see it as an assembly which should not be interpreted. - To explain that better: we mark *all* assemblies as to be interpreted (via: `MtouchInterpreter=all`), but exclude only `MyAssembly` (via: `MtouchInterpreter=all,-MyAssembly`). - So when custom linker step processes `aot-instaces.dll` it treats it as an assembly to be interpreted, so it does not mark it for AOT compilation. - This further results with `aot-instances` AOT image missing, and all the methods which we skipped during AOT compilation never get generated. ## The fix To fix this and address regressions reported in: #20848 we are reenabling dedup optimization whenever AOT compilation is requested and fixing the issue where the custom linker step for generating AOT parameters always treates the dedup assembly as the one to be AOTed. Once approved this should be backported to .NET 8 as servicing releases are also affected with it. --------- Co-authored-by: Ivan Povazan <[email protected]> Co-authored-by: GitHub Actions Autoformatter <[email protected]>
…talyst-x64` (#20946) Backport of #20945 --- ## Description This is a follow-up PR to: #20936 We should not enable dedup when targeting `maccatalyst-x64` because in case when the project file specifies `MtouchInterpreter=all,-System.Private.CoreLib`, the build will run the full AOT compiler with interpreter enabled. In this setup the runtime is configured to run in interp only mode: https://github.com/xamarin/xamarin-macios/blob/97a91cc4e3bf7cf8a4c657ca00ece620f2e28e91/tools/common/Target.cs#L812-L813 which means that during runtime, AOT images will be ignored - aot runtime will load them but mark them as unusuable since they are compiled with `full` compiler switch and the code falls back to interpreter (ref: https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2131-L2148 ) This is problematic for the `aot-instances` container image, which has a special handling at the runtime and does not accept it to be marked as unusable (we might want to revisit this in the future): https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2527-L2529 ## Changes This PR disables dedup optimization when targeting `maccatalyst-x64` and updates the required tests to match the behavior. --------- Co-authored-by: Ivan Povazan <[email protected]> Co-authored-by: GitHub Actions Autoformatter <[email protected]>
## Description This is a follow-up PR to: #20936 We should not enable dedup when targeting `maccatalyst-x64` because in case when the project file specifies `MtouchInterpreter=all,-System.Private.CoreLib`, the build will run the full AOT compiler with interpreter enabled. In this setup the runtime is configured to run in interp only mode: https://github.com/xamarin/xamarin-macios/blob/97a91cc4e3bf7cf8a4c657ca00ece620f2e28e91/tools/common/Target.cs#L812-L813 which means that during runtime, AOT images will be ignored - aot runtime will load them but mark them as unusuable since they are compiled with `full` compiler switch and the code falls back to interpreter (ref: https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2131-L2148 ) This is problematic for the `aot-instances` container image, which has a special handling at the runtime and does not accept it to be marked as unusable (we might want to revisit this in the future): https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2527-L2529 ## Changes This PR disables dedup optimization when targeting `maccatalyst-x64` and updates the required tests to match the behavior. --- Backports: - [x] #20946 - [x] Original reenabling of dedup for .NET 9 already includes these changes: #20941 --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
## Description As part of the fix for: dotnet/runtime#99248 we disabled dedup optimization in partial/hybrid AOT mode (when both interpreter and AOT compiler are enabled). This change got backported to .NET 8 and with the latest servicing release regressed build times and app sizes significantly as reported in: #20848 However, it turns out that disabling dedup optimization is not required to fix dotnet/runtime#99248 but instead we should correct the Xamarin SDK integration with this optimization which this PR is doing. The following section describes the initial problem in more details. ## Overview of AOT modes and dedup optimization When the repro project from dotnet/runtime#99248 is built with dedup enabled in hybrid AOT+interpreter mode, the app crashes with: ``` 024-07-23 14:32:37.524110+0200 IvansApp[12711:20244208] debug: AOT NOT FOUND: (wrapper other) object:gsharedvt_out_sig (intptr). 2024-07-23 14:32:37.524120+0200 IvansApp[12711:20244208] error: * Assertion at /Users/ivan/repos/runtime-mono-iOS/src/mono/mono/mini/interp/interp.c:2667, condition `is_ok (error)' not met, function:init_jit_call_info, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information. ``` To track down why these wrappers which are used to transition from interpreter to AOT code, are not generated we need to understand when they are compiled in different AOT modes with and without dedup optimization enabled: - In full AOT setup - all assemblies AOT compiled - `gsharedvt_out_sig` methods are never generated - In hybrid AOT + interpreter setup - all assemblies AOT compiled: `MtouchInterpreter=-all` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT images of every assembly (to enable interpreter calling into each specific assembly - here wrappers with same signatures are duplicated) - Dedup ON: - `gsharedvt_out_sig` methods are generated only in `aot-instances` AOT image - during AOT compilation of individual assemblies generation of `gsharedvt_out_sig` is skipped - during AOT compilation of `aot-instances` assembly we collect all `gsharedvt_out_sig` variants from the full program scope and generate code for them in `aot-instances` AOT image - In hybrid AOT + interpreter setup - all assemblies interpreted except a given assembly: `MtouchInterpreter=all,-MyAssembly` - Dedup OFF: - `gsharedvt_out_sig` methods are generated in AOT image of `MyAssembly` (to enable interpreter calling into it) - Dedup ON: <- $${\color{red} ISSUE }$$ - `gsharedvt_out_sig` methods *should* be generated only in `aot-instances` AOT image, but the `aot-instances` image is missing - explanation: - what happens is that generation of `gsharedvt_out_sig` is skipped during AOT compilation of `MyAssembly` (as expected). - But, the build does not mark `aot-instances` assembly as the one that should be AOT compiled. - The reason for this is that we have a global `_IsDedupEnabled` flag, but when custom linker step analysis `aot-instances.dll` it does not see it as an assembly which should not be interpreted. - To explain that better: we mark *all* assemblies as to be interpreted (via: `MtouchInterpreter=all`), but exclude only `MyAssembly` (via: `MtouchInterpreter=all,-MyAssembly`). - So when custom linker step processes `aot-instaces.dll` it treats it as an assembly to be interpreted, so it does not mark it for AOT compilation. - This further results with `aot-instances` AOT image missing, and all the methods which we skipped during AOT compilation never get generated. ## The fix To fix this and address regressions reported in: #20848 we are reenabling dedup optimization whenever AOT compilation is requested and fixing the issue where the custom linker step for generating AOT parameters always treates the dedup assembly as the one to be AOTed. Once approved this should be backported to .NET 8 as servicing releases are also affected with it. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
Description
As part of the fix for: dotnet/runtime#99248 we disabled dedup optimization in partial/hybrid AOT mode (when both interpreter and AOT compiler are enabled). This change got backported to .NET 8 and with the latest servicing release regressed build times and app sizes significantly as reported in: #20848
However, it turns out that disabling dedup optimization is not required to fix dotnet/runtime#99248 but instead we should correct the Xamarin SDK integration with this optimization which this PR is doing. The following section describes the initial problem in more details.
Overview of AOT modes and dedup optimization
When the repro project from dotnet/runtime#99248 is built with dedup enabled in hybrid AOT+interpreter mode, the app crashes with:
To track down why these wrappers which are used to transition from interpreter to AOT code, are not generated we need to understand when they are compiled in different AOT modes with and without dedup optimization enabled:
In full AOT setup - all assemblies AOT compiled
gsharedvt_out_sig
methods are never generatedIn hybrid AOT + interpreter setup - all assemblies AOT compiled:
MtouchInterpreter=-all
gsharedvt_out_sig
methods are generated in AOT images of every assembly (to enable interpreter calling into each specific assembly - here wrappers with same signatures are duplicated)gsharedvt_out_sig
methods are generated only inaot-instances
AOT imagegsharedvt_out_sig
is skippedaot-instances
assembly we collect allgsharedvt_out_sig
variants from the full program scope and generate code for them inaot-instances
AOT imageIn hybrid AOT + interpreter setup - all assemblies interpreted except a given assembly:
MtouchInterpreter=all,-MyAssembly
gsharedvt_out_sig
methods are generated in AOT image ofMyAssembly
(to enable interpreter calling into it)gsharedvt_out_sig
methods should be generated only inaot-instances
AOT image, but theaot-instances
image is missinggsharedvt_out_sig
is skipped during AOT compilation ofMyAssembly
(as expected).aot-instances
assembly as the one that should be AOT compiled._IsDedupEnabled
flag, but when custom linker step analysisaot-instances.dll
it does not see it as an assembly which should not be interpreted.MtouchInterpreter=all
), but exclude onlyMyAssembly
(via:MtouchInterpreter=all,-MyAssembly
).aot-instaces.dll
it treats it as an assembly to be interpreted, so it does not mark it for AOT compilation.aot-instances
AOT image missing, and all the methods which we skipped during AOT compilation never get generated.The fix
To fix this and address regressions reported in: #20848 we are reenabling dedup optimization whenever AOT compilation is requested and fixing the issue where the custom linker step for generating AOT parameters always treates the dedup assembly as the one to be AOTed.
Once approved this should be backported to .NET 8 as servicing releases are also affected with it.