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

Support cold EH funclets in VM #1929

Merged
merged 1 commit into from
Jul 8, 2022
Merged
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
5 changes: 0 additions & 5 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3247,11 +3247,6 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
#endif
}

// #ifdef DEBUG
// // TODO: Implement support for EH splitting in Crossgen2.
// opts.compProcedureSplittingEH = false;
// #endif

#ifdef DEBUG

// Now, set compMaxUncheckedOffsetForNullObject for STRESS_NULL_OBJECT_CHECK
Expand Down
40 changes: 37 additions & 3 deletions src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6116,12 +6116,32 @@ BOOL ReadyToRunJitManager::JitCodeToMethodInfo(RangeSection * pRangeSection,
// Save the raw entry
PTR_RUNTIME_FUNCTION RawFunctionEntry = pRuntimeFunctions + MethodIndex;

const ULONG UMethodIndex = (ULONG)MethodIndex;

// If the MethodIndex happen to be the cold code block, turn it into the associated hot code block
for (DWORD i = 0; i < pInfo->m_nScratch; i++)
{
if ((ULONG)MethodIndex == pInfo->m_pScratch[i])
const bool isColdCode = ((i % 2) == 0);

if (UMethodIndex == pInfo->m_pScratch[i])
{
if (i % 2 == 0)
if (isColdCode)
{
MethodIndex = pInfo->m_pScratch[i + 1];
}

break;
}
else if (isColdCode && (UMethodIndex > pInfo->m_pScratch[i]))
{
// If MethodIndex is a cold funclet from a cold block, the above search will fail.
// To get its corresponding hot block, find the cold block containing the funclet,
// then use the Scratch table.
// The cold funclet's MethodIndex will be greater than its cold block's MethodIndex,
// but less than the next cold block's MethodIndex in the Scratch table.
const bool isFuncletIndex = (i + 2 == pInfo->m_nScratch) || (UMethodIndex < pInfo->m_pScratch[i + 2]);

if (isFuncletIndex)
{
MethodIndex = pInfo->m_pScratch[i + 1];
break;
Expand Down Expand Up @@ -6250,11 +6270,25 @@ BOOL ReadyToRunJitManager::IsFunclet(EECodeInfo* pCodeInfo)

ULONG methodIndex = (ULONG)(pCodeInfo->GetFunctionEntry() - pRuntimeFunctions);

// If it is either the main hot-code or the cold code, then it is not a funclet
// If it is the hot or cold part of the main function, then it is not a funclet
for (DWORD i = 0; i < pInfo->m_nScratch; i++)
{
if (methodIndex == pInfo->m_pScratch[i])
{
// Even indices of Scratch table are cold
if ((i % 2) == 0)
{
SIZE_T unwindSize;
PTR_VOID pUnwindData = GetUnwindDataBlob(pCodeInfo->GetModuleBase(), pCodeInfo->GetFunctionEntry(), &unwindSize);
_ASSERTE(pUnwindData != NULL);

// Chained unwind info is used only for cold part of the main code
const UCHAR chainedUnwindFlag = (((PTR_UNWIND_INFO)pUnwindData)->Flags & UNW_FLAG_CHAININFO);
return (chainedUnwindFlag == 0);
}

// If the function is split, all funclets are cold,
// and all functions in Scratch are split.
return FALSE;
}
}
Expand Down