Skip to content

Commit

Permalink
Don't zero Offheap after commit
Browse files Browse the repository at this point in the history
Commit on all existing platforms will implicitly (and likely lazily)
zero the address range, since we are currently creating Offheap with
anonymous small pages.

Hence we are removing our explicit zero call (which was already the case
of xLinux).

Signed-off-by: Aleksandar Micic <[email protected]>
  • Loading branch information
Aleksandar Micic authored and Aleksandar Micic committed Nov 22, 2024
1 parent ef89b64 commit 22a5046
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions gc/base/SparseVirtualMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
*/

MM_SparseVirtualMemory *
MM_SparseVirtualMemory::newInstance(MM_EnvironmentBase* env, uint32_t memoryCategory, MM_Heap *in_heap)
MM_SparseVirtualMemory::newInstance(MM_EnvironmentBase *env, uint32_t memoryCategory, MM_Heap *in_heap)
{
MM_GCExtensionsBase *extensions = env->getExtensions();
MM_SparseVirtualMemory* vmem = NULL;
vmem = (MM_SparseVirtualMemory*)env->getForge()->allocate(sizeof(MM_SparseVirtualMemory), OMR::GC::AllocationCategory::FIXED, OMR_GET_CALLSITE());
MM_SparseVirtualMemory *vmem = NULL;
vmem = (MM_SparseVirtualMemory *)env->getForge()->allocate(sizeof(MM_SparseVirtualMemory), OMR::GC::AllocationCategory::FIXED, OMR_GET_CALLSITE());

if (vmem) {
new (vmem) MM_SparseVirtualMemory(env, extensions->sparseHeapPageSize, extensions->sparseHeapPageFlags, in_heap);
Expand All @@ -60,7 +60,7 @@ MM_SparseVirtualMemory::newInstance(MM_EnvironmentBase* env, uint32_t memoryCate
}

bool
MM_SparseVirtualMemory::initialize(MM_EnvironmentBase* env, uint32_t memoryCategory)
MM_SparseVirtualMemory::initialize(MM_EnvironmentBase *env, uint32_t memoryCategory)
{
uintptr_t in_heap_size = (uintptr_t)_heap->getHeapTop() - (uintptr_t)_heap->getHeapBase();
uintptr_t maxHeapSize = _heap->getMaximumMemorySize();
Expand All @@ -82,9 +82,9 @@ MM_SparseVirtualMemory::initialize(MM_EnvironmentBase* env, uint32_t memoryCateg
}

if (success) {
Trc_MM_SparseVirtualMemory_createSparseVirtualMemory_success((void*)_heap->getHeapTop(), (void*)_heap->getHeapBase(), (void *)in_heap_size, (void *)maxHeapSize, (void *)regionSize, regionCount, (void *)off_heap_size, _sparseDataPool);
Trc_MM_SparseVirtualMemory_createSparseVirtualMemory_success((void *)_heap->getHeapTop(), (void *)_heap->getHeapBase(), (void *)in_heap_size, (void *)maxHeapSize, (void *)regionSize, regionCount, (void *)off_heap_size, _sparseDataPool);
} else {
Trc_MM_SparseVirtualMemory_createSparseVirtualMemory_failure((void*)_heap->getHeapTop(), (void*)_heap->getHeapBase(), (void *)in_heap_size, (void *)maxHeapSize, (void *)regionSize, regionCount, (void *)off_heap_size, _sparseDataPool);
Trc_MM_SparseVirtualMemory_createSparseVirtualMemory_failure((void *)_heap->getHeapTop(), (void *)_heap->getHeapBase(), (void *)in_heap_size, (void *)maxHeapSize, (void *)regionSize, regionCount, (void *)off_heap_size, _sparseDataPool);
}

return success;
Expand Down Expand Up @@ -125,18 +125,13 @@ MM_SparseVirtualMemory::updateSparseDataEntryAfterObjectHasMoved(void *dataPtr,
void *
MM_SparseVirtualMemory::allocateSparseFreeEntryAndMapToHeapObject(void *proxyObjPtr, uintptr_t size)
{
/* Commiting and decommiting memory sizes must be multiple of pagesize */
/* Committing and de-committing memory sizes must be multiple of pagesize */
uintptr_t adjustedSize = MM_Math::roundToCeiling(_pageSize, size);

omrthread_monitor_enter(_largeObjectVirtualMemoryMutex);
void *sparseHeapAddr = _sparseDataPool->findFreeListEntry(adjustedSize);
bool success = MM_VirtualMemory::commitMemory(sparseHeapAddr, adjustedSize);

/* We can likely significantly reduce the list of platforms requiring zeroing after commit - however initially we will take an ultra safe approach */
#if !(defined(LINUX) && defined(J9VM_ARCH_X86))
OMRZeroMemory(sparseHeapAddr, adjustedSize);
#endif /* !(defined(LINUX) && defined(J9VM_ARCH_X86)) */

if (NULL != sparseHeapAddr) {
_sparseDataPool->mapSparseDataPtrToHeapProxyObjectPtr(sparseHeapAddr, proxyObjPtr, adjustedSize);
} else {
Expand All @@ -147,17 +142,17 @@ MM_SparseVirtualMemory::allocateSparseFreeEntryAndMapToHeapObject(void *proxyObj
omrthread_monitor_exit(_largeObjectVirtualMemoryMutex);

if (success) {
Trc_MM_SparseVirtualMemory_commitMemory_success(sparseHeapAddr, (void*)adjustedSize, proxyObjPtr);
Trc_MM_SparseVirtualMemory_commitMemory_success(sparseHeapAddr, (void *)adjustedSize, proxyObjPtr);
} else {
Trc_MM_SparseVirtualMemory_commitMemory_failure(sparseHeapAddr, (void*)adjustedSize, proxyObjPtr);
Trc_MM_SparseVirtualMemory_commitMemory_failure(sparseHeapAddr, (void *)adjustedSize, proxyObjPtr);
sparseHeapAddr = NULL;
}

return sparseHeapAddr;
}

bool
MM_SparseVirtualMemory::freeSparseRegionAndUnmapFromHeapObject(MM_EnvironmentBase* env, void *dataPtr)
MM_SparseVirtualMemory::freeSparseRegionAndUnmapFromHeapObject(MM_EnvironmentBase *env, void *dataPtr)
{
uintptr_t dataSize = _sparseDataPool->findObjectDataSizeForSparseDataPtr(dataPtr);
bool ret = true;
Expand All @@ -169,9 +164,9 @@ MM_SparseVirtualMemory::freeSparseRegionAndUnmapFromHeapObject(MM_EnvironmentBas
omrthread_monitor_enter(_largeObjectVirtualMemoryMutex);
ret = (_sparseDataPool->returnFreeListEntry(dataPtr, dataSize) && _sparseDataPool->unmapSparseDataPtrFromHeapProxyObjectPtr(dataPtr));
omrthread_monitor_exit(_largeObjectVirtualMemoryMutex);
Trc_MM_SparseVirtualMemory_decommitMemory_success(dataPtr, (void*)dataSize);
Trc_MM_SparseVirtualMemory_decommitMemory_success(dataPtr, (void *)dataSize);
} else {
Trc_MM_SparseVirtualMemory_decommitMemory_failure(dataPtr, (void*)dataSize);
Trc_MM_SparseVirtualMemory_decommitMemory_failure(dataPtr, (void *)dataSize);
/* TODO: Assert Fatal in case of failure? */
Assert_MM_true(false);
}
Expand All @@ -180,7 +175,7 @@ MM_SparseVirtualMemory::freeSparseRegionAndUnmapFromHeapObject(MM_EnvironmentBas
return ret;
}
bool
MM_SparseVirtualMemory::decommitMemory(MM_EnvironmentBase* env, void* address, uintptr_t size)
MM_SparseVirtualMemory::decommitMemory(MM_EnvironmentBase *env, void *address, uintptr_t size)
{
bool ret = false;
void *highValidAddress = (void *)((uintptr_t)address + size);
Expand Down

0 comments on commit 22a5046

Please sign in to comment.