From 9e83ee155a353d2078a0f7dcbf4ede8a0beabc3b Mon Sep 17 00:00:00 2001 From: Aleksandar Micic Date: Mon, 25 Nov 2024 13:50:14 -0500 Subject: [PATCH] Zero offheap on commit on OSX For some reason OSX does not seem to zero memory on commit, unless it's the first commit. For now, till we understand if there is a way to force zero on subsequent re-commits, we will zero it explicitly. Including zPTF as well, since we don't know how it will behave, even if/when it adds support for commit/decommit/virtual-memory. Signed-off-by: Aleksandar Micic --- gc/base/SparseVirtualMemory.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gc/base/SparseVirtualMemory.cpp b/gc/base/SparseVirtualMemory.cpp index c0c76b704ae..65fca3e3ab9 100644 --- a/gc/base/SparseVirtualMemory.cpp +++ b/gc/base/SparseVirtualMemory.cpp @@ -132,6 +132,11 @@ MM_SparseVirtualMemory::allocateSparseFreeEntryAndMapToHeapObject(void *proxyObj void *sparseHeapAddr = _sparseDataPool->findFreeListEntry(adjustedSize); bool success = MM_VirtualMemory::commitMemory(sparseHeapAddr, adjustedSize); +#if defined(OSX) || defined(OMRZTPF) + /* Most platforms will perform an implicit zero through the preceding commit. */ + OMRZeroMemory(sparseHeapAddr, adjustedSize); +#endif /* defined(OSX) || defined(OMRZTPF)) */ + if (NULL != sparseHeapAddr) { _sparseDataPool->mapSparseDataPtrToHeapProxyObjectPtr(sparseHeapAddr, proxyObjPtr, adjustedSize); } else {