-
Notifications
You must be signed in to change notification settings - Fork 5.3k
JIT: Support async contexts for OSR/EnC #121672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
Still have various x86 functions like |
|
Sorry, for some reason Copilot added a |
|
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 |
I think it is ok to take this shortcut - if it is just for EnC on x86. |
There was a problem hiding this 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 |
|
The VM changes LGTM |
AndyAyersMS
left a comment
There was a problem hiding this 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.
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.