Skip to content

Commit 55d0b29

Browse files
committed
Address PR feedback
1 parent 9740856 commit 55d0b29

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ int32_t* InterpCompiler::GetCode(int32_t *pCodeSize)
10461046
InterpCompiler::InterpCompiler(COMP_HANDLE compHnd,
10471047
CORINFO_METHOD_INFO* methodInfo)
10481048
: m_pInitLocalsIns(nullptr)
1049-
, m_globalVarsStackTop(0)
1049+
, m_globalVarsWithRefsStackTop(0)
10501050
{
10511051
// Fill in the thread-local used for assertions
10521052
t_InterpJitInfoTls = compHnd;
@@ -1108,12 +1108,11 @@ InterpMethod* InterpCompiler::CompileMethod()
11081108
void InterpCompiler::PatchInitLocals(CORINFO_METHOD_INFO* methodInfo)
11091109
{
11101110
// We may have global vars containing managed pointers or interior pointers, so we need
1111-
// to zero the region of the stack containing global vars, not just IL locals.
1112-
// data[0] is either the start of IL locals or the end of IL locals depending on whether local
1113-
// zeroing was enabled for this method. We want to preserve that so we don't unnecessarily
1114-
// zero the IL locals if the method's author didn't want them zeroed
1111+
// to zero the region of the stack containing global vars, not just IL locals. Now that
1112+
// offset allocation has occurred we know where the global vars end, so we can expand
1113+
// the initlocals opcode that was originally generated to also zero them.
11151114
int32_t startOffset = m_pInitLocalsIns->data[0];
1116-
int32_t totalSize = m_globalVarsStackTop - startOffset;
1115+
int32_t totalSize = m_globalVarsWithRefsStackTop - startOffset;
11171116
if (totalSize > m_pInitLocalsIns->data[1])
11181117
{
11191118
INTERP_DUMP(
@@ -1128,7 +1127,7 @@ void InterpCompiler::PatchInitLocals(CORINFO_METHOD_INFO* methodInfo)
11281127
INTERP_DUMP(
11291128
"Not expanding initlocals from [%d-%d] for global vars stack top of %d\n",
11301129
startOffset, startOffset + m_pInitLocalsIns->data[1],
1131-
m_globalVarsStackTop
1130+
m_globalVarsWithRefsStackTop
11321131
);
11331132
}
11341133
}

src/coreclr/interpreter/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class InterpCompiler
359359

360360
int32_t CreateVarExplicit(InterpType interpType, CORINFO_CLASS_HANDLE clsHnd, int size);
361361

362-
int32_t m_totalVarsStackSize, m_globalVarsStackTop;
362+
int32_t m_totalVarsStackSize, m_globalVarsWithRefsStackTop;
363363
int32_t m_paramAreaOffset = 0;
364364
int32_t m_ILLocalsOffset, m_ILLocalsSize;
365365
void AllocVarOffsetCB(int *pVar, void *pData);

src/coreclr/interpreter/compileropt.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void InterpCompiler::AllocOffsets()
227227
INTERP_DUMP("\nAllocating var offsets\n");
228228

229229
int finalVarsStackSize = m_totalVarsStackSize,
230-
globalVarsStackTop = m_totalVarsStackSize;
230+
globalVarsWithRefsStackTop = m_totalVarsStackSize;
231231

232232
// We now have the top of stack offset. All local regs are allocated after this offset, with each basic block
233233
for (pBB = m_pEntryBB; pBB != NULL; pBB = pBB->pNextBB)
@@ -415,16 +415,19 @@ void InterpCompiler::AllocOffsets()
415415
pVar->global && (
416416
(pVar->interpType == InterpTypeO) ||
417417
(pVar->interpType == InterpTypeByRef) ||
418-
(pVar->interpType == InterpTypeVT)
418+
(
419+
(pVar->interpType == InterpTypeVT) &&
420+
(m_compHnd->getClassAttribs(pVar->clsHnd) & CORINFO_FLG_CONTAINS_GC_PTR)
421+
)
419422
)
420423
)
421424
{
422425
int32_t endOfVar = pVar->offset + pVar->size;
423-
if (endOfVar > globalVarsStackTop)
424-
globalVarsStackTop = endOfVar;
426+
if (endOfVar > globalVarsWithRefsStackTop)
427+
globalVarsWithRefsStackTop = endOfVar;
425428
}
426429
}
427430

428-
m_globalVarsStackTop = globalVarsStackTop;
431+
m_globalVarsWithRefsStackTop = globalVarsWithRefsStackTop;
429432
m_totalVarsStackSize = ALIGN_UP_TO(finalVarsStackSize, INTERP_STACK_ALIGNMENT);
430433
}

0 commit comments

Comments
 (0)