From b8ae90eba7dd39c596b7eb9f30fc9d9a24089141 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 19 Feb 2021 14:05:47 -0800 Subject: [PATCH 1/2] Add assembly name to SuperPMI collection For each class, add JIT/EE calls to getAssemblyName so the SuperPMI collections contain this information. This can be useful to try and track down where a particular function in a large method context hive came from. Only do this when `COMPlus_EnableExtraSuperPmiQueries=1` is set. --- .../superpmi/superpmi-shared/lwmlist.h | 3 + .../superpmi-shared/methodcontext.cpp | 88 +++++++++++++++++++ .../superpmi/superpmi-shared/methodcontext.h | 17 +++- .../superpmi-shim-collector/icorjitinfo.cpp | 12 ++- .../ToolBox/superpmi/superpmi/icorjitinfo.cpp | 16 +--- src/coreclr/inc/jiteeversionguid.h | 10 +-- src/coreclr/jit/compiler.cpp | 8 ++ 7 files changed, 132 insertions(+), 22 deletions(-) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h index a0b02d9cbb87e2..7826a25ae00d48 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -102,6 +102,9 @@ LWM(GetLazyStringLiteralHelper, DWORDLONG, DWORD) LWM(GetLikelyClass, Agnostic_GetLikelyClass, Agnostic_GetLikelyClassResult) LWM(GetLocationOfThisType, DWORDLONG, Agnostic_CORINFO_LOOKUP_KIND) LWM(GetMethodAttribs, DWORDLONG, DWORD) +LWM(GetClassModule, DWORDLONG, DWORDLONG) +LWM(GetModuleAssembly, DWORDLONG, DWORDLONG) +LWM(GetAssemblyName, DWORDLONG, DWORD) LWM(GetMethodClass, DWORDLONG, DWORDLONG) LWM(GetMethodModule, DWORDLONG, DWORDLONG) LWM(GetMethodDefFromMethod, DWORDLONG, DWORD) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 175e3a48290916..05d3bb9def052a 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -796,6 +796,94 @@ DWORD MethodContext::repGetMethodAttribs(CORINFO_METHOD_HANDLE methodHandle) return value; } +void MethodContext::recGetClassModule(CORINFO_CLASS_HANDLE cls, CORINFO_MODULE_HANDLE mod) +{ + if (GetClassModule == nullptr) + GetClassModule = new LightWeightMap(); + + GetClassModule->Add(CastHandle(cls), CastHandle(mod)); + DEBUG_REC(dmpGetClassModule(CastHandle(cls), CastHandle(mod))); +} +void MethodContext::dmpGetClassModule(DWORDLONG key, DWORDLONG value) +{ + printf("GetClassModule cls-%016llX, mod-%016llX", key, value); +} +CORINFO_MODULE_HANDLE MethodContext::repGetClassModule(CORINFO_CLASS_HANDLE cls) +{ + AssertCodeMsg(GetClassModule != nullptr, EXCEPTIONCODE_MC, + "Found a null GetClassModule for %016llX.", CastHandle(cls)); + AssertCodeMsg(GetClassModule->GetIndex(CastHandle(cls)) != -1, EXCEPTIONCODE_MC, + "Didn't find %016llX", CastHandle(cls)); + CORINFO_MODULE_HANDLE value = (CORINFO_MODULE_HANDLE)GetClassModule->Get(CastHandle(cls)); + DEBUG_REP(dmpGetClassModule(CastHandle(cls), CastHandle(value))); + return value; +} + +void MethodContext::recGetModuleAssembly(CORINFO_MODULE_HANDLE mod, CORINFO_ASSEMBLY_HANDLE assem) +{ + if (GetModuleAssembly == nullptr) + GetModuleAssembly = new LightWeightMap(); + + GetModuleAssembly->Add(CastHandle(mod), CastHandle(assem)); + DEBUG_REC(dmpGetModuleAssembly(CastHandle(mod), CastHandle(assem))); +} +void MethodContext::dmpGetModuleAssembly(DWORDLONG key, DWORDLONG value) +{ + printf("GetModuleAssembly mod-%016llX, assem-%016llX", key, value); +} +CORINFO_ASSEMBLY_HANDLE MethodContext::repGetModuleAssembly(CORINFO_MODULE_HANDLE mod) +{ + AssertCodeMsg(GetModuleAssembly != nullptr, EXCEPTIONCODE_MC, + "Found a null GetModuleAssembly for %016llX.", CastHandle(mod)); + AssertCodeMsg(GetModuleAssembly->GetIndex(CastHandle(mod)) != -1, EXCEPTIONCODE_MC, + "Didn't find %016llX", CastHandle(mod)); + CORINFO_ASSEMBLY_HANDLE value = (CORINFO_ASSEMBLY_HANDLE)GetModuleAssembly->Get(CastHandle(mod)); + DEBUG_REP(dmpGetModuleAssembly(CastHandle(mod), CastHandle(assem))); + return value; +} + +void MethodContext::recGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem, const char* assemblyName) +{ + if (GetAssemblyName == nullptr) + GetAssemblyName = new LightWeightMap(); + + DWORD value; + if (assemblyName != nullptr) + { + value = GetAssemblyName->AddBuffer((const unsigned char*)assemblyName, (DWORD)strlen(assemblyName) + 1); + } + else + { + value = (DWORD)-1; + } + + GetAssemblyName->Add(CastHandle(assem), value); + DEBUG_REC(dmpGetAssemblyName(CastHandle(mod), value)); +} +void MethodContext::dmpGetAssemblyName(DWORDLONG key, DWORD value) +{ + const char* assemblyName = (const char*)GetAssemblyName->GetBuffer(value); + printf("GetAssemblyName assem-%016llX, value-%u '%s'", key, value, assemblyName); + GetAssemblyName->Unlock(); +} +const char* MethodContext::repGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem) +{ + const char* result = "hackishAssemblyName"; + DWORD value = (DWORD)-1; + int itemIndex = -1; + if (GetAssemblyName != nullptr) + { + itemIndex = GetAssemblyName->GetIndex(CastHandle(assem)); + } + if (itemIndex >= 0) + { + value = GetAssemblyName->Get(CastHandle(assem)); + result = (const char*)GetAssemblyName->GetBuffer(value); + } + DEBUG_REP(dmpGetAssemblyName(CastHandle(assem), value)); + return result; +} + // Note - the jit will call freearray on the array we give back.... void MethodContext::recGetVars(CORINFO_METHOD_HANDLE ftn, ULONG32* cVars, diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h index 573a36d2f72a38..4851d369669537 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -106,6 +106,18 @@ class MethodContext void dmpGetMethodAttribs(DWORDLONG key, DWORD value); DWORD repGetMethodAttribs(CORINFO_METHOD_HANDLE methodHandle); + void recGetClassModule(CORINFO_CLASS_HANDLE cls, CORINFO_MODULE_HANDLE mod); + void dmpGetClassModule(DWORDLONG key, DWORDLONG value); + CORINFO_MODULE_HANDLE repGetClassModule(CORINFO_CLASS_HANDLE cls); + + void recGetModuleAssembly(CORINFO_MODULE_HANDLE mod, CORINFO_ASSEMBLY_HANDLE assem); + void dmpGetModuleAssembly(DWORDLONG key, DWORDLONG value); + CORINFO_ASSEMBLY_HANDLE repGetModuleAssembly(CORINFO_MODULE_HANDLE mod); + + void recGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem, const char* assemblyName); + void dmpGetAssemblyName(DWORDLONG key, DWORD value); + const char* repGetAssemblyName(CORINFO_ASSEMBLY_HANDLE assem); + void recGetVars(CORINFO_METHOD_HANDLE ftn, ULONG32* cVars, ICorDebugInfo::ILVarInfo** vars, bool* extendOthers); void dmpGetVars(DWORDLONG key, const Agnostic_GetVars& value); void repGetVars(CORINFO_METHOD_HANDLE ftn, ULONG32* cVars, ICorDebugInfo::ILVarInfo** vars, bool* extendOthers); @@ -869,7 +881,7 @@ class MethodContext }; // ********************* Please keep this up-to-date to ease adding more *************** -// Highest packet number: 188 +// Highest packet number: 191 // ************************************************************************************* enum mcPackets { @@ -1034,6 +1046,9 @@ enum mcPackets Packet_SigInstHandleMap = 184, Packet_AllocPgoInstrumentationBySchema = 186, // Added 1/4/2021 Packet_GetPgoInstrumentationResults = 187, // Added 1/4/2021 + Packet_GetClassModule = 189, // Added 2/19/2021 + Packet_GetModuleAssembly = 190, // Added 2/19/2021 + Packet_GetAssemblyName = 191, // Added 2/19/2021 PacketCR_AddressMap = 113, PacketCR_AllocGCInfo = 114, diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 6ba188d5987838..9f5f1e912a479d 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -608,21 +608,27 @@ bool interceptor_ICJI::isStructRequiringStackAllocRetBuf(CORINFO_CLASS_HANDLE cl CORINFO_MODULE_HANDLE interceptor_ICJI::getClassModule(CORINFO_CLASS_HANDLE cls) { mc->cr->AddCall("getClassModule"); - return original_ICorJitInfo->getClassModule(cls); + CORINFO_MODULE_HANDLE temp = original_ICorJitInfo->getClassModule(cls); + mc->recGetClassModule(cls, temp); + return temp; } // Returns the assembly that contains the module "mod". CORINFO_ASSEMBLY_HANDLE interceptor_ICJI::getModuleAssembly(CORINFO_MODULE_HANDLE mod) { mc->cr->AddCall("getModuleAssembly"); - return original_ICorJitInfo->getModuleAssembly(mod); + CORINFO_ASSEMBLY_HANDLE temp = original_ICorJitInfo->getModuleAssembly(mod); + mc->recGetModuleAssembly(mod, temp); + return temp; } // Returns the name of the assembly "assem". const char* interceptor_ICJI::getAssemblyName(CORINFO_ASSEMBLY_HANDLE assem) { mc->cr->AddCall("getAssemblyName"); - return original_ICorJitInfo->getAssemblyName(assem); + const char* temp = original_ICorJitInfo->getAssemblyName(assem); + mc->recGetAssemblyName(assem, temp); + return temp; } // Allocate and delete process-lifetime objects. Should only be diff --git a/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp index dbc80e1a72bd85..9d59f4449be613 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -489,31 +489,21 @@ bool MyICJI::isStructRequiringStackAllocRetBuf(CORINFO_CLASS_HANDLE cls) CORINFO_MODULE_HANDLE MyICJI::getClassModule(CORINFO_CLASS_HANDLE cls) { jitInstance->mc->cr->AddCall("getClassModule"); - LogError("Hit unimplemented getClassModule"); - DebugBreakorAV(28); - return (CORINFO_MODULE_HANDLE)0; - // jitInstance->mc->getClassModule(cls); + return jitInstance->mc->repGetClassModule(cls); } // Returns the assembly that contains the module "mod". CORINFO_ASSEMBLY_HANDLE MyICJI::getModuleAssembly(CORINFO_MODULE_HANDLE mod) { jitInstance->mc->cr->AddCall("getModuleAssembly"); - LogError("Hit unimplemented getModuleAssembly"); - DebugBreakorAV(28); - return (CORINFO_ASSEMBLY_HANDLE)0; - - // return jitInstance->mc->getModuleAssembly(mod); + return jitInstance->mc->repGetModuleAssembly(mod); } // Returns the name of the assembly "assem". const char* MyICJI::getAssemblyName(CORINFO_ASSEMBLY_HANDLE assem) { jitInstance->mc->cr->AddCall("getAssemblyName"); - LogError("Hit unimplemented getAssemblyName"); - DebugBreakorAV(28); - return nullptr; - // return jitInstance->mc->getAssemblyName(assem); + return jitInstance->mc->repGetAssemblyName(assem); } // Allocate and delete process-lifetime objects. Should only be diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 8d356ee92323c6..07843243c24f6a 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 = { /* ba99f659-11ae-4c05-bdad-650cb5104f26 */ - 0xba99f659, - 0x11ae, - 0x4c05, - {0xbd, 0xad, 0x65, 0x0c, 0xb5, 0x10, 0x4f, 0x26} +constexpr GUID JITEEVersionIdentifier = { /* 73d20c3a-75a9-4eea-a952-60419d67b6a6 */ + 0x73d20c3a, + 0x75a9, + 0x4eea, + {0xa9, 0x52, 0x60, 0x41, 0x9d, 0x67, 0xb6, 0xa6} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 17b86c8c74e6c7..21851cdef1ddf6 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -5583,6 +5583,14 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr, info.compClassAttr = info.compCompHnd->getClassAttribs(info.compClassHnd); } +#ifdef DEBUG + if (JitConfig.EnableExtraSuperPmiQueries()) + { + // Get the assembly name, to aid finding any particular SuperPMI method context function + (void)info.compCompHnd->getAssemblyName(info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd))); + } +#endif // DEBUG + info.compProfilerCallback = false; // Assume false until we are told to hook this method. #if defined(DEBUG) || defined(LATE_DISASM) From 7fef531a96eea45f4626032bb9f618fa0b0bcc2f Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Sat, 20 Feb 2021 11:16:11 -0800 Subject: [PATCH 2/2] Formatting --- src/coreclr/jit/compiler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 21851cdef1ddf6..a8b990d2ed0d25 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -5587,7 +5587,8 @@ int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr, if (JitConfig.EnableExtraSuperPmiQueries()) { // Get the assembly name, to aid finding any particular SuperPMI method context function - (void)info.compCompHnd->getAssemblyName(info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd))); + (void)info.compCompHnd->getAssemblyName( + info.compCompHnd->getModuleAssembly(info.compCompHnd->getClassModule(info.compClassHnd))); } #endif // DEBUG