From fffc9eaf4ac25002be8f9f14a9496ea122999dfe Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 20 Nov 2020 17:48:41 -0800 Subject: [PATCH] Implement getMethodModule R2R testing was failing by hitting an assert about unimplemented getMethodModule, called as part of R2R-only devirtualization handling in the JIT. I didn't determine why this regressed now. Fixes #45016 --- .../superpmi/superpmi-shared/lwmlist.h | 1 + .../superpmi-shared/methodcontext.cpp | 24 +++++++++++++++++++ .../superpmi/superpmi-shared/methodcontext.h | 7 +++++- .../superpmi-shim-collector/icorjitinfo.cpp | 4 +++- .../ToolBox/superpmi/superpmi/icorjitinfo.cpp | 4 +--- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h index b9731198754a9..3355f0149ec71 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -103,6 +103,7 @@ LWM(GetLazyStringLiteralHelper, DWORDLONG, DWORD) LWM(GetLocationOfThisType, DWORDLONG, Agnostic_CORINFO_LOOKUP_KIND) LWM(GetMethodAttribs, DWORDLONG, DWORD) LWM(GetMethodClass, DWORDLONG, DWORDLONG) +LWM(GetMethodModule, DWORDLONG, DWORDLONG) LWM(GetMethodDefFromMethod, DWORDLONG, DWORD) LWM(GetMethodHash, DWORDLONG, DWORD) LWM(GetMethodInfo, DWORDLONG, Agnostic_GetMethodInfo) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index b2443351f8565..054a60e09860c 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -759,6 +759,30 @@ CORINFO_CLASS_HANDLE MethodContext::repGetMethodClass(CORINFO_METHOD_HANDLE meth return value; } +void MethodContext::recGetMethodModule(CORINFO_METHOD_HANDLE methodHandle, CORINFO_MODULE_HANDLE moduleHandle) +{ + if (GetMethodModule == nullptr) + GetMethodModule = new LightWeightMap(); + + GetMethodModule->Add((DWORDLONG)methodHandle, (DWORDLONG)moduleHandle); + DEBUG_REC(dmpGetMethodModule((DWORDLONG)methodHandle, (DWORDLONG)moduleHandle)); +} +void MethodContext::dmpGetMethodModule(DWORDLONG key, DWORDLONG value) +{ + printf("GetMethodModule key %016llX, value %016llX", key, value); +} +CORINFO_MODULE_HANDLE MethodContext::repGetMethodModule(CORINFO_METHOD_HANDLE methodHandle) +{ + AssertCodeMsg(GetMethodModule != nullptr, EXCEPTIONCODE_MC, + "Found a null GetMethodModule. Probably missing a fatTrigger for %016llX.", (DWORDLONG)methodHandle); + int index = GetMethodModule->GetIndex((DWORDLONG)methodHandle); + AssertCodeMsg(index != -1, EXCEPTIONCODE_MC, "Didn't find %016llX. Probably missing a fatTrigger", + (DWORDLONG)methodHandle); + CORINFO_MODULE_HANDLE value = (CORINFO_MODULE_HANDLE)GetMethodModule->Get((DWORDLONG)methodHandle); + DEBUG_REP(dmpGetMethodModule((DWORDLONG)methodHandle, (DWORDLONG)value)); + return value; +} + void MethodContext::recGetClassAttribs(CORINFO_CLASS_HANDLE classHandle, DWORD attribs) { if (GetClassAttribs == nullptr) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h index 2b0e6a9b55bea..5dafd7c79456a 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -611,6 +611,10 @@ class MethodContext void dmpGetMethodClass(DWORDLONG key, DWORDLONG value); CORINFO_CLASS_HANDLE repGetMethodClass(CORINFO_METHOD_HANDLE methodHandle); + void recGetMethodModule(CORINFO_METHOD_HANDLE methodHandle, CORINFO_MODULE_HANDLE moduleHandle); + void dmpGetMethodModule(DWORDLONG key, DWORDLONG value); + CORINFO_MODULE_HANDLE repGetMethodModule(CORINFO_METHOD_HANDLE methodHandle); + void recGetClassAttribs(CORINFO_CLASS_HANDLE classHandle, DWORD attribs); void dmpGetClassAttribs(DWORDLONG key, DWORD value); DWORD repGetClassAttribs(CORINFO_CLASS_HANDLE classHandle); @@ -1355,7 +1359,7 @@ class MethodContext }; // ********************* Please keep this up-to-date to ease adding more *************** -// Highest packet number: 178 +// Highest packet number: 181 // ************************************************************************************* enum mcPackets { @@ -1457,6 +1461,7 @@ enum mcPackets Packet_GetLocationOfThisType = 69, Packet_GetMethodAttribs = 70, Packet_GetMethodClass = 71, + Packet_GetMethodModule = 181, // Added 11/20/2020 Packet_GetMethodDefFromMethod = 72, Packet_GetMethodHash = 73, Packet_GetMethodInfo = 74, diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp index bb1bba81f01d7..f56e01989b7f7 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -212,7 +212,9 @@ CORINFO_CLASS_HANDLE interceptor_ICJI::getMethodClass(CORINFO_METHOD_HANDLE meth CORINFO_MODULE_HANDLE interceptor_ICJI::getMethodModule(CORINFO_METHOD_HANDLE method) { mc->cr->AddCall("getMethodModule"); - return original_ICorJitInfo->getMethodModule(method); + CORINFO_MODULE_HANDLE temp = original_ICorJitInfo->getMethodModule(method); + mc->recGetMethodModule(method, temp); + return temp; } // This function returns the offset of the specified method in the diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp index 789dfae1fd940..c8b42b49aab7c 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -156,9 +156,7 @@ CORINFO_CLASS_HANDLE MyICJI::getMethodClass(CORINFO_METHOD_HANDLE method) CORINFO_MODULE_HANDLE MyICJI::getMethodModule(CORINFO_METHOD_HANDLE method) { jitInstance->mc->cr->AddCall("getMethodModule"); - LogError("Hit unimplemented getMethodModule"); - DebugBreakorAV(7); - return 0; + return jitInstance->mc->repGetMethodModule(method); } // This function returns the offset of the specified method in the