Skip to content

[ios-clr] Resolve throw helpers to managed methods in R2R compilation#125646

Draft
kotlarmilos wants to merge 6 commits intodotnet:mainfrom
kotlarmilos:r2r-throw-helpers
Draft

[ios-clr] Resolve throw helpers to managed methods in R2R compilation#125646
kotlarmilos wants to merge 6 commits intodotnet:mainfrom
kotlarmilos:r2r-throw-helpers

Conversation

@kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented Mar 17, 2026

Description

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.

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 crossgen2 RequiresRuntimeJitException catch blocks and running the same crossgen2 invocation with and without the fix:

Before After Delta
Interpreter fallback methods 3,269 341 -2,928

Breakdown of the 2,928 precompiled methods:

  • 2,187 CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED (ARM intrinsics in System.Private.CoreLib: Arm.Aes, Arm.AdvSimd, etc.)
  • 741 CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION (ARM intrinsic range checks)

Fixes #120047

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>
Copilot AI review requested due to automatic review settings March 17, 2026 11:36
@kotlarmilos kotlarmilos changed the title [crossgen2] Resolve throw helpers to managed methods in R2R compilation [ios-clr] Resolve throw helpers to managed methods in R2R compilation Mar 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and CORINFO_HELP_THROW_NOT_IMPLEMENTED to managed ThrowHelpers method entrypoints.
  • Add a small helper (GetThrowHelperMethodEntrypoint) to look up the ThrowHelpers method and produce a method-entrypoint import node.

You can also share your feedback on Copilot code review. Take the survey.

kotlarmilos and others added 2 commits March 18, 2026 16:12
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>
Copilot AI review requested due to automatic review settings March 18, 2026 15:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and CORINFO_HELP_THROW_NOT_IMPLEMENTED to concrete ReadyToRunHelper IDs during R2R compilation.
  • Promote the corresponding ReadyToRunHelper entries into the real (serialized) helper ID range with explicit values aligned to the native readytorun.h enum.
  • 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.

Comment on lines 1279 to +1290
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,
Copy link
Member

@jkotas jkotas Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump minor R2R version at the top of the file, and add a comment on what changed in this R2R version

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

You may want to trigger optional crossgen run before merging

kotlarmilos and others added 2 commits March 19, 2026 12:07
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 11:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_IMPLEMENTED to concrete ReadyToRunHelper IDs during R2R compilation.
  • Promote the corresponding ReadyToRunHelper values 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.

@kotlarmilos
Copy link
Member Author

/azp run crossgen2,crossgen2-composite

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@kotlarmilos
Copy link
Member Author

/azp list

@azure-pipelines

This comment was marked as resolved.

@kotlarmilos
Copy link
Member Author

/azp run runtime-coreclr crossgen2,runtime-coreclr crossgen2-composite

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clr-ios] Ensure must-expand intrinsics execute through R2R

3 participants