8217291: Failure of ::realloc() should be handled correctly in adlc/forms.cpp

Handle reallocation failures in adlc.

Reviewed-by: kvn, neliasso
diff --git a/src/hotspot/share/adlc/arena.cpp b/src/hotspot/share/adlc/arena.cpp
index e984dc3..60a546e 100644
--- a/src/hotspot/share/adlc/arena.cpp
+++ b/src/hotspot/share/adlc/arena.cpp
@@ -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 --git a/src/hotspot/share/adlc/arena.hpp b/src/hotspot/share/adlc/arena.hpp
index ca16d69..d0dac9d 100644
--- a/src/hotspot/share/adlc/arena.hpp
+++ b/src/hotspot/share/adlc/arena.hpp
@@ -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 --git a/src/hotspot/share/adlc/forms.cpp b/src/hotspot/share/adlc/forms.cpp
index 5e2fb3f..ef72faa 100644
--- a/src/hotspot/share/adlc/forms.cpp
+++ b/src/hotspot/share/adlc/forms.cpp
@@ -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;
 }