[clr-interp] Fix logic around interpreter stub startup where the CallStubHeader may not be generated due to a race#120952
Merged
davidwrighton merged 4 commits intodotnet:mainfrom Oct 22, 2025
Conversation
Member
davidwrighton
commented
Oct 21, 2025
- Instead of generating it at the end of DoPrestub, which does not reliably finish before other threads may attempt to use the CallStubHeader, do it on demand just when it is needed
- This reduces total memory allocation, and makes the logic correct by construction
- In addition the GetInterpThreadContextWithPossiblyMissingThread function did not correctly setup EH handling regions and such to accomodate for the possibility that it might need to allocate or do a GC transition, so I've added passing the transition context into it, and set it up to use a PrestubFrame to protect the argument registers
…StubHeader may not be generated due to a race - Instead of generating it at the end of DoPrestub, which does not reliably finish before other threads may attempt to use the CallStubHeader, do it on demand just when it is needed - This reduces total memory allocation, and makes the logic correct by construction - In addition the GetInterpThreadContextWithPossiblyMissingThread function did not correctly setup EH handling regions and such to accomodate for the possibility that it might need to allocate or do a GC transition, so I've added passing the transition context into it, and set it up to use a PrestubFrame to protect the argument registers
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a race condition in the interpreter stub startup logic where the CallStubHeader might not be generated before other threads attempt to use it. The fix moves the CallStubHeader generation from DoPrestub (where it couldn't reliably complete before other threads needed it) to on-demand generation when actually needed.
- Removes early CallStubHeader generation from DoPrestub that could race
- Implements on-demand CallStubHeader generation in the interpreter stub path with proper synchronization
- Adds proper EH handling and GC transition support to GetInterpThreadContextWithPossiblyMissingThreadOrCallStub
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/virtualcallstub.cpp | Removes forward declaration now moved to header |
| src/coreclr/vm/threads.cpp | Refactors and expands GetInterpThreadContextWithPossiblyMissingThread to handle on-demand CallStub generation with proper frame setup |
| src/coreclr/vm/prestub.cpp | Removes premature CallStubHeader generation that could race |
| src/coreclr/vm/precode.cpp | Fixes field access to use methodDesc instead of methodHnd |
| src/coreclr/vm/interpexec.cpp | Simplifies CreateNativeToInterpreterCallStub early-exit logic and fixes field references |
| src/coreclr/vm/exceptionhandling.h | Moves IsCallDescrWorkerInternalReturnAddress declaration to header for broader visibility |
| src/coreclr/vm/exceptionhandling.cpp | Removes forward declaration now in header |
| src/coreclr/vm/arm64/asmhelpers.asm | Updates assembly to call renamed function and check for missing CallStub |
| src/coreclr/vm/arm64/asmhelpers.S | Updates assembly to call renamed function and check for missing CallStub |
| src/coreclr/vm/amd64/asmhelpers.S | Updates assembly to call renamed function and check for missing CallStub |
| src/coreclr/vm/amd64/AsmHelpers.asm | Updates assembly to call renamed function and check for missing CallStub |
| src/coreclr/interpreter/interpreter.h | Defines INTERPRETER_COMPILER_INTERNAL to control field naming |
| src/coreclr/interpreter/inc/interpretershared.h | Adds conditional compilation to expose methodDesc field outside compiler |
Contributor
|
Tagging subscribers to this area: @mangod9 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
|
I hope there was a way to not to create the CallStub from the asm helper, but I don't see one. |
This was referenced Oct 22, 2025
kg
reviewed
Oct 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.