--- old/src/hotspot/share/memory/allocation.cpp 2018-03-16 07:20:10.908108768 +0100 +++ new/src/hotspot/share/memory/allocation.cpp 2018-03-16 07:20:10.708108775 +0100 @@ -37,6 +37,49 @@ #include "services/memTracker.hpp" #include "utilities/ostream.hpp" +// allocate using malloc; will fail if no memory available +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const NativeCallStack& stack, + AllocFailType alloc_failmode) { + char* p = (char*) os::malloc(size, flags, stack); + if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { + vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); + } + return p; +} + +char* AllocateHeap(size_t size, + MEMFLAGS flags) { + return AllocateHeap(size, flags, CALLER_PC); +} +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const std::nothrow_t& nothrow_constant) { + return AllocateHeap(size, flags, CALLER_PC, AllocFailStrategy::RETURN_NULL); +} +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const std::nothrow_t& nothrow_constant, + const NativeCallStack& stack) { + return AllocateHeap(size, flags, stack, AllocFailStrategy::RETURN_NULL); +} + +char* ReallocateHeap(char *old, + size_t size, + MEMFLAGS flag, + AllocFailType alloc_failmode) { + char* p = (char*) os::realloc(old, size, flag, CALLER_PC); + if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { + vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); + } + return p; +} + +void FreeHeap(void* p) { + os::free(p); +} + void* MetaspaceObj::_shared_metaspace_base = NULL; void* MetaspaceObj::_shared_metaspace_top = NULL; --- old/src/hotspot/share/memory/allocation.hpp 2018-03-16 07:20:11.220108757 +0100 +++ new/src/hotspot/share/memory/allocation.hpp 2018-03-16 07:20:11.020108764 +0100 @@ -154,22 +154,71 @@ class NativeCallStack; +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const NativeCallStack& stack, + AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); +char* AllocateHeap(size_t size, + MEMFLAGS flags); +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const std::nothrow_t& nothrow_constant); +char* AllocateHeap(size_t size, + MEMFLAGS flags, + const std::nothrow_t& nothrow_constant, + const NativeCallStack& stack); + +char* ReallocateHeap(char *old, + size_t size, + MEMFLAGS flag, + AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); + +void FreeHeap(void* p); + template class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { public: - NOINLINE void* operator new(size_t size, const NativeCallStack& stack) throw(); - NOINLINE void* operator new(size_t size) throw(); - NOINLINE void* operator new (size_t size, const std::nothrow_t& nothrow_constant, - const NativeCallStack& stack) throw(); - NOINLINE void* operator new (size_t size, const std::nothrow_t& nothrow_constant) - throw(); - NOINLINE void* operator new [](size_t size, const NativeCallStack& stack) throw(); - NOINLINE void* operator new [](size_t size) throw(); - NOINLINE void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, - const NativeCallStack& stack) throw(); - NOINLINE void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) - throw(); - void operator delete(void* p); - void operator delete [] (void* p); + ALWAYSINLINE void* operator new(size_t size) throw() { + return (void*)AllocateHeap(size, F); + } + + ALWAYSINLINE void* operator new(size_t size, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, stack); + } + + ALWAYSINLINE void* operator new(size_t size, + const std::nothrow_t& nothrow_constant, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, nothrow_constant, stack); + } + + ALWAYSINLINE void* operator new(size_t size, + const std::nothrow_t& nothrow_constant) throw() { + return (void*)AllocateHeap(size, F, nothrow_constant); + } + + ALWAYSINLINE void* operator new[](size_t size) throw() { + return (void*)AllocateHeap(size, F); + } + + ALWAYSINLINE void* operator new[](size_t size, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, stack); + } + + ALWAYSINLINE void* operator new[](size_t size, + const std::nothrow_t& nothrow_constant, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, nothrow_constant, stack); + } + + ALWAYSINLINE void* operator new[](size_t size, + const std::nothrow_t& nothrow_constant) throw() { + return (void*)AllocateHeap(size, F, nothrow_constant); + } + + void operator delete(void* p) { FreeHeap(p); } + void operator delete [] (void* p) { FreeHeap(p); } }; // Base class for objects allocated on the stack only. --- old/src/hotspot/share/memory/allocation.inline.hpp 2018-03-16 07:20:11.552108745 +0100 +++ new/src/hotspot/share/memory/allocation.inline.hpp 2018-03-16 07:20:11.348108753 +0100 @@ -48,83 +48,6 @@ } #endif -// allocate using malloc; will fail if no memory available -inline char* AllocateHeap(size_t size, MEMFLAGS flags, - const NativeCallStack& stack, - AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { - char* p = (char*) os::malloc(size, flags, stack); - if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { - vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); - } - return p; -} - -ALWAYSINLINE char* AllocateHeap(size_t size, MEMFLAGS flags, - AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { - return AllocateHeap(size, flags, CURRENT_PC, alloc_failmode); -} - -ALWAYSINLINE char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag, - AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { - char* p = (char*) os::realloc(old, size, flag, CURRENT_PC); - if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { - vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); - } - return p; -} - -inline void FreeHeap(void* p) { - os::free(p); -} - - -template void* CHeapObj::operator new(size_t size, - const NativeCallStack& stack) throw() { - return (void*)AllocateHeap(size, F, stack); -} - -template void* CHeapObj::operator new(size_t size) throw() { - return CHeapObj::operator new(size, CALLER_PC); -} - -template void* CHeapObj::operator new (size_t size, - const std::nothrow_t& nothrow_constant, const NativeCallStack& stack) throw() { - return (void*)AllocateHeap(size, F, stack, AllocFailStrategy::RETURN_NULL); -} - -template void* CHeapObj::operator new (size_t size, - const std::nothrow_t& nothrow_constant) throw() { - return CHeapObj::operator new(size, nothrow_constant, CALLER_PC); -} - -template void* CHeapObj::operator new [](size_t size, - const NativeCallStack& stack) throw() { - return CHeapObj::operator new(size, stack); -} - -template void* CHeapObj::operator new [](size_t size) - throw() { - return CHeapObj::operator new(size, CALLER_PC); -} - -template void* CHeapObj::operator new [](size_t size, - const std::nothrow_t& nothrow_constant, const NativeCallStack& stack) throw() { - return CHeapObj::operator new(size, nothrow_constant, stack); -} - -template void* CHeapObj::operator new [](size_t size, - const std::nothrow_t& nothrow_constant) throw() { - return CHeapObj::operator new(size, nothrow_constant, CALLER_PC); -} - -template void CHeapObj::operator delete(void* p){ - FreeHeap(p); -} - -template void CHeapObj::operator delete [](void* p){ - FreeHeap(p); -} - template size_t MmapArrayAllocator::size_for(size_t length) { size_t size = length * sizeof(E);