# HG changeset patch # User simonis # Date 1521223993 -3600 # Node ID 4881673579b7f8a7c9c5a2af4b4d2fb7cadd4b2f # Parent 7ea4724a959c7f475e4450affb10269efa4927b9 8199698: Change 8199275 breaks template instantiation for xlC (and potentially other compliers) Reviewed-by: stefank, coleenp diff -r 7ea4724a959c -r 4881673579b7 src/hotspot/share/memory/allocation.cpp --- a/src/hotspot/share/memory/allocation.cpp Tue Mar 20 13:40:03 2018 +0530 +++ b/src/hotspot/share/memory/allocation.cpp Fri Mar 16 19:13:13 2018 +0100 @@ -37,6 +37,39 @@ #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 /* = 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; +} + +char* AllocateHeap(size_t size, + MEMFLAGS flags, + AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/) { + return AllocateHeap(size, flags, CALLER_PC); +} + +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; diff -r 7ea4724a959c -r 4881673579b7 src/hotspot/share/memory/allocation.hpp --- a/src/hotspot/share/memory/allocation.hpp Tue Mar 20 13:40:03 2018 +0530 +++ b/src/hotspot/share/memory/allocation.hpp Fri Mar 16 19:13:13 2018 +0100 @@ -154,22 +154,61 @@ 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, + AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); + +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&, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, stack, AllocFailStrategy::RETURN_NULL); + } + + ALWAYSINLINE void* operator new(size_t size, const std::nothrow_t&) throw() { + return (void*)AllocateHeap(size, F, AllocFailStrategy::RETURN_NULL); + } + + 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&, + const NativeCallStack& stack) throw() { + return (void*)AllocateHeap(size, F, stack, AllocFailStrategy::RETURN_NULL); + } + + ALWAYSINLINE void* operator new[](size_t size, const std::nothrow_t&) throw() { + return (void*)AllocateHeap(size, F, AllocFailStrategy::RETURN_NULL); + } + + void operator delete(void* p) { FreeHeap(p); } + void operator delete [] (void* p) { FreeHeap(p); } }; // Base class for objects allocated on the stack only. diff -r 7ea4724a959c -r 4881673579b7 src/hotspot/share/memory/allocation.inline.hpp --- a/src/hotspot/share/memory/allocation.inline.hpp Tue Mar 20 13:40:03 2018 +0530 +++ b/src/hotspot/share/memory/allocation.inline.hpp Fri Mar 16 19:13:13 2018 +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); diff -r 7ea4724a959c -r 4881673579b7 src/hotspot/share/utilities/globalDefinitions_xlc.hpp --- a/src/hotspot/share/utilities/globalDefinitions_xlc.hpp Tue Mar 20 13:40:03 2018 +0530 +++ b/src/hotspot/share/utilities/globalDefinitions_xlc.hpp Fri Mar 16 19:13:13 2018 +0100 @@ -152,7 +152,18 @@ #endif // Inlining support -#define NOINLINE -#define ALWAYSINLINE inline __attribute__((always_inline)) +// +// Be aware that for function/method declarations, xlC only supports the following +// syntax (i.e. the attribute must be placed AFTER the function/method declarator): +// +// void* operator new(size_t size) throw() NOINLINE; +// +// For function/method defintions, the more common placement BEFORE the +// function/method declarator seems to be supported as well: +// +// NOINLINE void* CHeapObj::operator new(size_t size) throw() {...} + +#define NOINLINE __attribute__((__noinline__)) +#define ALWAYSINLINE inline __attribute__((__always_inline__)) #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_XLC_HPP