Skip to content

JIT: Improve inlining functions with EH in .NET 10 #108900

Closed

Description

@BruceForstall

This item tracks work to improve inlining in RyuJIT in .NET 10.

Inline functions containing exception handling (EH)

The JIT currently will not inline a function with exception handling (EH) clauses (try/catch, try/finally, etc.). This work item is to remove that limitation.

A mechanical aspect of the implementation is simply to allow the insertion of the inlinee function EH information into the inliner EH table. Related, the inlinee must create and use its own EH table and not share the root EH table.

One specific note is that we still will not be able to inline any code with EH into an EH filter clause – that is not supported by the runtime. (I think this limitation goes back to Windows SEH, so maybe it can be considered for loosening?)

Specific work:

@SingleAccretion points out that for dynamic methods (which don't have useful tokens) the VM has a mechanism for storing a type handle in the reported EH clause (see SetHasCachedTypeHandle) and it looks like this is queried unconditionally by the code manager. So we should consider using that.

if (m_pMethodBeingCompiled->IsDynamicMethod() &&
((pEHClause->Flags & COR_ILEXCEPTION_CLAUSE_FILTER) == 0) &&
(clause->ClassToken != mdTokenNil))
{
ResolvedToken resolved{};
m_pMethodBeingCompiled->AsDynamicMethodDesc()->GetResolver()->ResolveToken(clause->ClassToken, &resolved);
pEHClause->TypeHandle = (void*)resolved.TypeHandle.AsPtr();
SetHasCachedTypeHandle(pEHClause);
LOG((LF_EH, LL_INFO1000000, " CachedTypeHandle: 0x%08x -> %p\n", clause->ClassToken, pEHClause->TypeHandle));
}

Related

#62038

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    User StoryA single user-facing feature. Can be grouped under an epic.
    on Oct 15, 2024
  2. added this to the 10.0.0 milestone on Oct 15, 2024
  3. dotnet-policy-service commented on Oct 15, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. moved this to Team User Stories in .NET Core CodeGenon Oct 17, 2024
  5. changed the title [-]JIT: Improve inlining in .NET 10[/-] [+]JIT: Improve inlining functions with EH in .NET 10[/+] on Oct 17, 2024
  6. removed
    User StoryA single user-facing feature. Can be grouped under an epic.
    on Oct 17, 2024
  7. AndyAyersMS commented on Jul 30, 2025

    @AndyAyersMS
    Member

    We accomplished a lot in .NET 10, so closing this.

    Remaining work can be addressed in future releases.

  8. moved this from Team User Stories to Done in .NET Core CodeGenon Jul 30, 2025
  9. locked and limited conversation to collaborators on Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions