Skip to content

Emitting Async methods in ReadyToRun image #121559

@jtschuster

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions