Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RyuJIT: Inlined "is class statically inited" check #47901

Closed
wants to merge 21 commits into from
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
3 changes: 2 additions & 1 deletion src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ LWM(GetTokenTypeAsHandle, GetTokenTypeAsHandleValue, DWORDLONG)
LWM(GetTypeForBox, DWORDLONG, DWORDLONG)
LWM(GetTypeForPrimitiveValueClass, DWORDLONG, DWORD)
LWM(GetTypeForPrimitiveNumericClass, DWORDLONG, DWORD)
LWM(GetUnboxedEntry, DWORDLONG, DLD);
LWM(GetUnboxedEntry, DWORDLONG, DLD)
LWM(GetIsClassInitedFieldAddress, DWORDLONG, DLD)
LWM(GetUnBoxHelper, DWORDLONG, DWORD)
LWM(GetVarArgsHandle, GetVarArgsHandleValue, DLDL)
LWM(GetVars, DWORDLONG, Agnostic_GetVars)
Expand Down
35 changes: 35 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,41 @@ CORINFO_METHOD_HANDLE MethodContext::repGetUnboxedEntry(CORINFO_METHOD_HANDLE ft
return (CORINFO_METHOD_HANDLE)(result.A);
}

void MethodContext::recGetIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask, size_t result)
{
if (GetIsClassInitedFieldAddress == nullptr)
{
GetIsClassInitedFieldAddress = new LightWeightMap<DWORDLONG, DLD>();
}

DWORDLONG key = CastHandle(cls);
DLD value;
value.A = (DWORDLONG)result;
if (pIsInitedMask != nullptr)
{
value.B = (DWORD)*pIsInitedMask;
}
else
{
value.B = 0;
}
GetIsClassInitedFieldAddress->Add(key, value);
}
void MethodContext::dmpGetIsClassInitedFieldAddress(DWORDLONG key, DLD value)
{
printf("GetIsClassInitedFieldAddressedEntry cls-%016llX, result-%016llX, is-init-mask-%u", key, value.A, value.B);
}
size_t MethodContext::repGetIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask)
{
DWORDLONG key = CastHandle(cls);
DLD result = GetIsClassInitedFieldAddress->Get(key);
if (pIsInitedMask != nullptr)
{
*pIsInitedMask = (int)result.B;
}
return (size_t)result.A;
}

void MethodContext::recGetDefaultComparerClass(CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE result)
{
if (GetDefaultComparerClass == nullptr)
Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ class MethodContext
void dmpGetUnboxedEntry(DWORDLONG key, DLD value);
CORINFO_METHOD_HANDLE repGetUnboxedEntry(CORINFO_METHOD_HANDLE ftn, bool* requiresInstMethodTableArg);

void recGetIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask, size_t result);
void dmpGetIsClassInitedFieldAddress(DWORDLONG key, DLD value);
size_t repGetIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask);

void recGetDefaultComparerClass(CORINFO_CLASS_HANDLE cls, CORINFO_CLASS_HANDLE result);
void dmpGetDefaultComparerClass(DWORDLONG key, DWORDLONG value);
CORINFO_CLASS_HANDLE repGetDefaultComparerClass(CORINFO_CLASS_HANDLE cls);
Expand Down Expand Up @@ -881,7 +885,7 @@ class MethodContext
};

// ********************* Please keep this up-to-date to ease adding more ***************
// Highest packet number: 191
// Highest packet number: 192
// *************************************************************************************
enum mcPackets
{
Expand Down Expand Up @@ -1012,6 +1016,7 @@ enum mcPackets
Packet_GetTypeForPrimitiveValueClass = 91,
Packet_GetTypeForPrimitiveNumericClass = 168, // Added 12/7/2017
Packet_GetUnboxedEntry = 165, // Added 10/26/17
Packet_GetIsClassInitedFieldAddress = 192, // Added 3/5/2021
Packet_GetUnBoxHelper = 92,
Packet_GetReadyToRunHelper = 150, // Added 10/10/2014
Packet_GetReadyToRunDelegateCtorHelper = 157, // Added 3/30/2016
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::getUnboxedEntry(CORINFO_METHOD_HANDLE ft
return result;
}

size_t interceptor_ICJI::getIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask)
{
mc->cr->AddCall("getIsClassInitedFieldAddress");
int localPIsInitedMask = false;
size_t result = original_ICorJitInfo->getIsClassInitedFieldAddress(cls, &localPIsInitedMask);
mc->recGetIsClassInitedFieldAddress(cls, &localPIsInitedMask, result);
if (pIsInitedMask != nullptr)
{
*pIsInitedMask = localPIsInitedMask;
}
return result;
}

// Given T, return the type of the default Comparer<T>.
// Returns null if the type can't be determined exactly.
CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultComparerClass(CORINFO_CLASS_HANDLE cls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::getUnboxedEntry(
return original_ICorJitInfo->getUnboxedEntry(ftn, requiresInstMethodTableArg);
}

size_t interceptor_ICJI::getIsClassInitedFieldAddress(
CORINFO_CLASS_HANDLE cls,
int* pIsInitedMask)
{
mcs->AddCall("getIsClassInitedFieldAddress");
return original_ICorJitInfo->getIsClassInitedFieldAddress(cls, pIsInitedMask);
}

CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultComparerClass(
CORINFO_CLASS_HANDLE elemType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::getUnboxedEntry(
return original_ICorJitInfo->getUnboxedEntry(ftn, requiresInstMethodTableArg);
}

size_t interceptor_ICJI::getIsClassInitedFieldAddress(
CORINFO_CLASS_HANDLE cls,
int* pIsInitedMask)
{
return original_ICorJitInfo->getIsClassInitedFieldAddress(cls, pIsInitedMask);
}

CORINFO_CLASS_HANDLE interceptor_ICJI::getDefaultComparerClass(
CORINFO_CLASS_HANDLE elemType)
{
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ CORINFO_METHOD_HANDLE MyICJI::getUnboxedEntry(CORINFO_METHOD_HANDLE ftn, bool* r
return result;
}

size_t MyICJI::getIsClassInitedFieldAddress(CORINFO_CLASS_HANDLE cls, int* pIsInitedMask)
{
jitInstance->mc->cr->AddCall("getIsClassInitedFieldAddress");
size_t result = jitInstance->mc->repGetIsClassInitedFieldAddress(cls, pIsInitedMask);
return result;
}

// Given T, return the type of the default Comparer<T>.
// Returns null if the type can't be determined exactly.
CORINFO_CLASS_HANDLE MyICJI::getDefaultComparerClass(CORINFO_CLASS_HANDLE cls)
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,11 @@ class ICorStaticInfo
bool* requiresInstMethodTableArg
) = 0;

virtual size_t getIsClassInitedFieldAddress(
CORINFO_CLASS_HANDLE cls,
int* pIsInitedMask
) = 0;

// Given T, return the type of the default Comparer<T>.
// Returns null if the type can't be determined exactly.
virtual CORINFO_CLASS_HANDLE getDefaultComparerClass(
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ CORINFO_METHOD_HANDLE getUnboxedEntry(
CORINFO_METHOD_HANDLE ftn,
bool* requiresInstMethodTableArg) override;

size_t getIsClassInitedFieldAddress(
CORINFO_CLASS_HANDLE cls,
int* pIsInitedMask) override;

CORINFO_CLASS_HANDLE getDefaultComparerClass(
CORINFO_CLASS_HANDLE elemType) override;

Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 73d20c3a-75a9-4eea-a952-60419d67b6a6 */
0x73d20c3a,
0x75a9,
0x4eea,
{0xa9, 0x52, 0x60, 0x41, 0x9d, 0x67, 0xb6, 0xa6}
constexpr GUID JITEEVersionIdentifier = { /* a93ec910-3e98-4eb1-8bf1-a1f272303878 */
0xa93ec910,
0x3e98,
0x4eb1,
{0x8b, 0xf1, 0xa1, 0xf2, 0x72, 0x30, 0x38, 0x78}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DEF_CLR_API(getMethodModule)
DEF_CLR_API(getMethodVTableOffset)
DEF_CLR_API(resolveVirtualMethod)
DEF_CLR_API(getUnboxedEntry)
DEF_CLR_API(getIsClassInitedFieldAddress)
DEF_CLR_API(getDefaultComparerClass)
DEF_CLR_API(getDefaultEqualityComparerClass)
DEF_CLR_API(expandRawHandleIntrinsic)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ CORINFO_METHOD_HANDLE WrapICorJitInfo::getUnboxedEntry(
return temp;
}

size_t WrapICorJitInfo::getIsClassInitedFieldAddress(
CORINFO_CLASS_HANDLE cls,
int* pIsInitedMask)
{
API_ENTER(getIsClassInitedFieldAddress);
size_t temp = wrapHnd->getIsClassInitedFieldAddress(cls, pIsInitedMask);
API_LEAVE(getIsClassInitedFieldAddress);
return temp;
}

CORINFO_CLASS_HANDLE WrapICorJitInfo::getDefaultComparerClass(
CORINFO_CLASS_HANDLE elemType)
{
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5026,6 +5026,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
compQuirkForPPPflag = compQuirkForPPP();
#endif

// Insert quick "is class statically initialized" checks in front of
// static init helper calls
DoPhase(this, PHASE_INSERT_STATINIT_CHECKS, &Compiler::fgInsertClsInitChecks);

// Insert GC Polls
DoPhase(this, PHASE_INSERT_GC_POLLS, &Compiler::fgInsertGCPolls);

Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,8 @@ class Compiler
bool fgDomsComputed; // Have we computed the dominator sets?
bool fgOptimizedFinally; // Did we optimize any try-finallys?

bool fgHasSwitch; // any BBJ_SWITCH jumps?
bool fgHasSwitch; // any BBJ_SWITCH jumps?
bool fgHasOptStaticInit; // Do we have a static initialization we can optimize?

BlockSet fgEnterBlks; // Set of blocks which have a special transfer of control; the "entry" blocks plus EH handler
// begin blocks.
Expand Down Expand Up @@ -5184,6 +5185,8 @@ class Compiler
PhaseStatus fgInsertGCPolls();
BasicBlock* fgCreateGCPoll(GCPollType pollType, BasicBlock* block);

PhaseStatus fgInsertClsInitChecks();

// Requires that "block" is a block that returns from
// a finally. Returns the number of successors (jump targets of
// of blocks in the covered "try" that did a "LEAVE".)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ CompPhaseNameMacro(PHASE_ASSERTION_PROP_MAIN, "Assertion prop",
#endif
CompPhaseNameMacro(PHASE_OPT_UPDATE_FLOW_GRAPH, "Update flow graph opt pass", "UPD-FG-O", false, -1, false)
CompPhaseNameMacro(PHASE_COMPUTE_EDGE_WEIGHTS2, "Compute edge weights (2, false)", "EDG-WGT2", false, -1, false)
CompPhaseNameMacro(PHASE_INSERT_STATINIT_CHECKS, "Insert is-cls-stat-init Checks", "CLSSICHK", false, -1, true)
CompPhaseNameMacro(PHASE_INSERT_GC_POLLS, "Insert GC Polls", "GC-POLLS", false, -1, true)
CompPhaseNameMacro(PHASE_DETERMINE_FIRST_COLD_BLOCK, "Determine first cold block", "COLD-BLK", false, -1, true)
CompPhaseNameMacro(PHASE_RATIONALIZE, "Rationalize IR", "RAT", false, -1, false)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void Compiler::fgInit()
#endif

fgHasSwitch = false;
fgHasOptStaticInit = false;
fgPgoSchema = nullptr;
fgPgoData = nullptr;
fgPgoSchemaCount = 0;
Expand Down
Loading