From 9b6b90c425b5b0d35337f3478ac262510c897b43 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 26 Jun 2023 00:46:11 +0200 Subject: [PATCH 01/15] Modify JIT-EE API --- src/coreclr/inc/corinfo.h | 3 +- src/coreclr/inc/icorjitinfoimpl_generated.h | 3 +- src/coreclr/inc/jiteeversionguid.h | 10 +++--- .../jit/ICorJitInfo_wrapper_generated.hpp | 5 +-- .../tools/Common/JitInterface/CorInfoImpl.cs | 2 +- .../JitInterface/CorInfoImpl_generated.cs | 6 ++-- .../ThunkGenerator/ThunkInput.txt | 2 +- .../aot/jitinterface/jitinterface_generated.h | 7 ++-- .../tools/superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi-shared/methodcontext.cpp | 33 +++++++++++-------- .../superpmi/superpmi-shared/methodcontext.h | 6 ++-- .../superpmi-shim-collector/icorjitinfo.cpp | 9 ++--- .../icorjitinfo_generated.cpp | 5 +-- .../icorjitinfo_generated.cpp | 5 +-- .../tools/superpmi/superpmi/icorjitinfo.cpp | 7 ++-- src/coreclr/vm/jitinterface.cpp | 3 +- 16 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 83d007e5a436b..9aa4b15ff7475 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2040,7 +2040,8 @@ class ICorStaticInfo // This method is used to fetch data needed to inline functions virtual bool getMethodInfo ( CORINFO_METHOD_HANDLE ftn, /* IN */ - CORINFO_METHOD_INFO* info /* OUT */ + CORINFO_METHOD_INFO* info, /* OUT */ + CORINFO_CONTEXT_HANDLE context = NULL /* IN */ ) = 0; // Decides if you have any limitations for inlining. If everything's OK, it will return diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 5a7b737b85168..78ab5ff7ec874 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -38,7 +38,8 @@ void getMethodSig( bool getMethodInfo( CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info) override; + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context) override; CorInfoInline canInline( CORINFO_METHOD_HANDLE callerHnd, diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 36f906df5e7ed..09c134484477e 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 88398e9f-093a-4212-85bc-bebb8c14cd24 */ - 0x88398e9f, - 0x093a, - 0x4212, - {0x85, 0xbc, 0xbe, 0xbb, 0x8c, 0x14, 0xcd, 0x24} +constexpr GUID JITEEVersionIdentifier = { /* dddb8c13-5d86-49cc-89a4-4092152ae237 */ + 0xdddb8c13, + 0x5d86, + 0x49cc, + {0x89, 0xa4, 0x40, 0x92, 0x15, 0x2a, 0xe2, 0x37} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 6d08b04259688..b4220332d2dfa 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -51,10 +51,11 @@ void WrapICorJitInfo::getMethodSig( bool WrapICorJitInfo::getMethodInfo( CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info) + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context) { API_ENTER(getMethodInfo); - bool temp = wrapHnd->getMethodInfo(ftn, info); + bool temp = wrapHnd->getMethodInfo(ftn, info, context); API_LEAVE(getMethodInfo); return temp; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 5c3eb76470fa3..cb3e139d1eb4a 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1179,7 +1179,7 @@ private void getMethodSig(CORINFO_METHOD_STRUCT_* ftn, CORINFO_SIG_INFO* sig, CO Get_CORINFO_SIG_INFO(method, sig: sig, scope: null); } - private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* info) + private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_STRUCT* context) { MethodDesc method = HandleToObject(ftn); #if READYTORUN diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index b31a87daec7c7..5efe1ce02993b 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -71,12 +71,12 @@ private static void _getMethodSig(IntPtr thisHandle, IntPtr* ppException, CORINF } [UnmanagedCallersOnly] - private static byte _getMethodInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* info) + private static byte _getMethodInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_STRUCT* context) { var _this = GetThis(thisHandle); try { - return _this.getMethodInfo(ftn, info) ? (byte)1 : (byte)0; + return _this.getMethodInfo(ftn, info, context) ? (byte)1 : (byte)0; } catch (Exception ex) { @@ -2498,7 +2498,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; callbacks[2] = (delegate* unmanaged)&_setMethodAttribs; callbacks[3] = (delegate* unmanaged)&_getMethodSig; - callbacks[4] = (delegate* unmanaged)&_getMethodInfo; + callbacks[4] = (delegate* unmanaged)&_getMethodInfo; callbacks[5] = (delegate* unmanaged)&_canInline; callbacks[6] = (delegate* unmanaged)&_beginInlining; callbacks[7] = (delegate* unmanaged)&_reportInliningDecision; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 4bec715c809bd..3cde7c6a2623e 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -163,7 +163,7 @@ FUNCTIONS uint32_t getMethodAttribs( CORINFO_METHOD_HANDLE ftn ); void setMethodAttribs( CORINFO_METHOD_HANDLE ftn, CorInfoMethodRuntimeFlags attribs ); void getMethodSig( CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO *sig, CORINFO_CLASS_HANDLE memberParent ); - bool getMethodInfo( CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info ); + bool getMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context); CorInfoInline canInline( CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE calleeHnd); void beginInlining(CORINFO_METHOD_HANDLE inlinerHnd, CORINFO_METHOD_HANDLE inlineeHnd); void reportInliningDecision(CORINFO_METHOD_HANDLE inlinerHnd, CORINFO_METHOD_HANDLE inlineeHnd, CorInfoInline inlineResult, const char * reason); diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 24c21759692ab..cc721bfb0e0a6 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -15,7 +15,7 @@ struct JitInterfaceCallbacks uint32_t (* getMethodAttribs)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn); void (* setMethodAttribs)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CorInfoMethodRuntimeFlags attribs); void (* getMethodSig)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO* sig, CORINFO_CLASS_HANDLE memberParent); - bool (* getMethodInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info); + bool (* getMethodInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context); CorInfoInline (* canInline)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE callerHnd, CORINFO_METHOD_HANDLE calleeHnd); void (* beginInlining)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE inlinerHnd, CORINFO_METHOD_HANDLE inlineeHnd); void (* reportInliningDecision)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE inlinerHnd, CORINFO_METHOD_HANDLE inlineeHnd, CorInfoInline inlineResult, const char* reason); @@ -233,10 +233,11 @@ class JitInterfaceWrapper : public ICorJitInfo virtual bool getMethodInfo( CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info) + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context) { CorInfoExceptionClass* pException = nullptr; - bool temp = _callbacks->getMethodInfo(_thisHandle, &pException, ftn, info); + bool temp = _callbacks->getMethodInfo(_thisHandle, &pException, ftn, info, context); if (pException != nullptr) throw pException; return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index 3eb6ddd698fd5..381278ecea502 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -105,7 +105,7 @@ LWM(GetAssemblyName, DWORDLONG, DWORD) LWM(GetMethodClass, DWORDLONG, DWORDLONG) LWM(GetMethodDefFromMethod, DWORDLONG, DWORD) LWM(GetMethodHash, DWORDLONG, DWORD) -LWM(GetMethodInfo, DWORDLONG, Agnostic_GetMethodInfo) +LWM(GetMethodInfo, DLDL, Agnostic_GetMethodInfo) LWM(GetMethodNameFromMetadata, Agnostic_CORINFO_METHODNAME_TOKENin, Agnostic_CORINFO_METHODNAME_TOKENout) LWM(GetMethodSig, DLDL, Agnostic_CORINFO_SIG_INFO) LWM(GetMethodSync, DWORDLONG, DLDL) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 8f11b2cb71c96..3cae414a097de 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -2939,13 +2939,14 @@ CorInfoHFAElemType MethodContext::repGetHFAType(CORINFO_CLASS_HANDLE clsHnd) return (CorInfoHFAElemType)value; } -void MethodContext::recGetMethodInfo(CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info, - bool result, - DWORD exceptionCode) +void MethodContext::recGetMethodInfo(CORINFO_METHOD_HANDLE ftn, + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context, + bool result, + DWORD exceptionCode) { if (GetMethodInfo == nullptr) - GetMethodInfo = new LightWeightMap(); + GetMethodInfo = new LightWeightMap(); Agnostic_GetMethodInfo value; ZeroMemory(&value, sizeof(value)); @@ -2967,16 +2968,18 @@ void MethodContext::recGetMethodInfo(CORINFO_METHOD_HANDLE ftn, value.result = result; value.exceptionCode = (DWORD)exceptionCode; - DWORDLONG key = CastHandle(ftn); + DLDL key; + key.A = CastHandle(ftn); + key.B = CastHandle(context); GetMethodInfo->Add(key, value); DEBUG_REC(dmpGetMethodInfo(key, value)); } -void MethodContext::dmpGetMethodInfo(DWORDLONG key, const Agnostic_GetMethodInfo& value) +void MethodContext::dmpGetMethodInfo(DLDL key, const Agnostic_GetMethodInfo& value) { if (value.result) { - printf("GetMethodInfo key ftn-%016" PRIX64 ", value res-%u ftn-%016" PRIX64 " scp-%016" PRIX64 " ilo-%u ils-%u ms-%u ehc-%u opt-%08X rk-%u args-%s locals-%s excp-%08X", - key, value.result, value.info.ftn, value.info.scope, value.info.ILCode_offset, value.info.ILCodeSize, + printf("GetMethodInfo key ftn-%016" PRIX64 " ctx-%016" PRIX64 ", value res-%u ftn-%016" PRIX64 " scp-%016" PRIX64 " ilo-%u ils-%u ms-%u ehc-%u opt-%08X rk-%u args-%s locals-%s excp-%08X", + key.A, key.B, value.result, value.info.ftn, value.info.scope, value.info.ILCode_offset, value.info.ILCodeSize, value.info.maxStack, value.info.EHcount, value.info.options, value.info.regionKind, SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO(value.info.args, GetMethodInfo, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO(value.info.locals, GetMethodInfo, SigInstHandleMap).c_str(), @@ -2984,14 +2987,16 @@ void MethodContext::dmpGetMethodInfo(DWORDLONG key, const Agnostic_GetMethodInfo } else { - printf("GetMethodInfo key ftn-%016" PRIX64 ", value res-%u excp-%08X", - key, value.result, value.exceptionCode); + printf("GetMethodInfo key ftn-%016" PRIX64 " ctx-%016" PRIX64 ", value res-%u excp-%08X", + key.A, key.B, value.result, value.exceptionCode); } } -bool MethodContext::repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, DWORD* exceptionCode) +bool MethodContext::repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context, DWORD* exceptionCode) { - DWORDLONG key = CastHandle(ftn); - Agnostic_GetMethodInfo value = LookupByKeyOrMiss(GetMethodInfo, key, ": key %016" PRIX64 "", key); + DLDL key; + key.A = CastHandle(ftn); + key.B = CastHandle(context); + Agnostic_GetMethodInfo value = LookupByKeyOrMiss(GetMethodInfo, key, ": key %016" PRIX64 "", key.A); DEBUG_REP(dmpGetMethodInfo(key, value)); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 1300451268026..5e4559d0be8df 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -402,9 +402,9 @@ class MethodContext void dmpGetHFAType(DWORDLONG key, DWORD value); CorInfoHFAElemType repGetHFAType(CORINFO_CLASS_HANDLE clsHnd); - void recGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, bool result, DWORD exceptionCode); - void dmpGetMethodInfo(DWORDLONG key, const Agnostic_GetMethodInfo& value); - bool repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, DWORD* exceptionCode); + void recGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context, bool result, DWORD exceptionCode); + void dmpGetMethodInfo(DLDL key, const Agnostic_GetMethodInfo& value); + bool repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context, DWORD* exceptionCode); void recGetNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 145b7ee9fce3f..3ac7b197d64ed 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -68,8 +68,9 @@ void interceptor_ICJI::getMethodSig(CORINFO_METHOD_HANDLE ftn, /* IN */ // return information about a method private to the implementation // returns false if method is not IL, or is otherwise unavailable. // This method is used to fetch data needed to inline functions -bool interceptor_ICJI::getMethodInfo(CORINFO_METHOD_HANDLE ftn, /* IN */ - CORINFO_METHOD_INFO* info /* OUT */ +bool interceptor_ICJI::getMethodInfo(CORINFO_METHOD_HANDLE ftn, /* IN */ + CORINFO_METHOD_INFO* info, /* OUT */ + CORINFO_CONTEXT_HANDLE context /* IN */ ) { bool temp = false; @@ -78,11 +79,11 @@ bool interceptor_ICJI::getMethodInfo(CORINFO_METHOD_HANDLE ftn, /* IN */ [&]() { mc->cr->AddCall("getMethodInfo"); - temp = original_ICorJitInfo->getMethodInfo(ftn, info); + temp = original_ICorJitInfo->getMethodInfo(ftn, info, context); }, [&](DWORD exceptionCode) { - this->mc->recGetMethodInfo(ftn, info, temp, exceptionCode); + this->mc->recGetMethodInfo(ftn, info, context, temp, exceptionCode); }); return temp; diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 70f64123a4790..dfd1ceafaa844 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -45,10 +45,11 @@ void interceptor_ICJI::getMethodSig( bool interceptor_ICJI::getMethodInfo( CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info) + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context) { mcs->AddCall("getMethodInfo"); - return original_ICorJitInfo->getMethodInfo(ftn, info); + return original_ICorJitInfo->getMethodInfo(ftn, info, context); } CorInfoInline interceptor_ICJI::canInline( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index fb2d3246a9689..88cd93078f490 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -41,9 +41,10 @@ void interceptor_ICJI::getMethodSig( bool interceptor_ICJI::getMethodInfo( CORINFO_METHOD_HANDLE ftn, - CORINFO_METHOD_INFO* info) + CORINFO_METHOD_INFO* info, + CORINFO_CONTEXT_HANDLE context) { - return original_ICorJitInfo->getMethodInfo(ftn, info); + return original_ICorJitInfo->getMethodInfo(ftn, info, context); } CorInfoInline interceptor_ICJI::canInline( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 756443dce9399..691e09bd9593e 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -68,13 +68,14 @@ void MyICJI::getMethodSig(CORINFO_METHOD_HANDLE ftn, /* IN */ // return information about a method private to the implementation // returns false if method is not IL, or is otherwise unavailable. // This method is used to fetch data needed to inline functions -bool MyICJI::getMethodInfo(CORINFO_METHOD_HANDLE ftn, /* IN */ - CORINFO_METHOD_INFO* info /* OUT */ +bool MyICJI::getMethodInfo(CORINFO_METHOD_HANDLE ftn, /* IN */ + CORINFO_METHOD_INFO* info, /* OUT */ + CORINFO_CONTEXT_HANDLE context /* IN */ ) { jitInstance->mc->cr->AddCall("getMethodInfo"); DWORD exceptionCode = 0; - bool value = jitInstance->mc->repGetMethodInfo(ftn, info, &exceptionCode); + bool value = jitInstance->mc->repGetMethodInfo(ftn, info, context, &exceptionCode); if (exceptionCode != 0) ThrowException(exceptionCode); return value; diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 28c7b9eeb982c..0c1787ad3b084 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -7586,7 +7586,8 @@ static void getMethodInfoHelper( bool CEEInfo::getMethodInfo( CORINFO_METHOD_HANDLE ftnHnd, - CORINFO_METHOD_INFO * methInfo) + CORINFO_METHOD_INFO * methInfo, + CORINFO_CONTEXT_HANDLE context) { CONTRACTL { THROWS; From faa23980a230c54b7b0b7f8be1e43d5cac82aea7 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 26 Jun 2023 01:03:50 +0200 Subject: [PATCH 02/15] Copy Andy's fix --- src/coreclr/inc/jiteeversionguid.h | 10 +++++----- src/coreclr/jit/importercalls.cpp | 23 ++++++++++++++++++++++- src/coreclr/vm/jitinterface.cpp | 20 ++++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 09c134484477e..730f1350218d4 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* dddb8c13-5d86-49cc-89a4-4092152ae237 */ - 0xdddb8c13, - 0x5d86, - 0x49cc, - {0x89, 0xa4, 0x40, 0x92, 0x15, 0x2a, 0xe2, 0x37} +constexpr GUID JITEEVersionIdentifier = { /* be5f3d2c-4b67-4dd2-8bc8-ba76052b5f18 */ + 0xbe5f3d2c, + 0x4b67, + 0x4dd2, + {0x8b, 0xc8, 0xba, 0x76, 0x05, 0x2b, 0x5f, 0x18} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index eb67240252e6a..ff7e40b369e56 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -7727,11 +7727,32 @@ void Compiler::impCheckCanInline(GenTreeCall* call, return; } #endif + JITDUMP("\nCheckCanInline: fetching method info for inline candidate %s -- context %p\n", + compiler->eeGetMethodName(ftn), pParam->exactContextHnd); + + if (pParam->exactContextHnd == nullptr) + { + JITDUMP("NULL context\n"); + } + else if (pParam->exactContextHnd == METHOD_BEING_COMPILED_CONTEXT()) + { + JITDUMP("Current method context\n"); + } + else if ((((size_t)pParam->exactContextHnd & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD)) + { + JITDUMP("Method context: %s\n", + compiler->eeGetMethodName((CORINFO_METHOD_HANDLE)pParam->exactContextHnd)); + } + else + { + JITDUMP("Class context: %s\n", compiler->eeGetClassName((CORINFO_CLASS_HANDLE)( + (size_t)pParam->exactContextHnd & ~CORINFO_CONTEXTFLAGS_MASK))); + } // Fetch method info. This may fail, if the method doesn't have IL. // CORINFO_METHOD_INFO methInfo; - if (!compCompHnd->getMethodInfo(ftn, &methInfo)) + if (!compCompHnd->getMethodInfo(ftn, &methInfo, pParam->exactContextHnd)) { inlineResult->NoteFatal(InlineObservation::CALLEE_NO_METHOD_INFO); return; diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 0c1787ad3b084..5a11bc2784eac 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -7423,7 +7423,8 @@ class MethodInfoHelperContext final static void getMethodInfoHelper( MethodInfoHelperContext& cxt, - CORINFO_METHOD_INFO* methInfo) + CORINFO_METHOD_INFO* methInfo, + CORINFO_CONTEXT_HANDLE exactContext = NULL) { STANDARD_VM_CONTRACT; _ASSERTE(methInfo != NULL); @@ -7547,7 +7548,18 @@ static void getMethodInfoHelper( DWORD cbSig = 0; ftn->GetSig(&pSig, &cbSig); - SigTypeContext context(ftn); + SigTypeContext context; + + if ((exactContext == NULL) || (exactContext == METHOD_BEING_COMPILED_CONTEXT()) || + (((size_t)exactContext & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD)) + { + SigTypeContext::InitTypeContext(ftn, &context); + } + else + { + TypeHandle th = TypeHandle((CORINFO_CLASS_HANDLE)((size_t)exactContext & ~CORINFO_CONTEXTFLAGS_MASK)); + SigTypeContext::InitTypeContext(th, &context); + } /* Fetch the method signature */ // Type parameters in the signature should be instantiated according to the @@ -7605,14 +7617,14 @@ CEEInfo::getMethodInfo( MethodInfoHelperContext cxt{ ftn }; if (ftn->IsDynamicMethod()) { - getMethodInfoHelper(cxt, methInfo); + getMethodInfoHelper(cxt, methInfo, context); result = true; } else if (!ftn->IsWrapperStub() && ftn->HasILHeader()) { COR_ILMETHOD_DECODER header(ftn->GetILHeader(TRUE), ftn->GetMDImport(), NULL); cxt.Header = &header; - getMethodInfoHelper(cxt, methInfo); + getMethodInfoHelper(cxt, methInfo, context); result = true; } else if (ftn->IsIL() && ftn->GetRVA() == 0) From c3f9db98cea6c5c1e06ac8dff10bfbbe4b2bd9df Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 26 Jun 2023 14:03:33 +0200 Subject: [PATCH 03/15] test --- src/coreclr/jit/importercalls.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index ff7e40b369e56..980e2cffabb8a 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -7821,11 +7821,11 @@ void Compiler::impCheckCanInline(GenTreeCall* call, #ifdef DEBUG var_types fncRealRetType = JITtype2varType(methInfo.args.retType); - assert((genActualType(fncRealRetType) == genActualType(fncRetType)) || - // VSW 288602 - // In case of IJW, we allow to assign a native pointer to a BYREF. - (fncRetType == TYP_BYREF && methInfo.args.retType == CORINFO_TYPE_PTR) || - (varTypeIsStruct(fncRetType) && (fncRealRetType == TYP_STRUCT))); + //assert((genActualType(fncRealRetType) == genActualType(fncRetType)) || + // // VSW 288602 + // // In case of IJW, we allow to assign a native pointer to a BYREF. + // (fncRetType == TYP_BYREF && methInfo.args.retType == CORINFO_TYPE_PTR) || + // (varTypeIsStruct(fncRetType) && (fncRealRetType == TYP_STRUCT))); #endif // Allocate an InlineCandidateInfo structure, From 3192c8300d4bc63434bd53bab720c0aeffdce464 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 28 Jun 2023 23:47:29 +0200 Subject: [PATCH 04/15] bump guid --- src/coreclr/inc/jiteeversionguid.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index bdc9c7be36cf0..1585cfdabc435 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 878d63a7-ffc9-421f-81f7-db4729f0ed5c */ - 0x878d63a7, - 0xffc9, - 0x421f, - {0x81, 0xf7, 0xdb, 0x47, 0x29, 0xf0, 0xed, 0x5c} +constexpr GUID JITEEVersionIdentifier = { /* 2335da47-1d6c-4844-96b6-025558a525ba */ + 0x2335da47, + 0x1d6c, + 0x4844, + {0x96, 0xb6, 0x02, 0x55, 0x58, 0xa5, 0x25, 0xba} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// From 09aec1bf3574c735bc6743b0518ba9a70804ee95 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 30 Jun 2023 00:46:37 +0200 Subject: [PATCH 05/15] test --- src/coreclr/jit/importercalls.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 2e791471c38b3..55e5465b78969 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -7758,6 +7758,8 @@ void Compiler::impCheckCanInline(GenTreeCall* call, return; } + compCompHnd->getMethodSig(ftn, &methInfo.args); + // Profile data allows us to avoid early "too many IL bytes" outs. // inlineResult->NoteBool(InlineObservation::CALLSITE_HAS_PROFILE_WEIGHTS, From 636cbaf31db3ee9d889809550b32a576a392704d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 30 Jun 2023 01:34:46 +0200 Subject: [PATCH 06/15] Fix? --- src/coreclr/jit/importercalls.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 55e5465b78969..b39967aee2469 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -7749,17 +7749,18 @@ void Compiler::impCheckCanInline(GenTreeCall* call, (size_t)pParam->exactContextHnd & ~CORINFO_CONTEXTFLAGS_MASK))); } + const bool isGdv = pParam->call->IsGuardedDevirtualizationCandidate(); + // Fetch method info. This may fail, if the method doesn't have IL. + // NOTE: For GDV we're expected to use a different context (per candidate) // CORINFO_METHOD_INFO methInfo; - if (!compCompHnd->getMethodInfo(ftn, &methInfo, pParam->exactContextHnd)) + if (!compCompHnd->getMethodInfo(ftn, &methInfo, isGdv ? nullptr : pParam->exactContextHnd)) { inlineResult->NoteFatal(InlineObservation::CALLEE_NO_METHOD_INFO); return; } - compCompHnd->getMethodSig(ftn, &methInfo.args); - // Profile data allows us to avoid early "too many IL bytes" outs. // inlineResult->NoteBool(InlineObservation::CALLSITE_HAS_PROFILE_WEIGHTS, @@ -7823,11 +7824,11 @@ void Compiler::impCheckCanInline(GenTreeCall* call, #ifdef DEBUG var_types fncRealRetType = JITtype2varType(methInfo.args.retType); - //assert((genActualType(fncRealRetType) == genActualType(fncRetType)) || - // // VSW 288602 - // // In case of IJW, we allow to assign a native pointer to a BYREF. - // (fncRetType == TYP_BYREF && methInfo.args.retType == CORINFO_TYPE_PTR) || - // (varTypeIsStruct(fncRetType) && (fncRealRetType == TYP_STRUCT))); + assert((genActualType(fncRealRetType) == genActualType(fncRetType)) || + // VSW 288602 + // In case of IJW, we allow to assign a native pointer to a BYREF. + (fncRetType == TYP_BYREF && methInfo.args.retType == CORINFO_TYPE_PTR) || + (varTypeIsStruct(fncRetType) && (fncRealRetType == TYP_STRUCT))); #endif // Allocate an InlineCandidateInfo structure, From 1eddadb20d105e107cc28fca358632b2bcc00762 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 1 Jul 2023 17:44:44 +0200 Subject: [PATCH 07/15] Perhaps, like this? --- .../tools/Common/JitInterface/CorInfoImpl.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 83aae3b702553..2e3b39bdbf0b5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1182,6 +1182,20 @@ private void getMethodSig(CORINFO_METHOD_STRUCT_* ftn, CORINFO_SIG_INFO* sig, CO private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_STRUCT* context) { MethodDesc method = HandleToObject(ftn); + + if (context != null) + { + if (method.RequiresInstMethodTableArg()) + { + method = _compilation.TypeSystemContext.GetMethodForInstantiatedType( + method.GetTypicalMethodDefinition(), (InstantiatedType)typeFromContext(context)); + } + else if (method.RequiresInstMethodDescArg()) + { + method = methodFromContext(context); + } + } + #if READYTORUN // Add an early CanInline check to see if referring to the IL of the target methods is // permitted from within this MethodBeingCompiled, the full CanInline check will be performed From bca80b7539b15aed5169d5a78656b109cf2ae5cc Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 1 Jul 2023 22:52:42 +0200 Subject: [PATCH 08/15] Better version --- .../tools/Common/JitInterface/CorInfoImpl.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 2e3b39bdbf0b5..b019f6b009fb9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1183,16 +1183,17 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf { MethodDesc method = HandleToObject(ftn); - if (context != null) + if (context != null && method.IsSharedByGenericInstantiations) { - if (method.RequiresInstMethodTableArg()) + TypeSystemEntity ctx = entityFromContext(context); + if (ctx is MethodDesc methodFromCtx) { - method = _compilation.TypeSystemContext.GetMethodForInstantiatedType( - method.GetTypicalMethodDefinition(), (InstantiatedType)typeFromContext(context)); + method = methodFromCtx; } - else if (method.RequiresInstMethodDescArg()) + else if (ctx is InstantiatedType instantiatedCtxType) { - method = methodFromContext(context); + method = _compilation.TypeSystemContext.GetMethodForInstantiatedType( + method.GetTypicalMethodDefinition(), instantiatedCtxType); } } From 73d9e43e541f1e9d48073309f0397666942147f3 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Sat, 1 Jul 2023 23:42:48 +0200 Subject: [PATCH 09/15] Update src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Co-authored-by: Jan Kotas --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index b019f6b009fb9..cf10850e7348b 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1188,6 +1188,7 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf TypeSystemEntity ctx = entityFromContext(context); if (ctx is MethodDesc methodFromCtx) { + Debug.Assert(method.GetTypicalMethodDefinition() == methodFromCtx.GetTypicalMethodDefinition()); method = methodFromCtx; } else if (ctx is InstantiatedType instantiatedCtxType) From 5afc431166f7afd525e36182f27850aa5d100bca Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 2 Jul 2023 13:54:06 +0200 Subject: [PATCH 10/15] fix assert --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index b019f6b009fb9..9e7c05b2100c7 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1186,8 +1186,9 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf if (context != null && method.IsSharedByGenericInstantiations) { TypeSystemEntity ctx = entityFromContext(context); - if (ctx is MethodDesc methodFromCtx) + if (ctx is MethodDesc methodFromCtx && context != contextFromMethodBeingCompiled()) { + Debug.Assert(method.GetTypicalMethodDefinition() == methodFromCtx.GetTypicalMethodDefinition()); method = methodFromCtx; } else if (ctx is InstantiatedType instantiatedCtxType) From 5958e9e01013078c0fc36ac01a584f4050c33be1 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 2 Jul 2023 14:03:01 +0200 Subject: [PATCH 11/15] Address feedback --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 9e7c05b2100c7..43fd2a70b8a66 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1193,8 +1193,16 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf } else if (ctx is InstantiatedType instantiatedCtxType) { - method = _compilation.TypeSystemContext.GetMethodForInstantiatedType( - method.GetTypicalMethodDefinition(), instantiatedCtxType); + MethodDesc methodTypicalDef = method.GetTypicalMethodDefinition(); + if (methodTypicalDef.RequiresInstMethodDescArg()) + { + // Presumably, a rare case: we had MyClass.Foo() method and + // GetTypicalMethodDefinition() converted it to MyClass.Foo + } + else + { + method = _compilation.TypeSystemContext.GetMethodForInstantiatedType(methodTypicalDef, instantiatedCtxType); + } } } From 08ac3853365439d5c76d864ed12c11934bff4208 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 2 Jul 2023 16:11:38 +0200 Subject: [PATCH 12/15] Align behavior --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 43fd2a70b8a66..9b4ffa837fb20 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1183,15 +1183,10 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf { MethodDesc method = HandleToObject(ftn); - if (context != null && method.IsSharedByGenericInstantiations) + if (context != null && method.IsSharedByGenericInstantiations && context != contextFromMethodBeingCompiled()) { TypeSystemEntity ctx = entityFromContext(context); - if (ctx is MethodDesc methodFromCtx && context != contextFromMethodBeingCompiled()) - { - Debug.Assert(method.GetTypicalMethodDefinition() == methodFromCtx.GetTypicalMethodDefinition()); - method = methodFromCtx; - } - else if (ctx is InstantiatedType instantiatedCtxType) + if (ctx is InstantiatedType instantiatedCtxType) { MethodDesc methodTypicalDef = method.GetTypicalMethodDefinition(); if (methodTypicalDef.RequiresInstMethodDescArg()) From 72115842c86f08e34f74aab5e1cf0708abdd0c2e Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 3 Jul 2023 12:13:23 +0200 Subject: [PATCH 13/15] Use MD context on clr --- src/coreclr/vm/jitinterface.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index f39a98207b9f3..c040d83304ec6 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -7626,13 +7626,18 @@ static void getMethodInfoHelper( SigTypeContext context; - if ((exactContext == NULL) || (exactContext == METHOD_BEING_COMPILED_CONTEXT()) || - (((size_t)exactContext & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD)) + if (exactContext == NULL || exactContext == METHOD_BEING_COMPILED_CONTEXT()) { SigTypeContext::InitTypeContext(ftn, &context); } + else if (((size_t)exactContext & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_METHOD) + { + MethodDesc* contextMD = (MethodDesc*)((size_t)exactContext & ~CORINFO_CONTEXTFLAGS_MASK); + SigTypeContext::InitTypeContext(contextMD, &context); + } else { + _ASSERT(((size_t)exactContext & CORINFO_CONTEXTFLAGS_MASK) == CORINFO_CONTEXTFLAGS_CLASS); TypeHandle th = TypeHandle((CORINFO_CLASS_HANDLE)((size_t)exactContext & ~CORINFO_CONTEXTFLAGS_MASK)); SigTypeContext::InitTypeContext(th, &context); } From 81a9f0cf7005e5cb8369921feaee13abe9ea6c38 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 3 Jul 2023 14:40:12 +0200 Subject: [PATCH 14/15] Do the same for cg/ilc --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 1753cc060aa79..a64fdfa4fb692 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1183,10 +1183,15 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf { MethodDesc method = HandleToObject(ftn); - if (context != null && method.IsSharedByGenericInstantiations && context != contextFromMethodBeingCompiled()) + if (context != null && method.IsSharedByGenericInstantiations) { TypeSystemEntity ctx = entityFromContext(context); - if (ctx is InstantiatedType instantiatedCtxType) + if (ctx is MethodDesc methodFromCtx && context != contextFromMethodBeingCompiled()) + { + Debug.Assert(method.GetTypicalMethodDefinition() == methodFromCtx.GetTypicalMethodDefinition()); + method = methodFromCtx; + } + else if (ctx is InstantiatedType instantiatedCtxType) { MethodDesc methodTypicalDef = method.GetTypicalMethodDefinition(); if (methodTypicalDef.RequiresInstMethodDescArg()) From 0fc3a2e8b104d7304b333b5100aeb4caecfbedb7 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 3 Jul 2023 18:13:58 +0200 Subject: [PATCH 15/15] Update src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Co-authored-by: Jan Kotas --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index a64fdfa4fb692..10749a4cc101c 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -1193,16 +1193,12 @@ private bool getMethodInfo(CORINFO_METHOD_STRUCT_* ftn, CORINFO_METHOD_INFO* inf } else if (ctx is InstantiatedType instantiatedCtxType) { - MethodDesc methodTypicalDef = method.GetTypicalMethodDefinition(); - if (methodTypicalDef.RequiresInstMethodDescArg()) + MethodDesc instantiatedMethod = _compilation.TypeSystemContext.GetMethodForInstantiatedType(method.GetTypicalMethodDefinition(), instantiatedCtxType); + if (method.HasInstantiation) { - // Presumably, a rare case: we had MyClass.Foo() method and - // GetTypicalMethodDefinition() converted it to MyClass.Foo - } - else - { - method = _compilation.TypeSystemContext.GetMethodForInstantiatedType(methodTypicalDef, instantiatedCtxType); + instantiatedMethod = _compilation.TypeSystemContext.GetInstantiatedMethod(instantiatedMethod, method.Instantiation); } + method = instantiatedMethod; } }