-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Switch to JIT intrinsics for generic context/async continuations #121799
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
NativeAOT and coreclr have various places where they want to have explicit control over the generic context and async continuation arguments. Introduce JIT intrinsics that allow them to explicitly set what value should be used for these arguments in an upcoming call. Also switch the async resumption stub's call to be properly marked async, and clean up some JIT side hacks as a result. That fixes dotnet#118575.
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs
Outdated
Show resolved
Hide resolved
|
I asked @davidwrighton for some help with implementing the same support in the interpreter. |
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 PR introduces new JIT intrinsics (SetNextCallGenericContext and SetNextCallAsyncContinuation) to provide explicit control over generic context and async continuation arguments in method calls. The changes eliminate platform-specific conditional compilation and simplify stub generation by modeling these arguments as part of the calling convention signature rather than as explicit parameters.
Key changes:
- Adds two new intrinsic methods to
RuntimeHelpersfor setting generic context and async continuation for the next call - Refactors stub generation in CoreCLR VM to use the new intrinsics instead of manually inserting arguments
- Updates the JIT importer to handle the new intrinsics and manage per-call context/continuation state
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs | Adds SetNextCallGenericContext and SetNextCallAsyncContinuation intrinsic methods |
| src/coreclr/vm/prestub.cpp | Refactors CreateDerivedTargetSig (renamed) to use intrinsics; updates unboxing and instantiating stub generation to call intrinsics instead of manually inserting parameters |
| src/coreclr/vm/method.hpp | Updates method signature declaration to match rename |
| src/coreclr/vm/jitinterface.cpp | Updates async resumption stub generation to use new intrinsics and removes platform-specific conditional compilation |
| src/coreclr/vm/corelib.h | Defines method metadata entries for the new intrinsics |
| src/coreclr/vm/callstubgenerator.cpp | Fixes indentation in logging code |
| src/coreclr/jit/namedintrinsiclist.h | Adds named intrinsic enum entries for the two new methods |
| src/coreclr/jit/lower.cpp | Updates comments to reflect that NativeAOT also uses the new intrinsic-based approach |
| src/coreclr/jit/importercalls.cpp | Implements intrinsic handling; adds logic to consume stored context/continuation values in call import; restructures generic context resolution flow |
| src/coreclr/jit/compiler.h | Adds fields to track the next call's generic context and async continuation local variables |
| src/coreclr/interpreter/intrinsics.cpp | Adds intrinsic recognition for the interpreter |
| src/coreclr/interpreter/compiler.h | Adds fields to track context/continuation variables in interpreter |
| src/coreclr/interpreter/compiler.cpp | Implements interpreter handling for the new intrinsics |
| src/coreclr/inc/corhdr.h | Reformats calling convention constant definitions |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
VM changes LGTM - as an interim step. |
VSadov
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.
LGTM.
|
I should have asked for a review on the interpreter parts. cc @janvorli @BrzVlad @kg @davidwrighton. Let me know if you have any feedback and I can open a follow up PR to address it. |
Takes advantage of the new functionality added in #121799.
Fix regression introduced in dotnet#121799 Force intrinsic expansion for new runtime helpers in the interpreter. Added the new methods and also NI_System_StubHelpers_NextCallReturnAddress, which has also `// Unconditionally expanded intrinsic` comment. This was happening on wasm and possibly on other platforms too, resulting in unhandled exception. Possibly only happening on platforms using generic instantiation IL stubs. ``` Unhandled exception. System.Diagnostics.UnreachableException: The program executed an instruction that was thought to be unreachable. at System.Runtime.CompilerServices.RuntimeHelpers.SetNextCallGenericContext(Void* value) in /Users/rodo/git/runtime-clean/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs:line 186 at InterpreterTest.TestVirtual() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 1960 at InterpreterTest.RunInterpreterTests() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 896 at InterpreterTest.Main(String[] args) in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 731 Aborted(native code called abort()) ```
Fix regression introduced in #121799 Force intrinsic expansion for new runtime helpers in the interpreter. Added the new methods and also `NI_System_StubHelpers_NextCallReturnAddress`, which has also `// Unconditionally expanded intrinsic` comment. This was happening on wasm and possibly on other platforms too, resulting in unhandled exception. Possibly only on platforms, which use generic instantiation IL stubs. ``` Unhandled exception. System.Diagnostics.UnreachableException: The program executed an instruction that was thought to be unreachable. at System.Runtime.CompilerServices.RuntimeHelpers.SetNextCallGenericContext(Void* value) in /Users/rodo/git/runtime-clean/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs:line 186 at InterpreterTest.TestVirtual() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 1960 at InterpreterTest.RunInterpreterTests() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 896 at InterpreterTest.Main(String[] args) in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 731 Aborted(native code called abort()) ```
NativeAOT and coreclr have various places where they want to have explicit control over the generic context and async continuation arguments. Introduce JIT intrinsics that allow them to explicitly set what value should be used for these arguments in an upcoming call. Model these arguments as part of the calling convention in the signatures where they are passed. That fixes #118575 for async, and is also necessary to compute proper call stubs for the interpreter.
See #121781 for more context.