Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ CORINFO_METHOD_HANDLE getUnboxedEntry(
// Returns null if the type can't be determined exactly.
CORINFO_CLASS_HANDLE getDefaultEqualityComparerClass(CORINFO_CLASS_HANDLE elemType);

CORINFO_CLASS_HANDLE getUniqueImplementingClass(CORINFO_CLASS_HANDLE baseType);

// Given resolved token that corresponds to an intrinsic classified as
// a CORINFO_INTRINSIC_GetRawHandle intrinsic, fetch the handle associated
// with the token. If this is not possible at compile-time (because the current method's
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LWM(GetHeapClassSize, DWORDLONG, DWORD)
LWM(CanAllocateOnStack, DWORDLONG, DWORD)
LWM(GetCookieForPInvokeCalliSig, GetCookieForPInvokeCalliSigValue, DLDL)
LWM(GetDefaultEqualityComparerClass, DWORDLONG, DWORDLONG)
LWM(GetUniqueImplementingClass, DWORDLONG, DWORDLONG)
LWM(GetDelegateCtor, Agnostic_GetDelegateCtorIn, Agnostic_GetDelegateCtorOut)
LWM(GetEEInfo, DWORD, Agnostic_CORINFO_EE_INFO)
LWM(GetEHinfo, DLD, Agnostic_CORINFO_EH_CLAUSE)
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,23 @@ CORINFO_CLASS_HANDLE MethodContext::repGetDefaultEqualityComparerClass(CORINFO_C
return result;
}

void MethodContext::recGetUniqueImplementingClass(CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE result)
{
if (GetUniqueImplementingClass == nullptr)
GetUniqueImplementingClass = new LightWeightMap<DWORDLONG, DWORDLONG>();

GetUniqueImplementingClass->Add((DWORDLONG)cls, (DWORDLONG)result);
}
void MethodContext::dmpGetUniqueImplementingClass(DWORDLONG key, DWORDLONG value)
{
printf("GetUniqueImplementingClass key cls-%016llX, value cls-%016llX", key, value);
}
CORINFO_CLASS_HANDLE MethodContext::repGetUniqueImplementingClass(CORINFO_CLASS_HANDLE cls)
{
CORINFO_CLASS_HANDLE result = (CORINFO_CLASS_HANDLE)GetUniqueImplementingClass->Get((DWORDLONG)cls);
return result;
}

void MethodContext::recGetTokenTypeAsHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_CLASS_HANDLE result)
{
if (GetTokenTypeAsHandle == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ class MethodContext
void dmpGetDefaultEqualityComparerClass(DWORDLONG key, DWORDLONG value);
CORINFO_CLASS_HANDLE repGetDefaultEqualityComparerClass(CORINFO_CLASS_HANDLE cls);

void recGetUniqueImplementingClass(CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE result);
void dmpGetUniqueImplementingClass(DWORDLONG key, DWORDLONG value);
CORINFO_CLASS_HANDLE repGetUniqueImplementingClass(CORINFO_CLASS_HANDLE cls);

void recGetTokenTypeAsHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_CLASS_HANDLE result);
void dmpGetTokenTypeAsHandle(const GetTokenTypeAsHandleValue& key, DWORDLONG value);
CORINFO_CLASS_HANDLE repGetTokenTypeAsHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken);
Expand Down Expand Up @@ -1337,7 +1341,7 @@ class MethodContext
};

// ********************* Please keep this up-to-date to ease adding more ***************
// Highest packet number: 178
// Highest packet number: 179
// *************************************************************************************
enum mcPackets
{
Expand Down Expand Up @@ -1413,6 +1417,7 @@ enum mcPackets
Packet_GetStringConfigValue = 152, // Added 2/12/2015
Packet_GetCookieForPInvokeCalliSig = 48,
Packet_GetDefaultEqualityComparerClass = 162, // Added 9/24/2017
Packet_GetUniqueImplementingClass = 179, // Added 6/7/2020
Packet_GetDelegateCtor = 49,
Packet_GetEEInfo = 50,
Packet_GetEHinfo = 51,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultEqualityComparerClass(CORINFO_C
return result;
}

CORINFO_CLASS_HANDLE interceptor_ICJI::getUniqueImplementingClass(CORINFO_CLASS_HANDLE cls)
{
mc->cr->AddCall("getUniqueImplementingClass");
CORINFO_CLASS_HANDLE result = original_ICorJitInfo->getUniqueImplementingClass(cls);
mc->recGetUniqueImplementingClass(cls, result);
return result;
}

void interceptor_ICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_GENERICHANDLE_RESULT* pResult)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultEqualityComparerClass(CORINFO_C
return original_ICorJitInfo->getDefaultEqualityComparerClass(cls);
}

CORINFO_CLASS_HANDLE interceptor_ICJI::getUniqueImplementingClass(CORINFO_CLASS_HANDLE cls)
{
mcs->AddCall("getUniqueImplementingClass");
return original_ICorJitInfo->getUniqueImplementingClass(cls);
}

void interceptor_ICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_GENERICHANDLE_RESULT* pResult)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultEqualityComparerClass(CORINFO_C
return original_ICorJitInfo->getDefaultEqualityComparerClass(cls);
}

CORINFO_CLASS_HANDLE interceptor_ICJI::getUniqueImplementingClass(CORINFO_CLASS_HANDLE cls)
{
return original_ICorJitInfo->getUniqueImplementingClass(cls);
}

void interceptor_ICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_GENERICHANDLE_RESULT* pResult)
{
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ CORINFO_CLASS_HANDLE MyICJI::getDefaultEqualityComparerClass(CORINFO_CLASS_HANDL
return result;
}

CORINFO_CLASS_HANDLE MyICJI::getUniqueImplementingClass(CORINFO_CLASS_HANDLE cls)
{
jitInstance->mc->cr->AddCall("getUniqueImplementingClass");
CORINFO_CLASS_HANDLE result = jitInstance->mc->repGetUniqueImplementingClass(cls);
return result;
}

void MyICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult)
{
jitInstance->mc->cr->AddCall("expandRawHandleIntrinsic");
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/src/inc/corhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,9 @@ typedef enum LoadHintEnum
#define DEFAULTDEPENDENCY_TYPE_W W("System.Runtime.CompilerServices.DefaultDependencyAttribute")
#define DEFAULTDEPENDENCY_TYPE "System.Runtime.CompilerServices.DefaultDependencyAttribute"

#define UNIQUEIMPL_TYPE_W W("System.Runtime.CompilerServices.UniqueImplAttribute")
#define UNIQUEIMPL_TYPE "System.Runtime.CompilerServices.UniqueImplAttribute"

#define DEPENDENCY_TYPE_W W("System.Runtime.CompilerServices.DependencyAttribute")
#define DEPENDENCY_TYPE "System.Runtime.CompilerServices.DependencyAttribute"

Expand Down
14 changes: 9 additions & 5 deletions src/coreclr/src/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ TODO: Talk about initializing strutures before use
#endif
#endif

SELECTANY const GUID JITEEVersionIdentifier = { /* 8b2226a2-ac30-4f5c-ae5c-926c792ecdb9 */
0x8b2226a2,
0xac30,
0x4f5c,
{ 0xae, 0x5c, 0x92, 0x6c, 0x79, 0x2e, 0xcd, 0xb9 }
SELECTANY const GUID JITEEVersionIdentifier = { /* 34d57104-4280-472f-a13e-842ab177777d */
0x34d57104,
0x4280,
0x472f,
{ 0xa1, 0x3e, 0x84, 0x2a, 0xb1, 0x77, 0x77, 0x7d }
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2102,6 +2102,10 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE elemType
) = 0;

virtual CORINFO_CLASS_HANDLE getUniqueImplementingClass(
CORINFO_CLASS_HANDLE baseType
) = 0;

// Given resolved token that corresponds to an intrinsic classified as
// a CORINFO_INTRINSIC_GetRawHandle intrinsic, fetch the handle associated
// with the token. If this is not possible at compile-time (because the current method's
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DEF_CLR_API(getMethodVTableOffset)
DEF_CLR_API(resolveVirtualMethod)
DEF_CLR_API(getUnboxedEntry)
DEF_CLR_API(getDefaultEqualityComparerClass)
DEF_CLR_API(getUniqueImplementingClass)
DEF_CLR_API(expandRawHandleIntrinsic)
DEF_CLR_API(getIntrinsicID)
DEF_CLR_API(isIntrinsicType)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ CORINFO_CLASS_HANDLE WrapICorJitInfo::getDefaultEqualityComparerClass(
return temp;
}

CORINFO_CLASS_HANDLE WrapICorJitInfo::getUniqueImplementingClass(
CORINFO_CLASS_HANDLE baseType
)
{
API_ENTER(getUniqueImplementingClass);
CORINFO_CLASS_HANDLE temp = wrapHnd->getUniqueImplementingClass(baseType);
API_LEAVE(getUniqueImplementingClass);
return temp;
}

void WrapICorJitInfo::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
Expand Down
13 changes: 8 additions & 5 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20350,9 +20350,16 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call,
return;
}

bool guessUniqueInterface = false;

INDEBUG(guessUniqueInterface = (JitConfig.JitGuardedDevirtualizationGuessUniqueInterface() > 0););

CORINFO_CLASS_HANDLE uniqueImplementingClass = NO_CLASS_HANDLE;

// info.compCompHnd->getUniqueImplementingClass(objClass);
if (guessUniqueInterface && !opts.IsReadyToRun() && opts.OptimizationEnabled())
{
uniqueImplementingClass = info.compCompHnd->getUniqueImplementingClass(objClass);
}

if (uniqueImplementingClass == NO_CLASS_HANDLE)
{
Expand All @@ -20363,10 +20370,6 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call,
JITDUMP("Only known implementor of interface %p (%s) is %p (%s)!\n", dspPtr(objClass), objClassName,
uniqueImplementingClass, eeGetClassName(uniqueImplementingClass));

bool guessUniqueInterface = true;

INDEBUG(guessUniqueInterface = (JitConfig.JitGuardedDevirtualizationGuessUniqueInterface() > 0););

if (!guessUniqueInterface)
{
JITDUMP("Guarded devirt for unique interface implementor is not enabled, sorry\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ CONFIG_INTEGER(JitEnableGuardedDevirtualization, W("JitEnableGuardedDevirtualiza

#if defined(DEBUG)
// Various policies for GuardedDevirtualization
CONFIG_INTEGER(JitGuardedDevirtualizationGuessUniqueInterface, W("JitGuardedDevirtualizationGuessUniqueInterface"), 1)
CONFIG_INTEGER(JitGuardedDevirtualizationGuessUniqueInterface, W("JitGuardedDevirtualizationGuessUniqueInterface"), 0)
CONFIG_INTEGER(JitGuardedDevirtualizationGuessBestClass, W("JitGuardedDevirtualizationGuessBestClass"), 1)
#endif // DEBUG

Expand Down
Loading