-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Support dynamically creating tailored continuation layouts #120411
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
base: main
Are you sure you want to change the base?
Support dynamically creating tailored continuation layouts #120411
Conversation
Add ability for the VM to dynamically create continuation layout types and for the JIT to request such types to be created.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
Now that we store directly into the ThunkTask's result we do not need to allocate a tail continuation at all.
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Show resolved
Hide resolved
See discussion around #120411 (comment).
Test failures look related: System.InvalidProgramException: Invalid IL code in AwaitNotAsync:AsyncEntryPoint |
I think this one was just Mono complaining about not supporting runtime async. But the 32-bit coreclr failures were related. Pushed a fix for that one, and I need to remember to revert the enabling of the testing. |
I still need to do some final testing that verifies that the ETW events look right, but this should be ready for another look @jkotas @noahfalk @VSadov. Anything else you see here? I opened #120799 and #120800 for follow-up diagnostics work. cc @dotnet/jit-contrib PTAL @AndyAyersMS. On the JIT side this is mostly simplifying things by removing the indirections through separate arrays stored in |
private static Task<T?> FinalizeTaskReturningThunk<T>() | ||
{ | ||
Continuation finalContinuation = new Continuation(); | ||
|
||
// Note that the exact location the return value is placed is tied | ||
// into getAsyncResumptionStub in the VM, so do not change this | ||
// without also changing that code (and the JIT). | ||
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) | ||
{ | ||
finalContinuation.Flags = CorInfoContinuationFlags.CORINFO_CONTINUATION_RESULT_IN_GCDATA | CorInfoContinuationFlags.CORINFO_CONTINUATION_NEEDS_EXCEPTION; | ||
finalContinuation.GCData = new object[1]; | ||
} | ||
else | ||
{ | ||
finalContinuation.Flags = CorInfoContinuationFlags.CORINFO_CONTINUATION_NEEDS_EXCEPTION; | ||
finalContinuation.Data = new byte[Unsafe.SizeOf<T>()]; | ||
} | ||
|
||
continuation.Next = finalContinuation; | ||
|
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.
We now represent the tail with a null "next" continuation. The problem with that is figuring out where to put the result of the final continuation -- we now use the storage inside the RuntimeAsyncTask<T>.m_result
as the place to put it when we get to the end.
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
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.
This looks good to me modulo making RuntimeAsync on by default. If there is a need to get it on by default regardless of the diagnostics I'd suggest we do it in a separate PR.
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.
Add ability for the VM to dynamically create continuation layout types and for the JIT to request such types to be created.