[ios-clr] Resolve throw helpers to managed methods in R2R compilation#125646
[ios-clr] Resolve throw helpers to managed methods in R2R compilation#125646kotlarmilos wants to merge 6 commits intodotnet:mainfrom
Conversation
Resolve CORINFO_HELP_THROW_ARGUMENTEXCEPTION, CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, and CORINFO_HELP_THROW_NOT_IMPLEMENTED to managed method entrypoints in Internal.Runtime.CompilerHelpers.ThrowHelpers instead of throwing RequiresRuntimeJitException. This precompiles ~2,970 ARM intrinsic methods in System.Private.CoreLib that previously fell back to the interpreter on iOS/MacCatalyst in full R2R mode. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates crossgen2’s ReadyToRun JIT interface to resolve several CORINFO_HELP_THROW_* helpers to managed implementations in Internal.Runtime.CompilerHelpers.ThrowHelpers, enabling R2R compilation to succeed on full-R2R/no-JIT platforms (e.g., iOS/MacCatalyst) instead of forcing interpreter fallback.
Changes:
- Map
CORINFO_HELP_THROW_ARGUMENTEXCEPTION,CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION,CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, andCORINFO_HELP_THROW_NOT_IMPLEMENTEDto managedThrowHelpersmethod entrypoints. - Add a small helper (
GetThrowHelperMethodEntrypoint) to look up theThrowHelpersmethod and produce a method-entrypoint import node.
You can also share your feedback on Copilot code review. Take the survey.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs
Outdated
Show resolved
Hide resolved
Replace GetThrowHelperMethodEntrypoint (method-name-based lookup that only works in large version bubble) with proper ReadyToRunHelper IDs (0x28-0x2B) for ThrowArgument, ThrowArgumentOutOfRange, ThrowPlatformNotSupported, and ThrowNotImplemented. This follows the same pattern as existing ThrowNullRef and ThrowDivZero helpers, and resolves the 'Data pointer is outside of loaded image' assert seen in non-large-version-bubble scenarios. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enables full ReadyToRun (R2R) compilation for iOS/MacCatalyst scenarios by resolving several CORINFO_HELP_THROW_* helpers to managed Internal.Runtime.CompilerHelpers.ThrowHelpers entrypoints instead of forcing RequiresRuntimeJitException fallback.
Changes:
- Map
CORINFO_HELP_THROW_ARGUMENTEXCEPTION,CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION,CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, andCORINFO_HELP_THROW_NOT_IMPLEMENTEDto concreteReadyToRunHelperIDs during R2R compilation. - Promote the corresponding
ReadyToRunHelperentries into the real (serialized) helper ID range with explicit values aligned to the nativereadytorun.henum. - Extend the native helper mapping (
readytorunhelpers.h) so the runtime understands these new R2R helper IDs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Resolves the affected JIT throw helpers to R2R helper IDs instead of requiring runtime JIT. |
| src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs | Adds explicit serialized helper IDs for the new throw helpers and removes them from the internal-only “fake helper” section. |
| src/coreclr/inc/readytorunhelpers.h | Adds native mapping entries from the new R2R helper IDs to the corresponding CORINFO_HELP_THROW_* helpers. |
| src/coreclr/inc/readytorun.h | Adds the new throw helpers to the native ReadyToRunHelper enum with fixed values matching the managed constants. |
You can also share your feedback on Copilot code review. Take the survey.
| case CorInfoHelpFunc.CORINFO_HELP_THROW_ARGUMENTEXCEPTION: | ||
| id = ReadyToRunHelper.ThrowArgument; | ||
| break; | ||
| case CorInfoHelpFunc.CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION: | ||
| id = ReadyToRunHelper.ThrowArgumentOutOfRange; | ||
| break; | ||
| case CorInfoHelpFunc.CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED: | ||
| id = ReadyToRunHelper.ThrowPlatformNotSupported; | ||
| break; | ||
| case CorInfoHelpFunc.CORINFO_HELP_THROW_NOT_IMPLEMENTED: | ||
| id = ReadyToRunHelper.ThrowNotImplemented; | ||
| break; |
| READYTORUN_HELPER_ThrowNullRef = 0x25, | ||
| READYTORUN_HELPER_ThrowDivZero = 0x26, | ||
| READYTORUN_HELPER_ThrowExact = 0x27, | ||
| READYTORUN_HELPER_ThrowArgument = 0x28, |
There was a problem hiding this comment.
Bump minor R2R version at the top of the file, and add a comment on what changed in this R2R version
jkotas
left a comment
There was a problem hiding this comment.
LGTM otherwise
You may want to trigger optional crossgen run before merging
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enables CoreCLR ReadyToRun (R2R) compilation to handle several common throw helpers by mapping them to R2R helper IDs (which ultimately resolve to managed Internal.Runtime.CompilerHelpers.ThrowHelpers entrypoints), avoiding RequiresRuntimeJitException and reducing interpreter fallback on iOS/MacCatalyst in full R2R mode.
Changes:
- Map
CORINFO_HELP_THROW_ARGUMENTEXCEPTION,..._ARGUMENTOUTOFRANGEEXCEPTION,..._PLATFORM_NOT_SUPPORTED, and..._NOT_IMPLEMENTEDto concreteReadyToRunHelperIDs during R2R compilation. - Promote the corresponding
ReadyToRunHelpervalues from “fake helpers” to real file-format helpers (with explicit numeric values). - Bump R2R header minor version from 18.3 to 18.4 and document the new version feature.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Stops treating selected throw helpers as “requires runtime JIT” by mapping them to R2R helper imports. |
| src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs | Adds real helper IDs for the throw helpers and removes their prior “fake helper” entries. |
| src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs | Updates the R2R header minor version to 18.4 for tool-emitted images. |
| src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h | Updates the NativeAOT-side R2R header minor version to match 18.4. |
| src/coreclr/inc/readytorunhelpers.h | Extends the runtime mapping table from R2R helper IDs to the corresponding CORINFO_HELP_* values. |
| src/coreclr/inc/readytorun.h | Updates the R2R minor version constant and documents what 18.4 adds; defines the new helper IDs in the native enum. |
You can also share your feedback on Copilot code review. Take the survey.
|
/azp run crossgen2,crossgen2-composite |
|
No pipelines are associated with this pull request. |
|
/azp list |
This comment was marked as resolved.
This comment was marked as resolved.
|
/azp run runtime-coreclr crossgen2,runtime-coreclr crossgen2-composite |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Description
Resolve
CORINFO_HELP_THROW_ARGUMENTEXCEPTION,CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION,CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, andCORINFO_HELP_THROW_NOT_IMPLEMENTEDto managed method entrypoints inInternal.Runtime.CompilerHelpers.ThrowHelpersinstead of throwingRequiresRuntimeJitException.On iOS/MacCatalyst with CoreCLR in full R2R mode methods that reference these throw helpers previously could not be precompiled by crossgen2, causing them to fall back to the interpreter at runtime.
Impact
Measured on a MAUI .NET 11 iOS composite R2R build (SDK
11.0.100-preview.2.26159.112) by adding logging to crossgen2RequiresRuntimeJitExceptioncatch blocks and running the same crossgen2 invocation with and without the fix:Breakdown of the 2,928 precompiled methods:
CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED(ARM intrinsics in System.Private.CoreLib:Arm.Aes,Arm.AdvSimd, etc.)CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION(ARM intrinsic range checks)Fixes #120047