8217291: Failure of ::realloc() should be handled correctly in adlc/forms.cpp
Summary: Handle reallocation failures in adlc.
Reviewed-by: kvn, neliasso
--- 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);
}
--- 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:
--- 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;
}