# HG changeset patch # User thartmann # Date 1548143449 -3600 # Node ID 9db898820f63be725a7bd3643b9f2d91c320641f # Parent 698ee6095c76f00f84348ef3b23f597235c3fb25 8217291: Failure of ::realloc() should be handled correctly in adlc/forms.cpp Summary: Handle reallocation failures in adlc. Reviewed-by: kvn, neliasso diff -r 698ee6095c76 -r 9db898820f63 src/hotspot/share/adlc/arena.cpp --- a/src/hotspot/share/adlc/arena.cpp Tue Jan 22 08:47:01 2019 +0100 +++ b/src/hotspot/share/adlc/arena.cpp Tue Jan 22 08:50:49 2019 +0100 @@ -34,6 +34,16 @@ return ptr; } +void* ReAllocateHeap(void* old_ptr, size_t size) { + unsigned char* ptr = (unsigned char*) realloc(old_ptr, size); + if (ptr == NULL && size != 0) { + fprintf(stderr, "Error: Out of memory in ADLC\n"); // logging can cause crash! + fflush(stderr); + exit(1); + } + return ptr; +} + void* Chunk::operator new(size_t requested_size, size_t length) throw() { return CHeapObj::operator new(requested_size + length); } diff -r 698ee6095c76 -r 9db898820f63 src/hotspot/share/adlc/arena.hpp --- a/src/hotspot/share/adlc/arena.hpp Tue Jan 22 08:47:01 2019 +0100 +++ b/src/hotspot/share/adlc/arena.hpp Tue Jan 22 08:50:49 2019 +0100 @@ -26,6 +26,7 @@ #define SHARE_ADLC_ARENA_HPP void* AllocateHeap(size_t size); +void* ReAllocateHeap(void* old_ptr, size_t size); // All classes in adlc may be derived // from one of the following allocation classes: diff -r 698ee6095c76 -r 9db898820f63 src/hotspot/share/adlc/forms.cpp --- a/src/hotspot/share/adlc/forms.cpp Tue Jan 22 08:47:01 2019 +0100 +++ b/src/hotspot/share/adlc/forms.cpp Tue Jan 22 08:50:49 2019 +0100 @@ -48,7 +48,9 @@ } void NameList::addName(const char *name) { - if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*)); + if (_cur == _max) { + _names = (const char**) ReAllocateHeap(_names, (_max *=2)*sizeof(char*)); + } _names[_cur++] = name; }