-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Save and restore ExecutionContext
for runtime async calls
#117056
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
Merged
Merged
Conversation
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
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
jakobbotsch
commented
Jun 26, 2025
jkotas
reviewed
Jun 26, 2025
src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs
Outdated
Show resolved
Hide resolved
This was referenced Jun 26, 2025
AndyAyersMS
reviewed
Jun 27, 2025
Retbuf calls are TYP_VOID but still come with RET_EXPRs. Use `gtReturnType` instead.
jakobbotsch
commented
Jun 27, 2025
cc @dotnet/jit-contrib PTAL @AndyAyersMS |
This was referenced Jun 27, 2025
AndyAyersMS
approved these changes
Jun 27, 2025
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 LGTM. Left a few comments for your consideration.
This was referenced Jul 1, 2025
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
runtime-async
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.
Add support for saving and restoring the
ExecutionContext
around runtime async calls. Most of this is done in the JIT:ExecutionContext
is stored on both synchronous and asynchronous (suspending/resuming) paths. The JIT inserts IR between import and inlining to save the context before each async call, and to restore it after. If the call is inside a try clause, then this requires insertion of a try-finally to ensure the context is restored even if an exception is thrown.ExecutionContext
is saved and restored only in the asynchronous path. Thus the JIT only saves/restores the context as part of the suspend/resume paths.For the first case above we allow inlining the helpers. The second case above happens too late to rely on normal inlining, so right now it just inserts calls to two helpers. In the future we can consider inlining these manually in the suspend/restore paths.
For runtime async calls we assume that
Thread.t_currentThread
is always initialized. This initialization happens as part ofDispatchContinuations
or the Task-returning thunks. So we can avoid callingInitializeCurrentThread
when capturing/restoring the contexts. I have introduced a newThread.CurrentThreadNoInit
to access the TLS field without initialization.