Skip to content

Emitting Async methods in ReadyToRun image #121559

Closed

Description

@jtschuster

Compiling runtime-async methods in ReadyToRun images requires 3 method entrypoints to be generated for each async method in metadata (Task-returning, async call conv, and resumption stub). The current ReadyToRun image format has the RuntimeFunctions table (a blob store with the native assembly code for each compiled method body), the MethodDefEntryPoints table (a per-assembly sparse array that maps from metadata token to an offset in the RuntimeFunctions blob), and the InstanceMethodEntryPoints table (a image-wide hash table that maps from the method's R2R signature (different than it's metadata signature) to an offset in the RuntimeFunctions table).

I see two obvious ways to emit async methods into a ReadyToRun image:

  1. Use the InstanceMethodEntryPoint table for async variants and resumption stubs in addition to generic instantiation methods.
  2. Create a new AsyncMethodDefEntryPoints sparse array table with 3 indices into the RuntimeFunctions table for each non-generic method (Task-returning, async, resumption stub), and create a new AsyncInstanceMethodEntryPoints table for generic instantiations of async methods.

Emitting async methods into the InstanceMethodEntryPoints table in option 1 requires adding extra information to the signature of each method in the table about which of the 3 async methods it is, which should fit in 2 bits.

I think the best starting point is to reuse InstanceMethodEntryPoints table for async variants and resumption stubs.

Documentation of readytorun format is at docs/design/coreclr/botr/readytorun-format.md.
Relevant runtime code is in src/coreclr/vm/readytoruninfo.h/cpp. Relevant code in crossgen2 is in src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/InstanceEntryPointTableNode.cs and src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodEntryPointTableNode.cs.

Activity

  1. added
    untriaged
    on Nov 12, 2025
  2. added
    needs-area-label
    on Nov 12, 2025
  3. MihuBot commented on Nov 12, 2025

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. jkotas commented on Nov 12, 2025

    @jkotas
    Member

    Use the InstanceMethodEntryPoint table for async variants

    +1. I assume that we would add a new bits to ReadyToRunMethodSigFlags

    resumption stub

    How are we going to deal with resumption stubs at runtime? Are we going to create DynamicMethodDescs for them and fix the runtime to allow DynamicMethodDescs to point to R2R code?

    An alternative is to merge the resumption stub with the method that it is tightly coupled with (#121013). If we went with this plan, the resumption stubs would not need to be tracked in InstanceMethodEntryPoint and we would not need to create DynamicMethodDescs for them at runtime. We would still have to fix the runtime to make this configuration work.

  5. added and removed
    needs-area-label
    on Nov 12, 2025
  6. removed
    untriaged
    on Nov 12, 2025
  7. locked and limited conversation to collaborators on May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions