From 201fc24d9b4b8933d84bc7749ebfaa9eb8718dae Mon Sep 17 00:00:00 2001 From: Fei Peng Date: Thu, 29 Nov 2018 15:02:24 -0800 Subject: [PATCH] Add SuperPMI code for the new getMethodNameFromMetadata Commit migrated from https://github.com/dotnet/coreclr/commit/1ebec7911d417205e6cfcae663e37fe843ce858b --- .../superpmi/superpmi-shared/icorjitinfoimpl.h | 3 +- .../src/ToolBox/superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi/superpmi-shared/methodcontext.cpp | 74 +++++++++++++--------- .../superpmi/superpmi-shared/methodcontext.h | 22 ++++++- .../superpmi-shim-collector/icorjitinfo.cpp | 11 ++-- .../superpmi/superpmi-shim-counter/icorjitinfo.cpp | 9 +-- .../superpmi/superpmi-shim-simple/icorjitinfo.cpp | 9 +-- .../src/ToolBox/superpmi/superpmi/icorjitinfo.cpp | 9 +-- 8 files changed, 88 insertions(+), 51 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h index 73a8d28..b6a66a3 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h @@ -716,7 +716,8 @@ const char* getMethodName(CORINFO_METHOD_HANDLE ftn, /* IN */ // Suitable for non-debugging use. const char* getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ const char** className, /* OUT */ - const char** namespaceName /* OUT */ + const char** namespaceName, /* OUT */ + const char** enclosingClassName /* OUT */ ); // this function is for debugging only. It returns a value that diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h index a50e9b6..137fbe1 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -109,7 +109,7 @@ LWM(GetMethodDefFromMethod, DWORDLONG, DWORD) LWM(GetMethodHash, DWORDLONG, DWORD) LWM(GetMethodInfo, DWORDLONG, Agnostic_GetMethodInfo) LWM(GetMethodName, DLD, DD) -LWM(GetMethodNameFromMetadata, DLDD, DDD) +LWM(GetMethodNameFromMetadata, Agnostic_CORINFO_METHODNAME_TOKENin, Agnostic_CORINFO_METHODNAME_TOKENout) LWM(GetMethodSig, DLDL, Agnostic_CORINFO_SIG_INFO) LWM(GetMethodSync, DWORDLONG, DLDL) LWM(GetMethodVTableOffset, DWORDLONG, DDD) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 11c7336..4883dd4 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -1001,57 +1001,68 @@ const char* MethodContext::repGetMethodName(CORINFO_METHOD_HANDLE ftn, const cha void MethodContext::recGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, char* methodName, const char** className, - const char** namespaceName) + const char** namespaceName, + const char** enclosingClassName) { if (GetMethodNameFromMetadata == nullptr) - GetMethodNameFromMetadata = new LightWeightMap(); - DDD value; - DLDD key; - key.A = (DWORDLONG)ftn; - key.B = (className != nullptr); - key.C = (namespaceName != nullptr); + GetMethodNameFromMetadata = new LightWeightMap(); + Agnostic_CORINFO_METHODNAME_TOKENout value; + Agnostic_CORINFO_METHODNAME_TOKENin key; + key.ftn = (DWORDLONG)ftn; + key.className = (className != nullptr); + key.namespaceName = (namespaceName != nullptr); + key.enclosingClassName = (enclosingClassName != nullptr); if (methodName != nullptr) - value.A = GetMethodNameFromMetadata->AddBuffer((unsigned char*)methodName, (DWORD)strlen(methodName) + 1); + value.methodName = GetMethodNameFromMetadata->AddBuffer((unsigned char*)methodName, (DWORD)strlen(methodName) + 1); else - value.A = (DWORD)-1; + value.methodName = (DWORD)-1; if ((className != nullptr) && (*className != nullptr)) - value.B = GetMethodNameFromMetadata->AddBuffer((unsigned char*)*className, (DWORD)strlen(*className) + 1); + value.className = GetMethodNameFromMetadata->AddBuffer((unsigned char*)*className, (DWORD)strlen(*className) + 1); else - value.B = (DWORD)-1; + value.className = (DWORD)-1; if ((namespaceName != nullptr) && (*namespaceName != nullptr)) - value.C = + value.namespaceName = GetMethodNameFromMetadata->AddBuffer((unsigned char*)*namespaceName, (DWORD)strlen(*namespaceName) + 1); else - value.C = (DWORD)-1; + value.namespaceName = (DWORD)-1; + + if ((enclosingClassName != nullptr) && (*enclosingClassName != nullptr)) + value.enclosingClassName = + GetMethodNameFromMetadata->AddBuffer((unsigned char*)*enclosingClassName, (DWORD)strlen(*enclosingClassName) + 1); + else + value.enclosingClassName = (DWORD)-1; GetMethodNameFromMetadata->Add(key, value); DEBUG_REC(dmpGetMethodNameFromMetadata(key, value)); } -void MethodContext::dmpGetMethodNameFromMetadata(DLDD key, DDD value) +void MethodContext::dmpGetMethodNameFromMetadata(Agnostic_CORINFO_METHODNAME_TOKENin key, Agnostic_CORINFO_METHODNAME_TOKENout value) { - unsigned char* methodName = (unsigned char*)GetMethodName->GetBuffer(value.A); - unsigned char* className = (unsigned char*)GetMethodName->GetBuffer(value.B); - unsigned char* namespaceName = (unsigned char*)GetMethodName->GetBuffer(value.C); - printf("GetMethodNameFromMetadata key - ftn-%016llX classNonNull-%u namespaceNonNull-%u, value meth-'%s', " - "class-'%s', namespace-'%s'", - key.A, key.B, key.C, methodName, className, namespaceName); + unsigned char* methodName = (unsigned char*)GetMethodName->GetBuffer(value.methodName); + unsigned char* className = (unsigned char*)GetMethodName->GetBuffer(value.className); + unsigned char* namespaceName = (unsigned char*)GetMethodName->GetBuffer(value.namespaceName); + unsigned char* enclosingClassName = (unsigned char*)GetMethodName->GetBuffer(value.enclosingClassName); + printf("GetMethodNameFromMetadata key - ftn-%016llX classNonNull-%u namespaceNonNull-%u nclosingClassNonNull-%u, value meth-'%s', " + "class-'%s', namespace-'%s' enclosingClass-'%s'", + key.ftn, key.className, key.namespaceName, key.enclosingClassName, methodName, className, namespaceName, enclosingClassName); GetMethodNameFromMetadata->Unlock(); } const char* MethodContext::repGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, const char** moduleName, - const char** namespaceName) + const char** namespaceName, + const char** enclosingClassName) { const char* result = nullptr; - DDD value; - DLDD key; - key.A = (DWORDLONG)ftn; - key.B = (moduleName != nullptr); - key.C = (namespaceName != nullptr); + Agnostic_CORINFO_METHODNAME_TOKENout value; + Agnostic_CORINFO_METHODNAME_TOKENin key; + key.ftn = (DWORDLONG)ftn; + key.className = (moduleName != nullptr); + key.namespaceName = (namespaceName != nullptr); + key.enclosingClassName = (enclosingClassName != nullptr); int itemIndex = -1; if (GetMethodNameFromMetadata != nullptr) @@ -1066,16 +1077,21 @@ const char* MethodContext::repGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ft else { value = GetMethodNameFromMetadata->Get(key); - result = (const char*)GetMethodNameFromMetadata->GetBuffer(value.A); + result = (const char*)GetMethodNameFromMetadata->GetBuffer(value.methodName); if (moduleName != nullptr) { - *moduleName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.B); + *moduleName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.className); } if (namespaceName != nullptr) { - *namespaceName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.C); + *namespaceName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.namespaceName); + } + + if (enclosingClassName != nullptr) + { + *enclosingClassName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.enclosingClassName); } } DEBUG_REP(dmpGetMethodNameFromMetadata(key, value)); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h index cde16ad..115cd41 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -95,6 +95,20 @@ public: DWORD B; DWORD C; }; + struct Agnostic_CORINFO_METHODNAME_TOKENin + { + DWORDLONG ftn; + DWORD className; + DWORD namespaceName; + DWORD enclosingClassName; + }; + struct Agnostic_CORINFO_METHODNAME_TOKENout + { + DWORD methodName; + DWORD className; + DWORD namespaceName; + DWORD enclosingClassName; + }; struct Agnostic_CORINFO_RESOLVED_TOKENin { DWORDLONG tokenContext; @@ -625,11 +639,13 @@ public: void recGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, char* methodname, const char** moduleName, - const char** namespaceName); - void dmpGetMethodNameFromMetadata(DLDD key, DDD value); + const char** namespaceName, + const char** enclosingClassName); + void dmpGetMethodNameFromMetadata(Agnostic_CORINFO_METHODNAME_TOKENin key, Agnostic_CORINFO_METHODNAME_TOKENout value); const char* repGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, const char** className, - const char** namespaceName); + const char** namespaceName, + const char** enclosingClassName); void recGetJitFlags(CORJIT_FLAGS* jitFlags, DWORD sizeInBytes, DWORD result); void dmpGetJitFlags(DWORD key, DD value); 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 1b1ba5d..898f824 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1481,14 +1481,15 @@ const char* interceptor_ICJI::getMethodName(CORINFO_METHOD_HANDLE ftn, /* return temp; } -const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ - const char** className, /* OUT */ - const char** namespaceName /* OUT */ +const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ + const char** className, /* OUT */ + const char** namespaceName, /* OUT */ + const char** enclosingClassName /* OUT */ ) { mc->cr->AddCall("getMethodNameFromMetadata"); - const char* temp = original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName); - mc->recGetMethodNameFromMetadata(ftn, (char*)temp, className, namespaceName); + const char* temp = original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName, enclosingClassName); + mc->recGetMethodNameFromMetadata(ftn, (char*)temp, className, namespaceName, enclosingClassName); return temp; } diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp index c8002f5..3348479 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp @@ -1153,13 +1153,14 @@ const char* interceptor_ICJI::getMethodName(CORINFO_METHOD_HANDLE ftn, /* return original_ICorJitInfo->getMethodName(ftn, moduleName); } -const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ - const char** className, /* OUT */ - const char** namespaceName /* OUT */ +const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ + const char** className, /* OUT */ + const char** namespaceName, /* OUT */ + const char** enclosingClassName /* OUT */ ) { mcs->AddCall("getMethodNameFromMetadata"); - return original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName); + return original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName, enclosingClassName); } // this function is for debugging only. It returns a value that diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp index 1bdd3b7..b5a18f8 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp @@ -1037,12 +1037,13 @@ const char* interceptor_ICJI::getMethodName(CORINFO_METHOD_HANDLE ftn, /* return original_ICorJitInfo->getMethodName(ftn, moduleName); } -const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ - const char** className, /* OUT */ - const char** namespaceName /* OUT */ +const char* interceptor_ICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ + const char** className, /* OUT */ + const char** namespaceName, /* OUT */ + const char** enclosingClassName /* OUT */ ) { - return original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName); + return original_ICorJitInfo->getMethodNameFromMetadata(ftn, className, namespaceName, enclosingClassName); } // this function is for debugging only. It returns a value that diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp index d6d4d6e..bf60a9a 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -1259,13 +1259,14 @@ const char* MyICJI::getMethodName(CORINFO_METHOD_HANDLE ftn, /* IN */ return jitInstance->mc->repGetMethodName(ftn, moduleName); } -const char* MyICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ - const char** className, /* OUT */ - const char** namespaceName /* OUT */ +const char* MyICJI::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftn, /* IN */ + const char** className, /* OUT */ + const char** namespaceName, /* OUT */ + const char** enclosingClassName /* OUT */ ) { jitInstance->mc->cr->AddCall("getMethodNameFromMetadata"); - return jitInstance->mc->repGetMethodNameFromMetadata(ftn, className, namespaceName); + return jitInstance->mc->repGetMethodNameFromMetadata(ftn, className, namespaceName, enclosingClassName); } // this function is for debugging only. It returns a value that -- 2.7.4