Skip to content

Commit e713f13

Browse files
Implementation of ldftn and calli (#116449)
- This implements ldftn by matching the implementation in the JIT. Integration with the delegate construction path is not done, so we always go down slow path delegate creation, but it does work. - This implementation leverages our CallStubGenerator to create stubs for calli instructions. To get the appropriate call stub to the right location, we use a new jit interface api called `GetCookieForInterpreterCalliSig` to pass the needed cookie around. - As a bonus it is now possible to call delegates by calling the Invoke method on the delegate. We will likely want to translate that to using an INTOP_CALLI in the future, but it does work for now. NOTE: This logic results in going through an interpreter->native->interpreter calling thunks to make interpreter to interpreter calls. We will likely want to build an optimized path which uses of NonVirtualEntry2MethodDesc or an interpreter specific form to avoid bouncing through the calling convention trampolines, but I'd like to have a fully functional system before diving into doing that sort of thing as an optimization.
1 parent 477d545 commit e713f13

32 files changed

+780
-192
lines changed

src/coreclr/inc/CrstTypes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,8 @@ Crst PerfMap
527527
End
528528

529529
Crst InterfaceDispatchGlobalLists
530+
End
531+
532+
Crst CallStubCache
533+
AcquiredBefore LoaderHeap
530534
End

src/coreclr/inc/corinfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,7 @@ class ICorDynamicInfo : public ICorStaticInfo
31893189
CORINFO_CONST_LOOKUP * pLookup
31903190
) = 0;
31913191

3192-
// Generate a cookie based on the signature that would needs to be passed
3193-
// to CORINFO_HELP_PINVOKE_CALLI
3192+
// Generate a cookie based on the signature to pass to CORINFO_HELP_PINVOKE_CALLI
31943193
virtual void* GetCookieForPInvokeCalliSig(
31953194
CORINFO_SIG_INFO* szMetaSig,
31963195
void** ppIndirection = NULL
@@ -3202,6 +3201,10 @@ class ICorDynamicInfo : public ICorStaticInfo
32023201
CORINFO_SIG_INFO* szMetaSig
32033202
) = 0;
32043203

3204+
// Generate a cookie based on the signature to pass to INTOP_CALLI in the interpreter.
3205+
virtual void* GetCookieForInterpreterCalliSig(
3206+
CORINFO_SIG_INFO* szMetaSig) = 0;
3207+
32053208
// Gets a handle that is checked to see if the current method is
32063209
// included in "JustMyCode"
32073210
virtual CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle(

src/coreclr/inc/crsttypes_generated.h

Lines changed: 102 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -20,105 +20,106 @@ enum CrstType
2020
CrstAssemblyLoader = 2,
2121
CrstAvailableClass = 3,
2222
CrstAvailableParamTypes = 4,
23-
CrstCCompRC = 5,
24-
CrstClassFactInfoHash = 6,
25-
CrstClassInit = 7,
26-
CrstClrNotification = 8,
27-
CrstCodeFragmentHeap = 9,
28-
CrstCodeVersioning = 10,
29-
CrstCOMCallWrapper = 11,
30-
CrstCOMWrapperCache = 12,
31-
CrstDataTest1 = 13,
32-
CrstDataTest2 = 14,
33-
CrstDbgTransport = 15,
34-
CrstDeadlockDetection = 16,
35-
CrstDebuggerController = 17,
36-
CrstDebuggerFavorLock = 18,
37-
CrstDebuggerHeapExecMemLock = 19,
38-
CrstDebuggerHeapLock = 20,
39-
CrstDebuggerJitInfo = 21,
40-
CrstDebuggerMutex = 22,
41-
CrstDynamicIL = 23,
42-
CrstDynamicMT = 24,
43-
CrstEtwTypeLogHash = 25,
44-
CrstEventPipe = 26,
45-
CrstEventStore = 27,
46-
CrstException = 28,
47-
CrstExecutableAllocatorLock = 29,
48-
CrstFCall = 30,
49-
CrstFrozenObjectHeap = 31,
50-
CrstFuncPtrStubs = 32,
51-
CrstFusionAppCtx = 33,
52-
CrstGCCover = 34,
53-
CrstGenericDictionaryExpansion = 35,
54-
CrstGlobalStrLiteralMap = 36,
55-
CrstHandleTable = 37,
56-
CrstIbcProfile = 38,
57-
CrstIJWFixupData = 39,
58-
CrstIJWHash = 40,
59-
CrstILStubGen = 41,
60-
CrstInlineTrackingMap = 42,
61-
CrstInstMethodHashTable = 43,
62-
CrstInterfaceDispatchGlobalLists = 44,
63-
CrstInterop = 45,
64-
CrstInteropData = 46,
65-
CrstIsJMCMethod = 47,
66-
CrstISymUnmanagedReader = 48,
67-
CrstJit = 49,
68-
CrstJitInlineTrackingMap = 50,
69-
CrstJitPatchpoint = 51,
70-
CrstJumpStubCache = 52,
71-
CrstLeafLock = 53,
72-
CrstListLock = 54,
73-
CrstLoaderAllocator = 55,
74-
CrstLoaderAllocatorReferences = 56,
75-
CrstLoaderHeap = 57,
76-
CrstManagedObjectWrapperMap = 58,
77-
CrstMethodDescBackpatchInfoTracker = 59,
78-
CrstMethodTableExposedObject = 60,
79-
CrstModule = 61,
80-
CrstModuleLookupTable = 62,
81-
CrstMulticoreJitHash = 63,
82-
CrstMulticoreJitManager = 64,
83-
CrstNativeImageEagerFixups = 65,
84-
CrstNativeImageLoad = 66,
85-
CrstNotifyGdb = 67,
86-
CrstPEImage = 68,
87-
CrstPendingTypeLoadEntry = 69,
88-
CrstPerfMap = 70,
89-
CrstPgoData = 71,
90-
CrstPinnedByrefValidation = 72,
91-
CrstPinnedHeapHandleTable = 73,
92-
CrstProfilerGCRefDataFreeList = 74,
93-
CrstProfilingAPIStatus = 75,
94-
CrstRCWCache = 76,
95-
CrstRCWCleanupList = 77,
96-
CrstReadyToRunEntryPointToMethodDescMap = 78,
97-
CrstReflection = 79,
98-
CrstReJITGlobalRequest = 80,
99-
CrstSigConvert = 81,
100-
CrstSingleUseLock = 82,
101-
CrstStressLog = 83,
102-
CrstStubCache = 84,
103-
CrstStubDispatchCache = 85,
104-
CrstSyncBlockCache = 86,
105-
CrstSyncHashLock = 87,
106-
CrstSystemDomain = 88,
107-
CrstSystemDomainDelayedUnloadList = 89,
108-
CrstThreadIdDispenser = 90,
109-
CrstThreadLocalStorageLock = 91,
110-
CrstThreadStore = 92,
111-
CrstTieredCompilation = 93,
112-
CrstTypeEquivalenceMap = 94,
113-
CrstTypeIDMap = 95,
114-
CrstUMEntryThunkCache = 96,
115-
CrstUMEntryThunkFreeListLock = 97,
116-
CrstUniqueStack = 98,
117-
CrstUnresolvedClassLock = 99,
118-
CrstUnwindInfoTableLock = 100,
119-
CrstVSDIndirectionCellLock = 101,
120-
CrstWrapperTemplate = 102,
121-
kNumberOfCrstTypes = 103
23+
CrstCallStubCache = 5,
24+
CrstCCompRC = 6,
25+
CrstClassFactInfoHash = 7,
26+
CrstClassInit = 8,
27+
CrstClrNotification = 9,
28+
CrstCodeFragmentHeap = 10,
29+
CrstCodeVersioning = 11,
30+
CrstCOMCallWrapper = 12,
31+
CrstCOMWrapperCache = 13,
32+
CrstDataTest1 = 14,
33+
CrstDataTest2 = 15,
34+
CrstDbgTransport = 16,
35+
CrstDeadlockDetection = 17,
36+
CrstDebuggerController = 18,
37+
CrstDebuggerFavorLock = 19,
38+
CrstDebuggerHeapExecMemLock = 20,
39+
CrstDebuggerHeapLock = 21,
40+
CrstDebuggerJitInfo = 22,
41+
CrstDebuggerMutex = 23,
42+
CrstDynamicIL = 24,
43+
CrstDynamicMT = 25,
44+
CrstEtwTypeLogHash = 26,
45+
CrstEventPipe = 27,
46+
CrstEventStore = 28,
47+
CrstException = 29,
48+
CrstExecutableAllocatorLock = 30,
49+
CrstFCall = 31,
50+
CrstFrozenObjectHeap = 32,
51+
CrstFuncPtrStubs = 33,
52+
CrstFusionAppCtx = 34,
53+
CrstGCCover = 35,
54+
CrstGenericDictionaryExpansion = 36,
55+
CrstGlobalStrLiteralMap = 37,
56+
CrstHandleTable = 38,
57+
CrstIbcProfile = 39,
58+
CrstIJWFixupData = 40,
59+
CrstIJWHash = 41,
60+
CrstILStubGen = 42,
61+
CrstInlineTrackingMap = 43,
62+
CrstInstMethodHashTable = 44,
63+
CrstInterfaceDispatchGlobalLists = 45,
64+
CrstInterop = 46,
65+
CrstInteropData = 47,
66+
CrstIsJMCMethod = 48,
67+
CrstISymUnmanagedReader = 49,
68+
CrstJit = 50,
69+
CrstJitInlineTrackingMap = 51,
70+
CrstJitPatchpoint = 52,
71+
CrstJumpStubCache = 53,
72+
CrstLeafLock = 54,
73+
CrstListLock = 55,
74+
CrstLoaderAllocator = 56,
75+
CrstLoaderAllocatorReferences = 57,
76+
CrstLoaderHeap = 58,
77+
CrstManagedObjectWrapperMap = 59,
78+
CrstMethodDescBackpatchInfoTracker = 60,
79+
CrstMethodTableExposedObject = 61,
80+
CrstModule = 62,
81+
CrstModuleLookupTable = 63,
82+
CrstMulticoreJitHash = 64,
83+
CrstMulticoreJitManager = 65,
84+
CrstNativeImageEagerFixups = 66,
85+
CrstNativeImageLoad = 67,
86+
CrstNotifyGdb = 68,
87+
CrstPEImage = 69,
88+
CrstPendingTypeLoadEntry = 70,
89+
CrstPerfMap = 71,
90+
CrstPgoData = 72,
91+
CrstPinnedByrefValidation = 73,
92+
CrstPinnedHeapHandleTable = 74,
93+
CrstProfilerGCRefDataFreeList = 75,
94+
CrstProfilingAPIStatus = 76,
95+
CrstRCWCache = 77,
96+
CrstRCWCleanupList = 78,
97+
CrstReadyToRunEntryPointToMethodDescMap = 79,
98+
CrstReflection = 80,
99+
CrstReJITGlobalRequest = 81,
100+
CrstSigConvert = 82,
101+
CrstSingleUseLock = 83,
102+
CrstStressLog = 84,
103+
CrstStubCache = 85,
104+
CrstStubDispatchCache = 86,
105+
CrstSyncBlockCache = 87,
106+
CrstSyncHashLock = 88,
107+
CrstSystemDomain = 89,
108+
CrstSystemDomainDelayedUnloadList = 90,
109+
CrstThreadIdDispenser = 91,
110+
CrstThreadLocalStorageLock = 92,
111+
CrstThreadStore = 93,
112+
CrstTieredCompilation = 94,
113+
CrstTypeEquivalenceMap = 95,
114+
CrstTypeIDMap = 96,
115+
CrstUMEntryThunkCache = 97,
116+
CrstUMEntryThunkFreeListLock = 98,
117+
CrstUniqueStack = 99,
118+
CrstUnresolvedClassLock = 100,
119+
CrstUnwindInfoTableLock = 101,
120+
CrstVSDIndirectionCellLock = 102,
121+
CrstWrapperTemplate = 103,
122+
kNumberOfCrstTypes = 104
122123
};
123124

124125
#endif // __CRST_TYPES_INCLUDED
@@ -134,6 +135,7 @@ int g_rgCrstLevelMap[] =
134135
13, // CrstAssemblyLoader
135136
3, // CrstAvailableClass
136137
4, // CrstAvailableParamTypes
138+
3, // CrstCallStubCache
137139
-1, // CrstCCompRC
138140
14, // CrstClassFactInfoHash
139141
10, // CrstClassInit
@@ -242,6 +244,7 @@ LPCSTR g_rgCrstNameMap[] =
242244
"CrstAssemblyLoader",
243245
"CrstAvailableClass",
244246
"CrstAvailableParamTypes",
247+
"CrstCallStubCache",
245248
"CrstCCompRC",
246249
"CrstClassFactInfoHash",
247250
"CrstClassInit",

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ void* GetCookieForPInvokeCalliSig(
590590
CORINFO_SIG_INFO* szMetaSig,
591591
void** ppIndirection) override;
592592

593+
void* GetCookieForInterpreterCalliSig(
594+
CORINFO_SIG_INFO* szMetaSig) override;
595+
593596
bool canGetCookieForPInvokeCalliSig(
594597
CORINFO_SIG_INFO* szMetaSig) override;
595598

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 = { /* ecc9bc7e-9223-4af6-af2f-b63e89c09279 */
41-
0xecc9bc7e,
42-
0x9223,
43-
0x4af6,
44-
{0xaf, 0x2f, 0xb6, 0x3e, 0x89, 0xc0, 0x92, 0x79}
40+
constexpr GUID JITEEVersionIdentifier = { /* f9f14a77-1225-42d0-a21e-6d8b45506fc6 */
41+
0xf9f14a77,
42+
0x1225,
43+
0x42d0,
44+
{0xa2, 0x1e, 0x6d, 0x8b, 0x45, 0x50, 0x6f, 0xc6}
4545
};
4646

4747
#endif // JIT_EE_VERSIONING_GUID_H

0 commit comments

Comments
 (0)