Skip to content

Commit c928a95

Browse files
authored
Support dynamically creating tailored continuation layouts (#120411)
Add ability for the VM to dynamically create continuation layout types and for the JIT to request such types to be created.
1 parent 9c700f7 commit c928a95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1413
-957
lines changed

.github/prompts/add-new-jit-ee-api.prompt.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
mode: 'agent'
3-
tools: ['githubRepo', 'codebase', 'terminalLastCommand']
3+
tools: ['fetch', 'codebase', 'runCommands', 'usages', 'search', 'think']
44
description: 'Add a new API to the JIT-VM (aka JIT-EE) interface in the codebase.'
55
---
66

77
#### 1 — Goal
88

9-
Implement **one** new JIT-VM (also known as JIT-EE) API and all supporting glue.
9+
Implement **one** new JIT-VM (also known as JIT-EE) API and all supporting glue.
1010
The JIT-VM interface defines the APIs through which the JIT compiler communicates with the runtime (VM).
1111

1212
#### 2 — Prerequisites for the model
1313

1414
* You have full repo access
15-
* You may run scripts (e.g., `.sh` or `.bat`)
15+
* You may run scripts (e.g., `.sh` or `.bat`)
1616
* Ask **clarifying questions** before the first code change if anything (signature, types, platform constraints) is unclear.
1717

1818
#### 3 — Required user inputs
1919

20-
Ask the user for a C-like signature of the new API if it's not provided.
20+
Ask the user for a C-like signature of the new API if it's not provided.
2121
Suggest `<repo_root>/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt` file as a reference. Example:
2222

2323
```
@@ -83,8 +83,8 @@ Use the correct directory for the script to run.
8383
+}
8484
```
8585

86-
6. Now implement the most complex part - SuperPMI. SuperPMI acts as a (de)serializer for JIT-VM queries in order
87-
to then replay them without the actual VM to speed up jit-diffs and other scenarios. All parameters and return
86+
6. Now implement the most complex part - SuperPMI. SuperPMI acts as a (de)serializer for JIT-VM queries in order
87+
to then replay them without the actual VM to speed up jit-diffs and other scenarios. All parameters and return
8888
values recorded/restored using special primitve types and helpers. We need to update the following files:
8989

9090
* `<repo_root>/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h`:
@@ -96,7 +96,7 @@ Go through each of them one by one.
9696

9797
* `<repo_root>/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h`:
9898
Define two `Agnostic_*` types for input arguments and another one for output parameters (return value, output arguments).
99-
Do not create them if one of the generics ones can be re-used such as `DLD`, `DD`, `DLDL`, etc. Use `DWORD*`
99+
Do not create them if one of the generics ones can be re-used such as `DLD`, `DD`, `DLDL`, etc. Use `DWORD*`
100100
like types for integers. Inspect the whole file to see how other APIs are defined.
101101

102102
* `<repo_root>/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h`:
@@ -126,7 +126,7 @@ Now add a new element to `enum mcPackets` enum in the same file. Example:
126126
```
127127

128128
* `<repo_root>/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp`:
129-
Add the implementation of the 3 methods to `methodcontext.cpp` at the end of it.
129+
Add the implementation of the 3 methods to `methodcontext.cpp` at the end of it.
130130
Consider other similar methods in the file for reference. Do not change implementations of other methods in the file. Example:
131131

132132
```diff

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs

Lines changed: 113 additions & 179 deletions
Large diffs are not rendered by default.

src/coreclr/inc/corinfo.h

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,29 +1698,34 @@ struct CORINFO_EE_INFO
16981698
CORINFO_OS osType;
16991699
};
17001700

1701+
// Keep in sync with ContinuationFlags enum in BCL sources
17011702
enum CorInfoContinuationFlags
17021703
{
1703-
// Whether or not the continuation expects the result to be boxed and
1704-
// placed in the GCData array at index 0. Not set if the callee is void.
1705-
CORINFO_CONTINUATION_RESULT_IN_GCDATA = 1,
1706-
// If this bit is set the continuation resumes inside a try block and thus
1707-
// if an exception is being propagated, needs to be resumed. The exception
1708-
// should be placed at index 0 or 1 depending on whether the continuation
1709-
// also expects a result.
1710-
CORINFO_CONTINUATION_NEEDS_EXCEPTION = 2,
1711-
// If this bit is set the continuation has the IL offset that inspired the
1712-
// OSR method saved in the beginning of 'Data', or -1 if the continuation
1713-
// belongs to a tier 0 method.
1714-
CORINFO_CONTINUATION_OSR_IL_OFFSET_IN_DATA = 4,
1704+
// Note: the following 'Has' members determine the members present at
1705+
// the beginning of the continuation's data chunk. Each field is
1706+
// pointer sized when present, apart from the result that has variable
1707+
// size.
1708+
1709+
// Whether or not the continuation starts with an OSR IL offset.
1710+
CORINFO_CONTINUATION_HAS_OSR_ILOFFSET = 1,
1711+
// If this bit is set the continuation resumes inside a try block and
1712+
// thus if an exception is being propagated, needs to be resumed.
1713+
CORINFO_CONTINUATION_HAS_EXCEPTION = 2,
1714+
// If this bit is set the continuation has space for a continuation
1715+
// context.
1716+
CORINFO_CONTINUATION_HAS_CONTINUATION_CONTEXT = 4,
1717+
// If this bit is set the continuation has space to store a result
1718+
// returned by the callee.
1719+
CORINFO_CONTINUATION_HAS_RESULT = 8,
17151720
// If this bit is set the continuation should continue on the thread
17161721
// pool.
1717-
CORINFO_CONTINUATION_CONTINUE_ON_THREAD_POOL = 8,
1718-
// If this bit is set the continuation has a SynchronizationContext
1719-
// that we should continue on.
1720-
CORINFO_CONTINUATION_CONTINUE_ON_CAPTURED_SYNCHRONIZATION_CONTEXT = 16,
1721-
// If this bit is set the continuation has a TaskScheduler
1722-
// that we should continue on.
1723-
CORINFO_CONTINUATION_CONTINUE_ON_CAPTURED_TASK_SCHEDULER = 32,
1722+
CORINFO_CONTINUATION_CONTINUE_ON_THREAD_POOL = 16,
1723+
// If this bit is set the continuation context is a
1724+
// SynchronizationContext that we should continue on.
1725+
CORINFO_CONTINUATION_CONTINUE_ON_CAPTURED_SYNCHRONIZATION_CONTEXT = 32,
1726+
// If this bit is set the continuation context is a TaskScheduler that
1727+
// we should continue on.
1728+
CORINFO_CONTINUATION_CONTINUE_ON_CAPTURED_TASK_SCHEDULER = 64,
17241729
};
17251730

17261731
struct CORINFO_ASYNC_INFO
@@ -1735,13 +1740,6 @@ struct CORINFO_ASYNC_INFO
17351740
CORINFO_FIELD_HANDLE continuationStateFldHnd;
17361741
// 'Flags' field
17371742
CORINFO_FIELD_HANDLE continuationFlagsFldHnd;
1738-
// 'Data' field
1739-
CORINFO_FIELD_HANDLE continuationDataFldHnd;
1740-
// 'GCData' field
1741-
CORINFO_FIELD_HANDLE continuationGCDataFldHnd;
1742-
// Whether or not the continuation needs to be allocated through the
1743-
// helper that also takes a method handle
1744-
bool continuationsNeedMethodHandle;
17451743
// Method handle for AsyncHelpers.CaptureExecutionContext
17461744
CORINFO_METHOD_HANDLE captureExecutionContextMethHnd;
17471745
// Method handle for AsyncHelpers.RestoreExecutionContext
@@ -1960,6 +1958,8 @@ struct CORINFO_FPSTRUCT_LOWERING
19601958
#define OFFSETOF__CORINFO_Span__reference 0
19611959
#define OFFSETOF__CORINFO_Span__length TARGET_POINTER_SIZE
19621960

1961+
#define OFFSETOF__CORINFO_Continuation__data (SIZEOF__CORINFO_Object + TARGET_POINTER_SIZE /* Next */ + TARGET_POINTER_SIZE /* Resume */ + 8 /* Flags + State */)
1962+
19631963

19641964
/* data to optimize delegate construction */
19651965
struct DelegateCtorArgs
@@ -3342,6 +3342,12 @@ class ICorDynamicInfo : public ICorStaticInfo
33423342

33433343
virtual CORINFO_METHOD_HANDLE getAsyncResumptionStub() = 0;
33443344

3345+
virtual CORINFO_CLASS_HANDLE getContinuationType(
3346+
size_t dataSize,
3347+
bool* objRefs,
3348+
size_t objRefsSize
3349+
) = 0;
3350+
33453351
// Optionally, convert calli to regular method call. This is for PInvoke argument marshalling.
33463352
virtual bool convertPInvokeCalliToCall(
33473353
CORINFO_RESOLVED_TOKEN * pResolvedToken,

src/coreclr/inc/dacvars.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ DEFINE_DACVAR(UNKNOWN_POINTER_TYPE, dac__g_TypedReferenceMT, ::g_TypedReferenceM
175175
DEFINE_DACVAR(UNKNOWN_POINTER_TYPE, dac__g_pWeakReferenceClass, ::g_pWeakReferenceClass)
176176
DEFINE_DACVAR(UNKNOWN_POINTER_TYPE, dac__g_pWeakReferenceOfTClass, ::g_pWeakReferenceOfTClass)
177177

178+
DEFINE_DACVAR_VOLATILE(UNKNOWN_POINTER_TYPE, dac__g_pContinuationClassIfSubTypeCreated, ::g_pContinuationClassIfSubTypeCreated)
179+
178180
#ifdef FEATURE_COMINTEROP
179181
DEFINE_DACVAR(UNKNOWN_POINTER_TYPE, dac__g_pBaseCOMObject, ::g_pBaseCOMObject)
180182
#endif

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ bool getTailCallHelpers(
655655
CORINFO_GET_TAILCALL_HELPERS_FLAGS flags,
656656
CORINFO_TAILCALL_HELPERS* pResult) override;
657657

658+
CORINFO_CLASS_HANDLE getContinuationType(
659+
size_t dataSize,
660+
bool* objRefs,
661+
size_t objRefsSize) override;
662+
658663
CORINFO_METHOD_HANDLE getAsyncResumptionStub() override;
659664

660665
bool convertPInvokeCalliToCall(

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737

3838
#include <minipal/guid.h>
3939

40-
constexpr GUID JITEEVersionIdentifier = { /* 3d2bdd20-eced-4a07-b9fb-227ce7f55fcd */
41-
0x3d2bdd20,
42-
0xeced,
43-
0x4a07,
44-
{0xb9, 0xfb, 0x22, 0x7c, 0xe7, 0xf5, 0x5f, 0xcd}
40+
constexpr GUID JITEEVersionIdentifier = { /* 68e93e9d-dd28-49ca-9ebc-a01a54532bb3 */
41+
0x68e93e9d,
42+
0xdd28,
43+
0x49ca,
44+
{0x9e, 0xbc, 0xa0, 0x1a, 0x54, 0x53, 0x2b, 0xb3}
4545
};
4646

4747
#endif // JIT_EE_VERSIONING_GUID_H

src/coreclr/jit/ICorJitInfo_names_generated.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ DEF_CLR_API(getFieldThreadLocalStoreID)
159159
DEF_CLR_API(GetDelegateCtor)
160160
DEF_CLR_API(MethodCompileComplete)
161161
DEF_CLR_API(getTailCallHelpers)
162+
DEF_CLR_API(getContinuationType)
162163
DEF_CLR_API(getAsyncResumptionStub)
163164
DEF_CLR_API(convertPInvokeCalliToCall)
164165
DEF_CLR_API(notifyInstructionSetUsage)

src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,17 @@ bool WrapICorJitInfo::getTailCallHelpers(
15361536
return temp;
15371537
}
15381538

1539+
CORINFO_CLASS_HANDLE WrapICorJitInfo::getContinuationType(
1540+
size_t dataSize,
1541+
bool* objRefs,
1542+
size_t objRefsSize)
1543+
{
1544+
API_ENTER(getContinuationType);
1545+
CORINFO_CLASS_HANDLE temp = wrapHnd->getContinuationType(dataSize, objRefs, objRefsSize);
1546+
API_LEAVE(getContinuationType);
1547+
return temp;
1548+
}
1549+
15391550
CORINFO_METHOD_HANDLE WrapICorJitInfo::getAsyncResumptionStub()
15401551
{
15411552
API_ENTER(getAsyncResumptionStub);

0 commit comments

Comments
 (0)