Пример #1
0
bool
MM_HeapVirtualMemory::initialize(MM_EnvironmentBase* env, uintptr_t size)
{
	/* call the superclass to inialize before we do any work */
	if (!MM_Heap::initialize(env)) {
		return false;
	}

	MM_GCExtensionsBase* extensions = env->getExtensions();
	uintptr_t padding = extensions->heapTailPadding;

	uintptr_t effectiveHeapAlignment = _heapAlignment;
	/* we need to ensure that we allocate the heap with region alignment since the region table requires that */
	MM_HeapRegionManager* manager = getHeapRegionManager();
	effectiveHeapAlignment = MM_Math::roundToCeiling(manager->getRegionSize(), effectiveHeapAlignment);

	MM_MemoryManager* memoryManager = extensions->memoryManager;
	bool created = false;
	bool forcedOverflowProtection = false;

	/* Under -Xaggressive ensure a full page of padding -- see JAZZ103 45254 */
	if (extensions->padToPageSize) {
#if (defined(AIXPPC) && !defined(PPC64))
		/*
		 * An attempt to allocate heap with top at 0xffffffff
		 * In this case extra padding is not required because of overflow protection padding can be used instead
		 */
		uintptr_t effectiveSize = MM_Math::roundToCeiling(manager->getRegionSize(), size);
		void *preferredHeapBase = (void *)((uintptr_t)0 - effectiveSize);

		created = memoryManager->createVirtualMemoryForHeap(env, &_vmemHandle, effectiveHeapAlignment, size, padding, preferredHeapBase, (void *)(extensions->heapCeiling));
		if (created) {
			/* overflow protection must be there to play role of padding even top is not so close to the end of the memory */
			forcedOverflowProtection = true;
		} else
#endif /* (defined(AIXPPC) && !defined(PPC64)) */
		{
			/* Ignore extra full page padding if page size is too large (hard coded here for 1G or larger) */
#define ONE_GB ((uintptr_t)1 * 1024 * 1024 * 1024)
			if (extensions->requestedPageSize < ONE_GB)
			{
				if (padding < extensions->requestedPageSize) {
					padding = extensions->requestedPageSize;
				}
			}
		}
	}

	if (!created && !memoryManager->createVirtualMemoryForHeap(env, &_vmemHandle, effectiveHeapAlignment, size, padding, (void*)(extensions->preferredHeapBase), (void*)(extensions->heapCeiling))) {
		return false;
	}

	/* Check we haven't overflowed the address range */
	if (forcedOverflowProtection || (HIGH_ADDRESS - ((uintptr_t)memoryManager->getHeapTop(&_vmemHandle)) < (OVERFLOW_ROUNDING)) || extensions->fvtest_alwaysApplyOverflowRounding) {
		/* Address range overflow */
		memoryManager->roundDownTop(&_vmemHandle, OVERFLOW_ROUNDING);
	}
	extensions->overflowSafeAllocSize = ((HIGH_ADDRESS - (uintptr_t)(memoryManager->getHeapTop(&_vmemHandle))) + 1);

	/* The memory returned might be less than we asked for -- get the actual size */
	_maximumMemorySize = memoryManager->getMaximumSize(&_vmemHandle);

	return true;
}
Пример #2
0
/**
 * Answer the largest size the heap will ever consume.
 * The value returned represents the difference between the lowest and highest possible address range
 * the heap can ever occupy.  This value includes any memory that may never be used by the heap (e.g.,
 * in a segmented heap scenario).
 * @return Maximum size that the heap will ever span.
 */
uintptr_t
MM_HeapVirtualMemory::getMaximumPhysicalRange()
{
	MM_MemoryManager* memoryManager = MM_GCExtensionsBase::getExtensions(_omrVM)->memoryManager;
	return ((uintptr_t)memoryManager->getMaximumSize(&_vmemHandle));
}