Skip to content

Commit 39c84a3

Browse files
authored
Fix corner-case accounting bug in new codeheap allocation (dotnet#107492)
The size of internal CodeHeap structures was not included in codeheap memory reservation. It caused false OOM exception to be thrown when JITed method code size was near 64kB multiple
1 parent 10f6c4c commit 39c84a3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/coreclr/vm/codeman.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,16 @@ HeapList* LoaderCodeHeap::CreateCodeHeap(CodeHeapRequestInfo *pInfo, LoaderHeap
23762376
}
23772377
else
23782378
{
2379+
// Include internal CodeHeap structures in the reserve
2380+
allocationSize = ALIGN_UP(allocationSize, VIRTUAL_ALLOC_RESERVE_GRANULARITY);
2381+
reserveSize = max(reserveSize, allocationSize);
2382+
2383+
if (reserveSize != (DWORD) reserveSize)
2384+
{
2385+
_ASSERTE(!"reserveSize does not fit in a DWORD");
2386+
EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE);
2387+
}
2388+
23792389
if (loAddr != NULL || hiAddr != NULL)
23802390
{
23812391
#ifdef _DEBUG

0 commit comments

Comments
 (0)