From 65f66bb4e9caaace732e36da9d26686bf1603382 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Sat, 2 Oct 2021 00:11:29 +0200 Subject: [PATCH] Fix code heap reservation size When I've moved the heap metadata out of the actual code heaps some time ago, I've forgotten to account for the personality routine slot allocated at the beginning of the heaps. This was exposed by an assert when executing under the JIT stress mode 2. This change fixes it by adding accounting for those. Close #59794 --- src/coreclr/vm/codeman.cpp | 5 +++++ src/coreclr/vm/dynamicmethod.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 78721292a3e9f5..153ca37d11b925 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -2412,6 +2412,11 @@ HeapList* EEJitManager::NewCodeHeap(CodeHeapRequestInfo *pInfo, DomainCodeHeapLi #endif size_t reserveSize = initialRequestSize; + +#if defined(TARGET_AMD64) || defined(TARGET_ARM64) + reserveSize += JUMP_ALLOCATE_SIZE; +#endif + if (reserveSize < minReserveSize) reserveSize = minReserveSize; reserveSize = ALIGN_UP(reserveSize, VIRTUAL_ALLOC_RESERVE_GRANULARITY); diff --git a/src/coreclr/vm/dynamicmethod.cpp b/src/coreclr/vm/dynamicmethod.cpp index 6b6c5ffacce4e7..6428256e81df76 100644 --- a/src/coreclr/vm/dynamicmethod.cpp +++ b/src/coreclr/vm/dynamicmethod.cpp @@ -398,6 +398,11 @@ HeapList* HostCodeHeap::InitializeHeapList(CodeHeapRequestInfo *pInfo) // Add TrackAllocation, HeapList and very conservative padding to make sure we have enough for the allocation ReserveBlockSize += sizeof(TrackAllocation) + HOST_CODEHEAP_SIZE_ALIGN + 0x100; + +#if defined(TARGET_AMD64) || defined(TARGET_ARM64) + ReserveBlockSize += JUMP_ALLOCATE_SIZE; +#endif + // reserve ReserveBlockSize rounded-up to VIRTUAL_ALLOC_RESERVE_GRANULARITY of memory ReserveBlockSize = ALIGN_UP(ReserveBlockSize, VIRTUAL_ALLOC_RESERVE_GRANULARITY);