Mercurial > hg > graal-jvmci-8
diff src/share/vm/memory/allocation.inline.hpp @ 9073:83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
Summary: Allow task queues to be mmapped instead of malloced on Solaris
Reviewed-by: coleenp, jmasa, johnc, tschatzl
author | brutisso |
---|---|
date | Mon, 08 Apr 2013 07:49:28 +0200 |
parents | 63e54c37ac64 |
children | 6f817ce50129 |
line wrap: on
line diff
--- a/src/share/vm/memory/allocation.inline.hpp Mon Feb 11 10:31:56 2013 -0800 +++ b/src/share/vm/memory/allocation.inline.hpp Mon Apr 08 07:49:28 2013 +0200 @@ -108,5 +108,49 @@ FreeHeap(p, F); } +template <class E, MEMFLAGS F> +E* ArrayAllocator<E, F>::allocate(size_t length) { + assert(_addr == NULL, "Already in use"); + + _size = sizeof(E) * length; + _use_malloc = _size < ArrayAllocatorMallocLimit; + + if (_use_malloc) { + _addr = AllocateHeap(_size, F); + if (_addr == NULL && _size >= (size_t)os::vm_allocation_granularity()) { + // malloc failed let's try with mmap instead + _use_malloc = false; + } else { + return (E*)_addr; + } + } + + int alignment = os::vm_allocation_granularity(); + _size = align_size_up(_size, alignment); + + _addr = os::reserve_memory(_size, NULL, alignment); + if (_addr == NULL) { + vm_exit_out_of_memory(_size, "Allocator (reserve)"); + } + + bool success = os::commit_memory(_addr, _size, false /* executable */); + if (!success) { + vm_exit_out_of_memory(_size, "Allocator (commit)"); + } + + return (E*)_addr; +} + +template<class E, MEMFLAGS F> +void ArrayAllocator<E, F>::free() { + if (_addr != NULL) { + if (_use_malloc) { + FreeHeap(_addr, F); + } else { + os::release_memory(_addr, _size); + } + _addr = NULL; + } +} #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP