From ba63deb21061d7516d301f857c37f674c021090d Mon Sep 17 00:00:00 2001 From: Simon Nattress Date: Wed, 3 Feb 2021 16:54:57 -0800 Subject: [PATCH] Pass opaque method signature handle between JIT/CG2 (#47779) * Crossgen2 presently abuses the `CORINFO_SIG_INFO` pSig field to pass a handle representing a managed method signature object which the JIT passes back to us later in compilation. This field is for byte arrays and causes problems with SuperPMI which rightly doesn't know how to interpret a zero-length buffer whose pointer is set. * Introduce a new field ,`methodSignature` where we pass the handle back to the JIT. This pattern saves us from allocating and pinning a byte buffer for signatures, something the native code VM and Crossgen1 don't have to worry about. * Add strongly typed `ObjectToHandle` and `HandleToObject` methods for `CORINFO_MODULE_STRUCT_` <=> `MethodIL` and `MethodSignatureInfo` <=> `MethodSignature`. * Add SuperPMI support for CORINFO_SIG_INFO.methodSignature Co-authored-by: Bruce Forstall --- .../superpmi/superpmi-shared/agnostic.h | 6 +-- .../superpmi-shared/methodcontext.cpp | 54 +++++-------------- .../superpmi/superpmi-shared/spmidumphelper.h | 4 +- .../superpmi-shared/spmirecordhelper.h | 20 ++----- src/coreclr/inc/corinfo.h | 6 ++- src/coreclr/inc/jiteeversionguid.h | 10 ++-- .../tools/Common/JitInterface/CorInfoImpl.cs | 47 ++++++++-------- .../tools/Common/JitInterface/CorInfoTypes.cs | 15 ++++-- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 10 ++-- src/coreclr/vm/jitinterface.cpp | 1 + 10 files changed, 75 insertions(+), 98 deletions(-) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/agnostic.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/agnostic.h index b00b3fe907d..4e04aafe1e8 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/agnostic.h @@ -27,7 +27,7 @@ struct Agnostic_CORINFO_SIG_INFO DWORDLONG args; DWORD pSig_Index; DWORD cbSig; - DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr) + DWORDLONG methodSignature; DWORDLONG scope; DWORD token; }; @@ -136,7 +136,7 @@ struct Agnostic_GetArgType_Key DWORD sigInst_classInst_Index; DWORD sigInst_methInstCount; DWORD sigInst_methInst_Index; - DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr) + DWORDLONG methodSignature; DWORDLONG scope; // Other getArgType() arguments @@ -149,9 +149,9 @@ struct Agnostic_GetArgClass_Key DWORD sigInst_classInst_Index; DWORD sigInst_methInstCount; DWORD sigInst_methInst_Index; + DWORDLONG methodSignature; DWORDLONG scope; DWORDLONG args; - DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr) }; struct Agnostic_GetBoundaries diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 7f44c9d6ae7..c6e23639397 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -2524,21 +2524,15 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig, // TODO: verify that the above comment is still true (that some of the fields of incoming argument `sig` contain garbage), or // can we store the whole thing and use StoreAgnostic_CORINFO_SIG_INFO()? - key.flags = (DWORD)sig->flags; - key.numArgs = (DWORD)sig->numArgs; - - if ((sig->cbSig == 0) && (sig->pSig != nullptr)) - { - // In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer - // to an object), not a pointer to an array of signature bytes. Store the handle itself. - key.sigHandle = CastHandle((void*)sig->pSig); - } + key.flags = (DWORD)sig->flags; + key.numArgs = (DWORD)sig->numArgs; SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index); - key.scope = CastHandle(sig->scope); - key.args = CastHandle(args); + key.methodSignature = CastPointer(sig->methodSignature); + key.scope = CastHandle(sig->scope); + key.args = CastHandle(args); Agnostic_GetArgType_Value value; value.vcTypeRet = CastHandle(*vcTypeRet); @@ -2550,12 +2544,11 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig, } void MethodContext::dmpGetArgType(const Agnostic_GetArgType_Key& key, const Agnostic_GetArgType_Value& value) { - printf("GetArgType key flg-%08X na-%u sigHnd-%016llX %s %s scp-%016llX arg-%016llX", + printf("GetArgType key flg-%08X na-%u %s %s msig-%016llX scp-%016llX arg-%016llX", key.flags, key.numArgs, - key.sigHandle, SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(), - key.scope, key.args); + key.methodSignature, key.scope, key.args); printf(", value result(cit)-%u(%s) vcType-%016llX excp-%08X", value.result, toString((CorInfoTypeWithMod)value.result), value.vcTypeRet, value.exceptionCode); } CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig, @@ -2572,16 +2565,9 @@ CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig, key.flags = (DWORD)sig->flags; key.numArgs = (DWORD)sig->numArgs; - - if ((sig->cbSig == 0) && (sig->pSig != nullptr)) - { - // In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer - // to an object), not a pointer to an array of signature bytes. Store the handle itself. - key.sigHandle = CastHandle((void*)sig->pSig); - } - key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount; key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount; + key.methodSignature = CastPointer(sig->methodSignature); key.scope = CastHandle(sig->scope); key.args = CastHandle(args); @@ -2674,15 +2660,9 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig, SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index); - key.scope = CastHandle(sig->scope); - key.args = CastHandle(args); - - if ((sig->cbSig == 0) && (sig->pSig != nullptr)) - { - // In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer - // to an object), not a pointer to an array of signature bytes. Store the handle itself. - key.sigHandle = CastHandle((void*)sig->pSig); - } + key.methodSignature = CastPointer(sig->methodSignature); + key.scope = CastHandle(sig->scope); + key.args = CastHandle(args); Agnostic_GetArgClass_Value value; value.result = CastHandle(result); @@ -2693,10 +2673,10 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig, } void MethodContext::dmpGetArgClass(const Agnostic_GetArgClass_Key& key, const Agnostic_GetArgClass_Value& value) { - printf("GetArgClass key %s %s scp-%016llX args-%016llX sigHnd-%016llX", + printf("GetArgClass key %s %s msig-%016llX scp-%016llX args-%016llX", SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(), - key.scope, key.args, key.sigHandle); + key.methodSignature, key.scope, key.args); printf(", value %016llX excp-%08X", value.result, value.exceptionCode); } CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig, @@ -2712,16 +2692,10 @@ CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig, key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount; key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount; + key.methodSignature = CastPointer(sig->methodSignature); key.scope = CastHandle(sig->scope); key.args = CastHandle(args); - if ((sig->cbSig == 0) && (sig->pSig != nullptr)) - { - // In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer - // to an object), not a pointer to an array of signature bytes. Store the handle itself. - key.sigHandle = CastHandle((void*)sig->pSig); - } - key.sigInst_classInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap); key.sigInst_methInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap); diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.h index 8908a8b74a6..977efc70c69 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmidumphelper.h @@ -162,8 +162,8 @@ inline std::string SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO( FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "cc", "ci", sigInfo.sigInst_classInstCount, sigInfo.sigInst_classInst_Index, handleMap); FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "mc", "mi", sigInfo.sigInst_methInstCount, sigInfo.sigInst_methInst_Index, handleMap); - cch = sprintf_s(pbuf, sizeOfBuffer, " args-%016llX sig-%s sigHnd-%016llX scp-%016llX tok-%08X}", - sigInfo.args, DumpPSig(sigInfo.pSig_Index, sigInfo.cbSig, buffers).c_str(), sigInfo.sigHandle, sigInfo.scope, sigInfo.token); + cch = sprintf_s(pbuf, sizeOfBuffer, " args-%016llX sig-%s msig-%016llX scp-%016llX tok-%08X}", + sigInfo.args, DumpPSig(sigInfo.pSig_Index, sigInfo.cbSig, buffers).c_str(), sigInfo.methodSignature, sigInfo.scope, sigInfo.token); pbuf += cch; sizeOfBuffer -= cch; diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmirecordhelper.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmirecordhelper.h index 6b996f9fc87..fa829797a0e 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/spmirecordhelper.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/spmirecordhelper.h @@ -218,12 +218,7 @@ inline Agnostic_CORINFO_SIG_INFO SpmiRecordsHelper::CreateAgnostic_CORINFO_SIG_I sig.sigInst_methInstCount = (DWORD)sigInfo.sigInst.methInstCount; sig.args = CastHandle(sigInfo.args); sig.cbSig = (DWORD)sigInfo.cbSig; - if ((sigInfo.cbSig == 0) && (sigInfo.pSig != nullptr)) - { - // In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer - // to an object), not a pointer to an array of signature bytes. Store the handle itself. - sig.sigHandle = CastHandle((void*)sigInfo.pSig); - } + sig.methodSignature = CastPointer(sigInfo.methodSignature); sig.scope = CastHandle(sigInfo.scope); sig.token = (DWORD)sigInfo.token; return sig; @@ -391,16 +386,9 @@ inline CORINFO_SIG_INFO SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(const Agnost sig.flags = (unsigned)sigInfo.flags; sig.numArgs = (unsigned)sigInfo.numArgs; sig.args = (CORINFO_ARG_LIST_HANDLE)sigInfo.args; - if (sigInfo.sigHandle != 0) - { - sig.cbSig = 0; - sig.pSig = (PCCOR_SIGNATURE)sigInfo.sigHandle; - } - else - { - sig.cbSig = (unsigned int)sigInfo.cbSig; - sig.pSig = (PCCOR_SIGNATURE)buffers->GetBuffer(sigInfo.pSig_Index); - } + sig.cbSig = (unsigned int)sigInfo.cbSig; + sig.pSig = (PCCOR_SIGNATURE)buffers->GetBuffer(sigInfo.pSig_Index); + sig.methodSignature = (MethodSignatureInfo*)sigInfo.methodSignature; sig.scope = (CORINFO_MODULE_HANDLE)sigInfo.scope; sig.token = (mdToken)sigInfo.token; diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index bdaae65d65f..97e044fc895 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1048,6 +1048,9 @@ typedef struct CORINFO_VarArgInfo * CORINFO_VARARGS_HANDLE; // (or the open instantiation) is being referred to. typedef struct CORINFO_CONTEXT_STRUCT_* CORINFO_CONTEXT_HANDLE; +// MethodSignatureInfo is an opaque handle for passing method signature information across the Jit/EE interface +struct MethodSignatureInfo; + typedef struct CORINFO_DEPENDENCY_STRUCT_ { CORINFO_MODULE_HANDLE moduleFrom; @@ -1091,10 +1094,11 @@ struct CORINFO_SIG_INFO CorInfoType retType : 8; unsigned flags : 8; // used by IL stubs code unsigned numArgs : 16; - struct CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code + struct CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code CORINFO_ARG_LIST_HANDLE args; PCCOR_SIGNATURE pSig; unsigned cbSig; + MethodSignatureInfo* methodSignature;// used in place of pSig and cbSig to reference a method signature object handle CORINFO_MODULE_HANDLE scope; // passed to getArgClass mdToken token; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 5383dd1d8ef..6c2aeea227b 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -32,11 +32,11 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////// // -constexpr GUID JITEEVersionIdentifier = { /* a904114d-6fe1-4884-82ab-47849d22d882 */ - 0xa904114d, - 0x6fe1, - 0x4884, - {0x82, 0xab, 0x47, 0x84, 0x9d, 0x22, 0xd8, 0x82} +constexpr GUID JITEEVersionIdentifier = { /* 20017875-6552-4375-80A8-F7E2CFC6AAB7 */ + 0x20017875, + 0x6552, + 0x4375, + { 0x80, 0xa8, 0xf7, 0xe2, 0xcf, 0xc6, 0xaa, 0xb7 } }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index de53d7caa72..01cddcf9c37 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -298,7 +298,7 @@ private void PublishCode() _methodCodeNode.Fixups.Add(node); } #else - MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)_methodScope); + MethodIL methodIL = HandleToObject(_methodScope); CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(ref _additionalDependencies, _compilation.NodeFactory, MethodBeingCompiled, methodIL); _methodCodeNode.InitializeNonRelocationDependencies(_additionalDependencies); #endif @@ -445,14 +445,16 @@ private Object HandleToObject(IntPtr handle) return _handleToObject[index]; } - private MethodDesc HandleToObject(CORINFO_METHOD_STRUCT_* method) { return (MethodDesc)HandleToObject((IntPtr)method); } - private CORINFO_METHOD_STRUCT_* ObjectToHandle(MethodDesc method) { return (CORINFO_METHOD_STRUCT_*)ObjectToHandle((Object)method); } - - private TypeDesc HandleToObject(CORINFO_CLASS_STRUCT_* type) { return (TypeDesc)HandleToObject((IntPtr)type); } - private CORINFO_CLASS_STRUCT_* ObjectToHandle(TypeDesc type) { return (CORINFO_CLASS_STRUCT_*)ObjectToHandle((Object)type); } - - private FieldDesc HandleToObject(CORINFO_FIELD_STRUCT_* field) { return (FieldDesc)HandleToObject((IntPtr)field); } - private CORINFO_FIELD_STRUCT_* ObjectToHandle(FieldDesc field) { return (CORINFO_FIELD_STRUCT_*)ObjectToHandle((Object)field); } + private MethodDesc HandleToObject(CORINFO_METHOD_STRUCT_* method) => (MethodDesc)HandleToObject((IntPtr)method); + private CORINFO_METHOD_STRUCT_* ObjectToHandle(MethodDesc method) => (CORINFO_METHOD_STRUCT_*)ObjectToHandle((Object)method); + private TypeDesc HandleToObject(CORINFO_CLASS_STRUCT_* type) => (TypeDesc)HandleToObject((IntPtr)type); + private CORINFO_CLASS_STRUCT_* ObjectToHandle(TypeDesc type) => (CORINFO_CLASS_STRUCT_*)ObjectToHandle((Object)type); + private FieldDesc HandleToObject(CORINFO_FIELD_STRUCT_* field) => (FieldDesc)HandleToObject((IntPtr)field); + private CORINFO_FIELD_STRUCT_* ObjectToHandle(FieldDesc field) => (CORINFO_FIELD_STRUCT_*)ObjectToHandle((object)field); + private MethodIL HandleToObject(CORINFO_MODULE_STRUCT_* module) => (MethodIL)HandleToObject((IntPtr)module); + private CORINFO_MODULE_STRUCT_* ObjectToHandle(MethodIL methodIL) => (CORINFO_MODULE_STRUCT_*)ObjectToHandle((object)methodIL); + private MethodSignature HandleToObject(MethodSignatureInfo* method) => (MethodSignature)HandleToObject((IntPtr)method); + private MethodSignatureInfo* ObjectToHandle(MethodSignature method) => (MethodSignatureInfo*)ObjectToHandle((object)method); private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORINFO_METHOD_INFO* methodInfo) { @@ -463,7 +465,7 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN } methodInfo->ftn = ObjectToHandle(method); - methodInfo->scope = (CORINFO_MODULE_STRUCT_*)ObjectToHandle(methodIL); + methodInfo->scope = ObjectToHandle(methodIL); var ilCode = methodIL.GetILBytes(); methodInfo->ILCode = (byte*)GetPin(ilCode); methodInfo->ILCodeSize = (uint)ilCode.Length; @@ -654,8 +656,9 @@ private void Get_CORINFO_SIG_INFO(MethodSignature signature, CORINFO_SIG_INFO* s sig->sigInst.methInst = null; // Not used by the JIT sig->sigInst.methInstCount = (uint)signature.GenericParameterCount; - sig->pSig = (byte*)ObjectToHandle(signature); + sig->pSig = null; sig->cbSig = 0; // Not used by the JIT + sig->methodSignature = ObjectToHandle(signature); sig->scope = null; sig->token = 0; // Not used by the JIT } @@ -677,8 +680,10 @@ private void Get_CORINFO_SIG_INFO(LocalVariableDefinition[] locals, CORINFO_SIG_ sig->args = (CORINFO_ARG_LIST_STRUCT_*)0; // CORINFO_ARG_LIST_STRUCT_ is argument index - sig->pSig = (byte*)ObjectToHandle(locals); + + sig->pSig = null; sig->cbSig = 0; // Not used by the JIT + sig->methodSignature = (MethodSignatureInfo*)ObjectToHandle(locals); sig->scope = null; // Not used by the JIT sig->token = 0; // Not used by the JIT } @@ -986,7 +991,7 @@ private void getEHinfo(CORINFO_METHOD_STRUCT_* ftn, uint EHnumber, ref CORINFO_E { return null; } - return (CORINFO_MODULE_STRUCT_*)ObjectToHandle(methodIL); + return ObjectToHandle(methodIL); } private bool resolveVirtualMethod(CORINFO_DEVIRTUALIZATION_INFO* info) @@ -1084,7 +1089,7 @@ private CorInfoCallConvExtension getUnmanagedCallConv(CORINFO_METHOD_STRUCT_* me { Debug.Assert(sig != null); - CorInfoCallConvExtension callConv = GetUnmanagedCallConv((MethodSignature)HandleToObject((IntPtr)sig->pSig), out pSuppressGCTransition); + CorInfoCallConvExtension callConv = GetUnmanagedCallConv(HandleToObject(sig->methodSignature), out pSuppressGCTransition); return callConv; } } @@ -1242,7 +1247,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe // dependency analysis operates on runtime determined ones, we convert the resolved token // to the runtime determined form (e.g. Foo<__Canon> becomes Foo). - var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + var methodIL = HandleToObject(pResolvedToken.tokenScope); var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ? MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext); @@ -1290,7 +1295,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe private void resolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) { - var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + var methodIL = HandleToObject(pResolvedToken.tokenScope); var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ? MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext); @@ -1394,7 +1399,7 @@ private bool tryResolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) { - var methodIL = (MethodIL)HandleToObject((IntPtr)module); + var methodIL = HandleToObject(module); var methodSig = (MethodSignature)methodIL.GetObject((int)sigTOK); Get_CORINFO_SIG_INFO(methodSig, sig); @@ -1412,7 +1417,7 @@ private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEX private void findCallSiteSig(CORINFO_MODULE_STRUCT_* module, uint methTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) { - var methodIL = (MethodIL)HandleToObject((IntPtr)module); + var methodIL = HandleToObject(module); Get_CORINFO_SIG_INFO(((MethodDesc)methodIL.GetObject((int)methTOK)), sig: sig); } @@ -1445,7 +1450,7 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) private char* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { - MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); + MethodIL methodIL = HandleToObject(module); string s = (string)methodIL.GetObject((int)metaTOK); length = (int)s.Length; return (char*)GetPin(s); @@ -2501,7 +2506,7 @@ private void freeArray(void* array) private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args, CORINFO_CLASS_STRUCT_** vcTypeRet) { int index = (int)args; - Object sigObj = HandleToObject((IntPtr)sig->pSig); + Object sigObj = HandleToObject((IntPtr)sig->methodSignature); MethodSignature methodSig = sigObj as MethodSignature; @@ -2526,7 +2531,7 @@ private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_ST private CORINFO_CLASS_STRUCT_* getArgClass(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args) { int index = (int)args; - Object sigObj = HandleToObject((IntPtr)sig->pSig); + Object sigObj = HandleToObject((IntPtr)sig->methodSignature); MethodSignature methodSig = sigObj as MethodSignature; if (methodSig != null) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index a6913e1474b..2b406909f27 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -69,6 +69,10 @@ public struct PatchpointInfo { } + public struct MethodSignatureInfo + { + } + public enum _EXCEPTION_POINTERS { } @@ -91,16 +95,17 @@ public enum HRESULT { public unsafe struct CORINFO_SIG_INFO { public CorInfoCallConv callConv; - public CORINFO_CLASS_STRUCT_* retTypeClass; // if the return type is a value class, this is its handle (enums are normalized) - public CORINFO_CLASS_STRUCT_* retTypeSigClass;// returns the value class as it is in the sig (enums are not converted to primitives) + public CORINFO_CLASS_STRUCT_* retTypeClass; // if the return type is a value class, this is its handle (enums are normalized) + public CORINFO_CLASS_STRUCT_* retTypeSigClass; // returns the value class as it is in the sig (enums are not converted to primitives) public byte _retType; - public CorInfoSigInfoFlags flags; // used by IL stubs code + public CorInfoSigInfoFlags flags; // used by IL stubs code public ushort numArgs; - public CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code + public CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code public CORINFO_ARG_LIST_STRUCT_* args; public byte* pSig; public uint cbSig; - public CORINFO_MODULE_STRUCT_* scope; // passed to getArgClass + public MethodSignatureInfo* methodSignature; // used in place of pSig and cbSig to reference a method signature object handle + public CORINFO_MODULE_STRUCT_* scope; // passed to getArgClass public mdToken token; public CorInfoType retType { get { return (CorInfoType)_retType; } set { _retType = (byte)value; } } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 637cf19c5d6..794320a5b9d 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -487,7 +487,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref object helperArg = GetRuntimeDeterminedObjectForToken(ref pResolvedToken); if (helperArg is MethodDesc methodDesc) { - var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + var methodIL = HandleToObject(pResolvedToken.tokenScope); MethodDesc sharedMethod = methodIL.OwningMethod.GetSharedRuntimeFormMethodTarget(); helperArg = new MethodWithToken(methodDesc, HandleToModuleToken(ref pResolvedToken), constrainedType, unboxing: false, context: sharedMethod); } @@ -878,7 +878,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) { mdToken token = pResolvedToken.token; - var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + var methodIL = HandleToObject(pResolvedToken.tokenScope); EcmaModule module; // If the method body is synthetized by the compiler (the definition of the MethodIL is not @@ -952,7 +952,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke private InfoAccessType constructStringLiteral(CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue) { - MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); + MethodIL methodIL = HandleToObject(module); // If this is not a MethodIL backed by a physical method body, we need to remap the token. Debug.Assert(methodIL.GetMethodILDefinition() is EcmaMethodIL); @@ -1453,7 +1453,7 @@ private static bool IsTypeSpecForTypicalInstantiation(TypeDesc t) constrainedType == null && exactType == MethodBeingCompiled.OwningType) { - var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); + var methodIL = HandleToObject(pResolvedToken.tokenScope); var rawMethod = (MethodDesc)methodIL.GetMethodILDefinition().GetObject((int)pResolvedToken.token); if (IsTypeSpecForTypicalInstantiation(rawMethod.OwningType)) { @@ -2516,7 +2516,7 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S } else { - var sig = (MethodSignature)HandleToObject((IntPtr)callSiteSig->pSig); + var sig = HandleToObject(callSiteSig->methodSignature); return Marshaller.IsMarshallingRequired(sig, Array.Empty()); } } diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 7f4fee170d3..6fabfae8417 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -472,6 +472,7 @@ CEEInfo::ConvToJitSig( sigRet->pSig = pSig; sigRet->cbSig = cbSig; + sigRet->methodSignature = 0; sigRet->retTypeClass = 0; sigRet->retTypeSigClass = 0; sigRet->scope = scopeHnd; -- GitLab