Skip to content

JIT: Preserve async continuation arg across EnC remap#128664

Open
tommcdon wants to merge 2 commits into
dotnet:mainfrom
tommcdon:dev/tommcdon/fix-asyncv2-enc-continuation-preserved
Open

JIT: Preserve async continuation arg across EnC remap#128664
tommcdon wants to merge 2 commits into
dotnet:mainfrom
tommcdon:dev/tommcdon/fix-asyncv2-enc-continuation-preserved

Conversation

@tommcdon
Copy link
Copy Markdown
Member

@tommcdon tommcdon commented May 27, 2026

The async continuation argument was homed in the local frame area which gets zeroed by FixContextForEnC during EnC remap. On platforms with shadow space, the continuation accidentally survived because it was homed above callerSP, outside the zeroed region. On platforms without shadow space, the continuation was destroyed.

Fix: Assign a dedicated IL number (ASYNC_CONTINUATION_ILNUM = -4) so the continuation arg appears in NativeVarInfo and survives EnC remap on all platforms.

This shifts MAX_ILNUM from -4 to -5, changing the NativeVarInfo encoding bias. R2R major version bumped 18→19 accordingly.

@tommcdon tommcdon added this to the 11.0.0 milestone May 27, 2026
@tommcdon tommcdon requested review from VSadov and jakobbotsch May 27, 2026 20:42
@tommcdon tommcdon self-assigned this May 27, 2026
Copilot AI review requested due to automatic review settings May 27, 2026 20:42
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
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 PR adjusts CoreCLR JIT frame layout for async methods under Edit-and-Continue (EnC) so the async continuation argument’s stack home is placed in the EnC-preserved “frame header” region, and updates GC info preserved-area sizing on x64 and ARM64 accordingly.

Changes:

  • lclvars.cpp: Skips normal arg/local offset assignment for lvaAsyncContinuationArg under EnC and allocates its stack slot via lvaAllocAsyncContexts.
  • codegenxarch.cpp: Extends EnC preserved-area size to include the continuation slot on x64.
  • codegenarmarch.cpp: Extends EnC preserved-area size to include the continuation slot on ARM64.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lclvars.cpp Changes EnC frame-layout allocation/skip logic so the async continuation arg is intended to live in the EnC-preserved header region.
src/coreclr/jit/codegenxarch.cpp Updates x64 EnC preserved-area size computation to account for the continuation slot.
src/coreclr/jit/codegenarmarch.cpp Updates ARM64 EnC preserved-area size computation to account for the continuation slot.

Comment thread src/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch
Copy link
Copy Markdown
Member

How does the generic context get handled? We should align these.

@tommcdon
Copy link
Copy Markdown
Member Author

How does the generic context get handled? We should align these.

Generic context is stored as an explicit parameter so is automatically stored into NativeVarInfo. The continuation arg, however, has UNKNOWN_ILNUM so doesn't automatically get stored.

@jakobbotsch
Copy link
Copy Markdown
Member

I wonder if we should give this a number instead. I am not totally sure if things will work out correctly in all cases if we try to allocate an argument together with locals.

@tommcdon
Copy link
Copy Markdown
Member Author

I wonder if we should give this a number instead. I am not totally sure if things will work out correctly in all cases if we try to allocate an argument together with locals.

I think it makes sense. The variable already has a normal parameter home, so we would simply be assigning it a proper IL value, like ASYNC_CONTINUATION_ILNUM = -4. FixContextForEnC will find the variable in NativeVarInfo and copy its value from old frame to the new frame. Unless there are objections, I'll push a commit with the proposed change.

@tommcdon
Copy link
Copy Markdown
Member Author

I wonder if we should give this a number instead. I am not totally sure if things will work out correctly in all cases if we try to allocate an argument together with locals.

I think it makes sense. The variable already has a normal parameter home, so we would simply be assigning it a proper IL value, like ASYNC_CONTINUATION_ILNUM = -4. FixContextForEnC will find the variable in NativeVarInfo and copy its value from old frame to the new frame. Unless there are objections, I'll push a commit with the proposed change.

I believe this approach will require a R2R major version bump, because NativeVarInfo isn't versioned today.

@jakobbotsch
Copy link
Copy Markdown
Member

I think that should be ok, we can combine it with the change for #128397.
I think we already took a major version change in .NET 11, so I am not sure if we actually need to take another. We don't guarantee compatibility between previews.

Copilot AI review requested due to automatic review settings May 28, 2026 16:54
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread src/coreclr/jit/lclvars.cpp
Comment thread src/coreclr/jit/lclvars.cpp
Comment thread src/coreclr/inc/readytorun.h Outdated
Comment thread src/coreclr/inc/cordebuginfo.h
@tommcdon
Copy link
Copy Markdown
Member Author

I think that should be ok, we can combine it with the change for #128397. I think we already took a major version change in .NET 11, so I am not sure if we actually need to take another. We don't guarantee compatibility between previews.

@jakobbotsch you are correct - the R2R major version was bumped on #122704 which is during .NET 11. @jkotas do you see any issues with breaking the R2R format across daily .NET 11 builds and previews?

@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 28, 2026

do you see any issues with breaking the R2R format across daily .NET 11 builds and previews?

I do not see any issues, as you have said we started a new compat tier for .NET 11 already.

Comment thread src/coreclr/inc/readytorun.h
@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 28, 2026

I thought that you are asking about whether it is ok to bump the version. We like to bump the version whenever we break the format to save us debugging weird crashes caused by mismatched versions.

Copilot AI review requested due to automatic review settings May 28, 2026 20:35
@tommcdon
Copy link
Copy Markdown
Member Author

I thought that you are asking about whether it is ok to bump the version. We like to bump the version whenever we break the format to save us debugging weird crashes caused by mismatched versions.

Ahh - I thought there was agreement on no version bump. Bringing it back!

Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Comment on lines +44 to 45
private const uint MAX_ILNUM = unchecked((uint)-5);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@rcj1 @max-charlamb just checking before dismissing this comment - do you see any concerns with adding ASYNC_CONTINUATION_ILNUM (-4) toNativeVarInfo without adjusting for older builds?

Comment thread src/coreclr/jit/lclvars.cpp
Comment thread src/coreclr/inc/readytorun.h Outdated
Comment thread src/coreclr/jit/lclvars.cpp
@tommcdon
Copy link
Copy Markdown
Member Author

tommcdon commented May 29, 2026

FYI - it looks like we just took another R2R breaking change in main

<<<<<<< dev/tommcdon/fix-asyncv2-enc-continuation-preserved
// R2R Version 19.0 changes NativeVarInfo encoding to include ASYNC_CONTINUATION_ILNUM
=======
// R2R Version 19 removes the READYTORUN_HELPER_ByRefWriteBarrier helper
>>>>>>> main

@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 29, 2026

it looks like we just took another R2R breaking change in main

Change this one to 20 to resolve the conflict.

tommcdon and others added 2 commits May 29, 2026 18:47
When async V2 is enabled and EnC is active, the JIT now assigns
ASYNC_CONTINUATION_ILNUM (-4) to the async continuation arg variable
instead of UNKNOWN_ILNUM (-4, previously). This allows the debugger to
identify and preserve this variable across EnC remaps.

Also adds compMapILvarNum reverse mapping case and fixes a typo in
cordebuginfo.h.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The ASYNC_CONTINUATION_ILNUM addition changes MAX_ILNUM from -4 to -5,
which alters the NativeVarInfo encoding bias. Bump the R2R major version
so old images are rejected rather than silently misinterpreting variable
info.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tommcdon tommcdon force-pushed the dev/tommcdon/fix-asyncv2-enc-continuation-preserved branch from 2e5c78f to 683aa07 Compare May 29, 2026 23:04
Copilot AI review requested due to automatic review settings May 29, 2026 23:04
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +22 to 26
#define READYTORUN_MAJOR_VERSION 20
#define READYTORUN_MINOR_VERSION 0x0000

#define MINIMUM_READYTORUN_MAJOR_VERSION 19
#define MINIMUM_READYTORUN_MAJOR_VERSION 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants