Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Nov 15, 2025

Now that async contexts are stored around the body of async methods we need to take special care that these pieces of state get restored on OSR and EnC transitions.

Now that async contexts are stored around the body of async methods we
need to take special case that these pieces of state get restored on OSR
and EnC transitions.
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 15, 2025
@dotnet-policy-service
Copy link
Contributor

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

@jakobbotsch
Copy link
Member Author

Still have various x86 functions like GetLocallocSPOffset that probably need to be taught about the two new specially allocated context variables.

@akoeplinger
Copy link
Member

Sorry, for some reason Copilot added a Fixes message for this PR in #121923 🤦

@akoeplinger akoeplinger reopened this Nov 24, 2025
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Need to revert async test enabling before merging, but it should be ready for review.

Also cc @VSadov @jkotas for the VM parts. To avoid changing JIT32 GC info I changed GetSizeOfFrameHeaderForEnC to make the determination if the two contexts are present based on MethodDesc::RequiresAsyncContextSaveAndRestore. But we could also change the JIT32 GC info if that is preferred. Thoughts?

@jkotas
Copy link
Member

jkotas commented Dec 11, 2025

we could also change the JIT32 GC info if that is preferred. Thoughts?

I think it is ok to take this shortcut - if it is just for EnC on x86.

@jakobbotsch jakobbotsch marked this pull request as ready for review December 11, 2025 13:43
Copilot AI review requested due to automatic review settings December 11, 2025 13:43
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 pull request adds support for async contexts (ExecutionContext and SynchronizationContext) in OSR (On Stack Replacement) and EnC (Edit and Continue) scenarios. The JIT now stores these contexts in the stack frame and ensures they are properly preserved when transitioning between tiered compilation levels.

Key Changes:

  • Async context locals are now allocated in the EnC frame header alongside other preserved state like the monitor acquired flag
  • OSR methods reuse the async context values from the tier0 frame instead of recapturing them
  • Frame layout calculations updated across all architectures to account for the two new async context slots

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tests/async/execution-context/execution-context.cs Adds test for verifying async context restoration across OSR transitions
src/coreclr/vm/gc_unwind_x86.inl Updates x86 EnC frame header size calculation to include async context slots
src/coreclr/vm/eetwain.cpp Updates EnC frame header size calls to pass MethodDesc parameter
src/coreclr/jit/lclvars.cpp Adds lvaAllocAsyncContexts helper and integrates async context allocation into frame layout; handles OSR locals properly
src/coreclr/jit/flowgraph.cpp Marks monitor acquired local as OSR local when in OSR mode
src/coreclr/jit/compiler.h Declares new lvaAllocAsyncContexts helper method
src/coreclr/jit/compiler.cpp Records async context offsets in patchpoint info for OSR; updates OSR local validation
src/coreclr/jit/codegenxarch.cpp Updates x64 EnC preserved area size to include async contexts
src/coreclr/jit/codegenriscv64.cpp Updates RISC-V64 frame calculations for async contexts
src/coreclr/jit/codegenloongarch64.cpp Updates LoongArch64 frame calculations and EnC preserved area for async contexts
src/coreclr/jit/codegencommon.cpp Disables contiguous GC pointer tracking when async contexts are present
src/coreclr/jit/codegenarmarch.cpp Updates ARM/ARM64 EnC preserved area size for async contexts
src/coreclr/jit/codegenarm64.cpp Updates ARM64 funclet frame size calculations for async contexts
src/coreclr/jit/codegenarm.cpp Updates ARM32 funclet frame size calculations for async contexts
src/coreclr/jit/async.cpp Skips context capture call for OSR methods (already done in tier0)
src/coreclr/inc/patchpointinfo.h Adds async context offset fields and accessor methods to PatchpointInfo structure
src/coreclr/inc/jiteeversionguid.h Updates JIT-EE interface version GUID
docs/design/coreclr/botr/clr-abi.md Documents async context preservation requirements for EnC

@jkotas
Copy link
Member

jkotas commented Dec 11, 2025

The VM changes LGTM

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

JIT changes look good.

@jakobbotsch jakobbotsch merged commit 0bdd768 into dotnet:main Jan 6, 2026
115 of 118 checks passed
@jakobbotsch jakobbotsch deleted the fix-osr-enc-async-state branch January 6, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants