From 379b6eaad133a9e34602b91c487c6a5a07304fc1 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 13 Dec 2019 22:15:37 -0800 Subject: [PATCH] Ignore method name when doing `mcs -removeDup` (#602) Thus, methods with different names but otherwise are identical will match and only one will be retained. This improves both Checked and Release, and fixes the Release build removeDup regression introduced in #548. --- src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp | 2 +- src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.cpp | 8 +++++--- src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.h | 2 +- .../src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp | 8 ++++---- src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp b/src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp index 64d5fa4..10a4e6c 100644 --- a/src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp +++ b/src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp @@ -26,7 +26,7 @@ bool unique(MethodContext* mc) mc->repCompileMethod(&newInfo, &newFlags); char* md5Buff = new char[MD5_HASH_BUFFER_SIZE]; - mc->dumpMethodMD5HashToBuffer(md5Buff, MD5_HASH_BUFFER_SIZE); + mc->dumpMethodMD5HashToBuffer(md5Buff, MD5_HASH_BUFFER_SIZE, /* ignoreMethodName */ true); if (inFile->GetIndex(newInfo.ILCodeSize) == -1) inFile->Add(newInfo.ILCodeSize, new DenseLightWeightMap()); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.cpp index 42b9df5..d071e8a 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.cpp @@ -258,12 +258,14 @@ const char* CallUtils::GetMethodName(MethodContext* mc, CORINFO_METHOD_HANDLE me } // Originally from src/jit/eeinterface.cpp -const char* CallUtils::GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig) +// If `ignoreMethodName` is `true`, we construct the function signature with a dummy method name that will be the +// same for all methods. +const char* CallUtils::GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig, bool ignoreMethodName /* = false */) { const char* returnType = NULL; - const char* className; - const char* methodName = GetMethodName(mc, hnd, &className); + const char* className = ignoreMethodName ? "CLASS" : nullptr; + const char* methodName = ignoreMethodName ? "METHOD" : GetMethodName(mc, hnd, &className); if ((GetHelperNum(hnd) != CORINFO_HELP_UNDEF) || IsNativeMethod(hnd)) { return methodName; diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.h index f0978d0..0233890 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/callutils.h @@ -34,7 +34,7 @@ public: static bool IsNativeMethod(CORINFO_METHOD_HANDLE method); static CORINFO_METHOD_HANDLE GetMethodHandleForNative(CORINFO_METHOD_HANDLE method); static const char* GetMethodName(MethodContext* mc, CORINFO_METHOD_HANDLE method, const char** classNamePtr); - static const char* GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig); + static const char* GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig, bool ignoreMethodName = false); }; #endif \ No newline at end of file diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index a50e310..ea76586 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -6346,7 +6346,7 @@ const WCHAR* MethodContext::repGetStringConfigValue(const WCHAR* name) return value; } -int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len) +int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len, bool ignoreMethodName /* = false */) { char* obuff = buff; @@ -6360,7 +6360,7 @@ int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len) repCompileMethod(&info, &flags); // Add the Method Signature - int t = sprintf_s(buff, len, "%s -- ", CallUtils::GetMethodFullName(this, info.ftn, info.args)); + int t = sprintf_s(buff, len, "%s -- ", CallUtils::GetMethodFullName(this, info.ftn, info.args, ignoreMethodName)); buff += t; len -= t; @@ -6379,11 +6379,11 @@ int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len) return (int)(buff - obuff); } -int MethodContext::dumpMethodMD5HashToBuffer(char* buff, int len) +int MethodContext::dumpMethodMD5HashToBuffer(char* buff, int len, bool ignoreMethodName /* = false */) { char bufferIdentityInfo[METHOD_IDENTITY_INFO_SIZE]; - int cbLen = dumpMethodIdentityInfoToBuffer(bufferIdentityInfo, METHOD_IDENTITY_INFO_SIZE); + int cbLen = dumpMethodIdentityInfoToBuffer(bufferIdentityInfo, METHOD_IDENTITY_INFO_SIZE, ignoreMethodName); if (cbLen < 0) return cbLen; diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h index 164bdd7..fb596c2 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -584,8 +584,8 @@ public: static int dumpStatTitleToBuffer(char* buff, int len); int methodSize; - int dumpMethodIdentityInfoToBuffer(char* buff, int len); - int dumpMethodMD5HashToBuffer(char* buff, int len); + int dumpMethodIdentityInfoToBuffer(char* buff, int len, bool ignoreMethodName = false); + int dumpMethodMD5HashToBuffer(char* buff, int len, bool ignoreMethodName = false); void recGlobalContext(const MethodContext& other); -- 2.7.4