You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/design/coreclr/botr/runtime-async-codegen.md
+20-8Lines changed: 20 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ The general responsibilities of the runtime-async code generator
12
12
13
13
2. Allow the async thunk logic to work.
14
14
15
-
3. Generate Async Debug info (Not yet described in this document)f
15
+
3. Generate Async Debug info (Not yet described in this document)
16
16
17
17
18
18
@@ -37,7 +37,7 @@ call <Await> One of the functions which matches NI_System_Runtime_Compiler
37
37
38
38
A search for this sequence is done if Method is known to be async.
39
39
40
-
The dispatch to async functions save the `ExecutionContext` on suspension and restore it on resumption via `AsyncHelpers.CaptureExecutionContext` and `AsyncHelpers.RestoreExecutionContext` respectively
40
+
The dispatch to async functions saves the `ExecutionContext` on suspension to be restored before resumption by `DispatchContinuations`.
41
41
42
42
If PREFIX_TASK_AWAIT_CONTINUE_ON_CAPTURED_CONTEXT, then continuation mode shall be ContinuationContextHandling::ContinueOnCapturedContext otherwise ContinuationContextHandling::ContinueOnThreadPool.
43
43
@@ -59,9 +59,21 @@ The dispatch to these functions will save and restore the execution context only
59
59
60
60
When encountered, triggers the function to suspend immediately, and return the passed in Continuation.
61
61
62
+
# Accessing known continuation fields
63
+
64
+
The continuation flags encode how to access several well-known fields if they are present in the continuation.
65
+
- The execution context
66
+
- The continuation context
67
+
- The exception object
68
+
- The return value
69
+
70
+
Each field has a pair of (first bit, number of bits) used to indicate where its details are encoded in the flags.
71
+
When the field is present the index is non-zero and the offset is computed as (DataStart + (index - 1) * PointerSize).
72
+
If a field is not present the index is zero.
73
+
62
74
# Saving and restoring of contexts
63
75
64
-
Capture the execution context before the suspension, and when the function resumes, call `AsyncHelpers.RestoreExecutionContext`. The context should be stored into the Continuation. The context may be captured by calling `AsyncHelpers.CaptureExecutionContext`.
76
+
Capture the execution context before the suspension. The context should be stored into the Continuation and its offset encoded via the scheme above. The context may be captured by calling `AsyncHelpers.CaptureExecutionContext`.
65
77
66
78
# ABI for async function handling
67
79
@@ -87,8 +99,8 @@ if (continuation != NULL)
87
99
// Resumption point
88
100
89
101
// Copy values out of continuation (including captured sync context and execution context locals)
90
-
// If the continuation may have an exception, check to see if its there, and if it is, throw it. Do this if CORINFO\_CONTINUATION\_HAS\_EXCEPTION is set.
91
-
// If the continuation has a return value, copy it out of the continuation. (CORINFO\_CONTINUATION\_HAS\_RESULT is set)
102
+
// If the continuation may have an exception, check to see if its there, and if it is, throw it. Do this if the flags indicate an exception object is present.
103
+
// If the continuation has a return value, copy it out of the continuation. Do this if the flags indicate a result is present.
92
104
}
93
105
```
94
106
@@ -109,16 +121,16 @@ This only applies to calls which where ContinuationContextHandling is not Contin
109
121
110
122
If set to ContinuationContextHandling::ContinueOnCapturedContext
111
123
112
-
- The Continuation shall have an allocated data member for the captured context, and the CORINFO_CONTINUATION_HAS_CONTINUATION_CONTEXT flag shall be set on the continuation.
124
+
- The Continuation shall have an allocated data member for the captured context, and its offset is encoded in the flags based on the scheme above.
113
125
114
-
- The Continuation will store the captured synchronization context. This is done by calling `AsyncHelpers.CaptureContinuationContext(ref newContinuation.ContinuationContext, ref newContinuation.Flags)` while filling in the `Continuation`.
126
+
- The Continuation will store the captured synchronization context. This can be done by calling `AsyncHelpers.CaptureContinuationContext(ref newContinuation.ContinuationContext, ref newContinuation.Flags)` while filling in the `Continuation`.
115
127
116
128
If set to ContinuationContextHandling::ContinueOnThreadPool
117
129
- The Continuation shall have the CORINFO_CONTINUATION_CONTINUE_ON_THREAD_POOL flag set
118
130
119
131
# Exception handling behavior
120
132
121
-
If an async function is called within a try block (In the jit hasTryIndex return true), set the CORINFO\_CONTINUATION\_HAS\_EXCEPTION bit on the Continuation and make it large enough.
133
+
If an async function is called within a try block (In the jit hasTryIndex return true), allocate space for an exception in the continuation and encode its offset in the flags based on the scheme above.
0 commit comments