8227168: Cleanup usage of NEW_C_HEAP_ARRAY
authorlkorinth
Wed, 11 Sep 2019 14:16:27 +0200
changeset 58083 9046db64ca39
parent 58081 8b08eaf9a0eb
child 58084 cddef3bde924
8227168: Cleanup usage of NEW_C_HEAP_ARRAY Reviewed-by: coleenp, dholmes, kbarrett, tschatzl
src/hotspot/os/aix/os_aix.cpp
src/hotspot/os/aix/os_perf_aix.cpp
src/hotspot/os/bsd/os_bsd.cpp
src/hotspot/os/linux/os_linux.cpp
src/hotspot/os/linux/os_perf_linux.cpp
src/hotspot/os/solaris/os_perf_solaris.cpp
src/hotspot/os/solaris/os_solaris.cpp
src/hotspot/os/windows/os_perf_windows.cpp
src/hotspot/os/windows/perfMemory_windows.cpp
src/hotspot/share/classfile/moduleEntry.cpp
src/hotspot/share/compiler/oopMap.cpp
src/hotspot/share/gc/cms/parNewGeneration.cpp
src/hotspot/share/gc/parallel/psCompactionManager.cpp
src/hotspot/share/gc/shared/cardTableRS.cpp
src/hotspot/share/gc/shared/referenceProcessor.cpp
src/hotspot/share/gc/shared/workgroup.cpp
src/hotspot/share/interpreter/oopMapCache.cpp
src/hotspot/share/memory/allocation.hpp
src/hotspot/share/runtime/os.cpp
src/hotspot/share/runtime/perfData.cpp
src/hotspot/share/runtime/synchronizer.cpp
src/hotspot/share/runtime/thread.cpp
src/hotspot/share/services/memoryManager.cpp
--- a/src/hotspot/os/aix/os_aix.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/aix/os_aix.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -554,7 +554,7 @@
   const size_t bufsize =
     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR)); // extensions dir
-  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+  char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
   // sysclasspath, java_home, dll_dir
   {
@@ -596,7 +596,7 @@
 
   // Concatenate user and invariant part of ld_library_path.
   // That's +1 for the colon and +1 for the trailing '\0'.
-  char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
+  char *ld_library_path = NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
   sprintf(ld_library_path, "%s%s" DEFAULT_LIBPATH, v, v_colon);
   Arguments::set_library_path(ld_library_path);
   FREE_C_HEAP_ARRAY(char, ld_library_path);
--- a/src/hotspot/os/aix/os_perf_aix.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/aix/os_perf_aix.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -443,12 +443,12 @@
 }
 
 bool CPUPerformanceInterface::CPUPerformance::initialize() {
-  size_t tick_array_size = (_counters.nProcs +1) * sizeof(CPUPerfTicks);
-  _counters.cpus = (CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
+  size_t array_entry_count = _counters.nProcs + 1;
+  _counters.cpus = NEW_C_HEAP_ARRAY(CPUPerfTicks, array_entry_count, mtInternal);
   if (NULL == _counters.cpus) {
     return false;
   }
-  memset(_counters.cpus, 0, tick_array_size);
+  memset(_counters.cpus, 0, array_entry_count * sizeof(*_counters.cpus));
 
   // For the CPU load total
   get_total_ticks(-1, &_counters.cpus[_counters.nProcs]);
--- a/src/hotspot/os/bsd/os_bsd.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -337,7 +337,7 @@
   const size_t bufsize =
     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
-  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+  char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
   // sysclasspath, java_home, dll_dir
   {
@@ -387,10 +387,10 @@
     const char *v_colon = ":";
     if (v == NULL) { v = ""; v_colon = ""; }
     // That's +1 for the colon and +1 for the trailing '\0'.
-    char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
-                                                     strlen(v) + 1 +
-                                                     sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
-                                                     mtInternal);
+    char *ld_library_path = NEW_C_HEAP_ARRAY(char,
+                                             strlen(v) + 1 +
+                                             sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
+                                             mtInternal);
     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
     Arguments::set_library_path(ld_library_path);
     FREE_C_HEAP_ARRAY(char, ld_library_path);
@@ -418,7 +418,7 @@
   const size_t bufsize =
     MAX2((size_t)MAXPATHLEN,  // for dll_dir & friends.
          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size); // extensions dir
-  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+  char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
   // sysclasspath, java_home, dll_dir
   {
@@ -480,10 +480,10 @@
     // could cause a change in behavior, but Apple's Java6 behavior
     // can be achieved by putting "." at the beginning of the
     // JAVA_LIBRARY_PATH environment variable.
-    char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
-                                                     strlen(v) + 1 + strlen(l) + 1 +
-                                                     system_ext_size + 3,
-                                                     mtInternal);
+    char *ld_library_path = NEW_C_HEAP_ARRAY(char,
+                                             strlen(v) + 1 + strlen(l) + 1 +
+                                             system_ext_size + 3,
+                                             mtInternal);
     sprintf(ld_library_path, "%s%s%s%s%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS ":.",
             v, v_colon, l, l_colon, user_home_dir);
     Arguments::set_library_path(ld_library_path);
--- a/src/hotspot/os/linux/os_linux.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/linux/os_linux.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -428,7 +428,7 @@
   const size_t bufsize =
     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
-  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+  char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
   // sysclasspath, java_home, dll_dir
   {
@@ -477,10 +477,10 @@
     const char *v_colon = ":";
     if (v == NULL) { v = ""; v_colon = ""; }
     // That's +1 for the colon and +1 for the trailing '\0'.
-    char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
-                                                     strlen(v) + 1 +
-                                                     sizeof(SYS_EXT_DIR) + sizeof("/lib/") + sizeof(DEFAULT_LIBPATH) + 1,
-                                                     mtInternal);
+    char *ld_library_path = NEW_C_HEAP_ARRAY(char,
+                                             strlen(v) + 1 +
+                                             sizeof(SYS_EXT_DIR) + sizeof("/lib/") + sizeof(DEFAULT_LIBPATH) + 1,
+                                             mtInternal);
     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib:" DEFAULT_LIBPATH, v, v_colon);
     Arguments::set_library_path(ld_library_path);
     FREE_C_HEAP_ARRAY(char, ld_library_path);
--- a/src/hotspot/os/linux/os_perf_linux.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/linux/os_perf_linux.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -503,12 +503,12 @@
 }
 
 bool CPUPerformanceInterface::CPUPerformance::initialize() {
-  size_t tick_array_size = (_counters.nProcs +1) * sizeof(os::Linux::CPUPerfTicks);
-  _counters.cpus = (os::Linux::CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
+  size_t array_entry_count = _counters.nProcs + 1;
+  _counters.cpus = NEW_C_HEAP_ARRAY(os::Linux::CPUPerfTicks, array_entry_count, mtInternal);
   if (NULL == _counters.cpus) {
     return false;
   }
-  memset(_counters.cpus, 0, tick_array_size);
+  memset(_counters.cpus, 0, array_entry_count * sizeof(*_counters.cpus));
 
   // For the CPU load total
   os::Linux::get_tick_information(&_counters.cpus[_counters.nProcs], -1);
--- a/src/hotspot/os/solaris/os_perf_solaris.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/solaris/os_perf_solaris.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -300,12 +300,12 @@
   }
 
   // Data structure(s) for saving CPU load (one per CPU)
-  size_t tick_array_size = _counters.nProcs * sizeof(CPUPerfTicks);
-  _counters.jvmTicks = (CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
+  size_t array_entry_count = _counters.nProcs;
+  _counters.jvmTicks = NEW_C_HEAP_ARRAY(CPUPerfTicks, array_entry_count, mtInternal);
   if (NULL == _counters.jvmTicks) {
     return false;
   }
-  memset(_counters.jvmTicks, 0, tick_array_size);
+  memset(_counters.jvmTicks, 0, array_entry_count * sizeof(*_counters.jvmTicks));
 
   // Get kstat cpu_stat counters for every CPU
   // loop over kstat to find our cpu_stat(s)
--- a/src/hotspot/os/solaris/os_solaris.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -562,7 +562,7 @@
     MAX3((size_t)MAXPATHLEN,  // For dll_dir & friends.
          sizeof(SYS_EXT_DIR) + sizeof("/lib/"), // invariant ld_library_path
          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
-  char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
+  char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 
   // sysclasspath, java_home, dll_dir
   {
@@ -648,7 +648,7 @@
     // through the dlinfo() call, so only add additional space for the path
     // components explicitly added here.
     size_t library_path_size = info->dls_size + strlen(common_path);
-    library_path = (char *)NEW_C_HEAP_ARRAY(char, library_path_size, mtInternal);
+    library_path = NEW_C_HEAP_ARRAY(char, library_path_size, mtInternal);
     library_path[0] = '\0';
 
     // Construct the desired Java library path from the linker's library
--- a/src/hotspot/os/windows/os_perf_windows.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/windows/os_perf_windows.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -136,7 +136,7 @@
 }
 
 static CounterQueryP create_counter_query() {
-  CounterQueryP const query = NEW_C_HEAP_ARRAY(CounterQueryS, 1, mtInternal);
+  CounterQueryP const query = NEW_C_HEAP_OBJ(CounterQueryS, mtInternal);
   memset(query, 0, sizeof(CounterQueryS));
   return query;
 }
@@ -144,7 +144,7 @@
 static void destroy_counter_query(CounterQueryP query) {
   assert(query != NULL, "invariant");
   pdh_cleanup(&query->query.query, &query->counter);
-  FREE_C_HEAP_ARRAY(CounterQueryS, query);
+  FREE_C_HEAP_OBJ(query);
 }
 
 static MultiCounterQueryP create_multi_counter_query() {
@@ -182,7 +182,7 @@
 
 static void destroy_counter_query(ProcessQueryP process_query) {
   destroy_multi_counter_query(&process_query->set);
-  FREE_C_HEAP_ARRAY(ProcessQueryS, process_query);
+  FREE_C_HEAP_OBJ(process_query);
 }
 
 static int open_query(HQUERY* query) {
@@ -199,7 +199,7 @@
   assert(!query->initialized, "invariant");
   assert(0 == query->noOfCounters, "invariant");
   assert(query->counters == NULL, "invariant");
-  query->counters = (HCOUNTER*)NEW_C_HEAP_ARRAY(char, nofCounters * sizeof(HCOUNTER), mtInternal);
+  query->counters = NEW_C_HEAP_ARRAY(HCOUNTER, nofCounters, mtInternal);
   if (query->counters == NULL) {
     return OS_ERR;
   }
@@ -388,7 +388,7 @@
   if (OS_ERR == current_process_idx) {
     return NULL;
   }
-  ProcessQueryP const process_query = NEW_C_HEAP_ARRAY(ProcessQueryS, 1, mtInternal);
+  ProcessQueryP const process_query = NEW_C_HEAP_OBJ(ProcessQueryS, mtInternal);
   memset(process_query, 0, sizeof(ProcessQueryS));
   process_query->set.queries = NEW_C_HEAP_ARRAY(MultiCounterQueryS, current_process_idx + 1, mtInternal);
   memset(process_query->set.queries, 0, sizeof(MultiCounterQueryS) * (current_process_idx + 1));
--- a/src/hotspot/os/windows/perfMemory_windows.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/os/windows/perfMemory_windows.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -764,7 +764,7 @@
     lpSA->lpSecurityDescriptor = NULL;
 
     // free the security attributes structure
-    FREE_C_HEAP_ARRAY(char, lpSA);
+    FREE_C_HEAP_OBJ(lpSA);
   }
 }
 
@@ -1073,8 +1073,8 @@
   // allocate and initialize the security attributes structure and
   // return it to the caller.
   //
-  LPSECURITY_ATTRIBUTES lpSA = (LPSECURITY_ATTRIBUTES)
-    NEW_C_HEAP_ARRAY(char, sizeof(SECURITY_ATTRIBUTES), mtInternal);
+  LPSECURITY_ATTRIBUTES lpSA =
+      NEW_C_HEAP_OBJ(SECURITY_ATTRIBUTES, mtInternal);
   lpSA->nLength = sizeof(SECURITY_ATTRIBUTES);
   lpSA->lpSecurityDescriptor = pSD;
   lpSA->bInheritHandle = FALSE;
--- a/src/hotspot/share/classfile/moduleEntry.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/classfile/moduleEntry.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -284,7 +284,7 @@
 // This is okay because the unnamed module gets created before the ClassLoaderData
 // is available to other threads.
 ModuleEntry* ModuleEntry::new_unnamed_module_entry(Handle module_handle, ClassLoaderData* cld) {
-  ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, sizeof(ModuleEntry), mtModule);
+  ModuleEntry* entry = NEW_C_HEAP_OBJ(ModuleEntry, mtModule);
 
   // Initialize everything BasicHashtable would
   entry->set_next(NULL);
@@ -311,7 +311,7 @@
 
 void ModuleEntry::delete_unnamed_module() {
   // Do not need unlink_entry() since the unnamed module is not in the hashtable
-  FREE_C_HEAP_ARRAY(char, this);
+  FREE_C_HEAP_OBJ(this);
 }
 
 ModuleEntryTable::ModuleEntryTable(int table_size)
--- a/src/hotspot/share/compiler/oopMap.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/compiler/oopMap.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -732,7 +732,7 @@
   _required = heap_size();
 
   // We need to allocate a chunk big enough to hold the ImmutableOopMapSet and all of its ImmutableOopMaps
-  address buffer = (address) NEW_C_HEAP_ARRAY(unsigned char, _required, mtCode);
+  address buffer = NEW_C_HEAP_ARRAY(unsigned char, _required, mtCode);
   return generate_into(buffer);
 }
 
--- a/src/hotspot/share/gc/cms/parNewGeneration.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/gc/cms/parNewGeneration.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1245,7 +1245,7 @@
     assert(_num_par_pushes > 0, "Tautology");
 #endif
     if (from_space_obj->forwardee() == from_space_obj) {
-      oopDesc* listhead = NEW_C_HEAP_ARRAY(oopDesc, 1, mtGC);
+      oopDesc* listhead = NEW_C_HEAP_OBJ(oopDesc, mtGC);
       listhead->forward_to(from_space_obj);
       from_space_obj = listhead;
     }
@@ -1401,7 +1401,7 @@
       // This can become a scaling bottleneck when there is work queue overflow coincident
       // with promotion failure.
       oopDesc* f = cur;
-      FREE_C_HEAP_ARRAY(oopDesc, f);
+      FREE_C_HEAP_OBJ(f);
     } else if (par_scan_state->should_be_partially_scanned(obj_to_push, cur)) {
       assert(arrayOop(cur)->length() == 0, "entire array remaining to be scanned");
       obj_to_push = cur;
--- a/src/hotspot/share/gc/parallel/psCompactionManager.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/gc/parallel/psCompactionManager.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -76,7 +76,6 @@
 
   assert(_manager_array == NULL, "Attempt to initialize twice");
   _manager_array = NEW_C_HEAP_ARRAY(ParCompactionManager*, parallel_gc_threads+1, mtGC);
-  guarantee(_manager_array != NULL, "Could not allocate manager_array");
 
   _stack_array = new OopTaskQueueSet(parallel_gc_threads);
   guarantee(_stack_array != NULL, "Could not allocate stack_array");
--- a/src/hotspot/share/gc/shared/cardTableRS.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/gc/shared/cardTableRS.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -656,11 +656,7 @@
     NEW_C_HEAP_ARRAY(uintptr_t, _max_covered_regions, mtGC);
   _last_LNC_resizing_collection =
     NEW_C_HEAP_ARRAY(int, _max_covered_regions, mtGC);
-  if (_lowest_non_clean == NULL
-      || _lowest_non_clean_chunk_size == NULL
-      || _lowest_non_clean_base_chunk_index == NULL
-      || _last_LNC_resizing_collection == NULL)
-    vm_exit_during_initialization("couldn't allocate an LNC array.");
+
   for (int i = 0; i < _max_covered_regions; i++) {
     _lowest_non_clean[i] = NULL;
     _lowest_non_clean_chunk_size[i] = 0;
--- a/src/hotspot/share/gc/shared/referenceProcessor.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/gc/shared/referenceProcessor.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -119,9 +119,6 @@
   _discovered_refs     = NEW_C_HEAP_ARRAY(DiscoveredList,
             _max_num_queues * number_of_subclasses_of_ref(), mtGC);
 
-  if (_discovered_refs == NULL) {
-    vm_exit_during_initialization("Could not allocated RefProc Array");
-  }
   _discoveredSoftRefs    = &_discovered_refs[0];
   _discoveredWeakRefs    = &_discoveredSoftRefs[_max_num_queues];
   _discoveredFinalRefs   = &_discoveredWeakRefs[_max_num_queues];
--- a/src/hotspot/share/gc/shared/workgroup.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/gc/shared/workgroup.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -40,10 +40,6 @@
 void  AbstractWorkGang::initialize_workers() {
   log_develop_trace(gc, workgang)("Constructing work gang %s with %u threads", name(), total_workers());
   _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal);
-  if (_workers == NULL) {
-    vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array.");
-  }
-
   add_workers(true);
 }
 
@@ -409,7 +405,6 @@
 SubTasksDone::SubTasksDone(uint n) :
   _tasks(NULL), _n_tasks(n), _threads_completed(0) {
   _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal);
-  guarantee(_tasks != NULL, "alloc failure");
   clear();
 }
 
--- a/src/hotspot/share/interpreter/oopMapCache.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/interpreter/oopMapCache.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -594,9 +594,9 @@
 
 void OopMapCache::compute_one_oop_map(const methodHandle& method, int bci, InterpreterOopMap* entry) {
   // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
-  OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1, mtClass);
+  OopMapCacheEntry* tmp = NEW_C_HEAP_OBJ(OopMapCacheEntry, mtClass);
   tmp->initialize();
   tmp->fill(method, bci);
   entry->resource_copy(tmp);
-  FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp);
+  FREE_C_HEAP_OBJ(tmp);
 }
--- a/src/hotspot/share/memory/allocation.hpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/memory/allocation.hpp	Wed Sep 11 14:16:27 2019 +0200
@@ -80,16 +80,21 @@
 // stored in the array then must pay attention to calling destructors
 // at needed.
 //
-//   NEW_RESOURCE_ARRAY(type, size)
-//   NEW_RESOURCE_OBJ(type)
-//   NEW_C_HEAP_ARRAY(type, size)
-//   NEW_C_HEAP_OBJ(type, memflags)
-//   FREE_C_HEAP_ARRAY(type, old)
-//   FREE_C_HEAP_OBJ(objname, type, memflags)
-//   char* AllocateHeap(size_t size, const char* name);
-//   void  FreeHeap(void* p);
+// NEW_RESOURCE_ARRAY*
+// REALLOC_RESOURCE_ARRAY*
+// FREE_RESOURCE_ARRAY*
+// NEW_RESOURCE_OBJ*
+// NEW_C_HEAP_ARRAY*
+// REALLOC_C_HEAP_ARRAY*
+// FREE_C_HEAP_ARRAY*
+// NEW_C_HEAP_OBJ*
+// FREE_C_HEAP_OBJ
 //
-
+// 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);
+//
 // In non product mode we introduce a super class for all allocation classes
 // that supports printing.
 // We avoid the superclass in product mode to save space.
--- a/src/hotspot/share/runtime/os.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/runtime/os.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -291,7 +291,7 @@
   bool retval = false;
 
   size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX);
-  char* fullfname = (char*)NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal);
+  char* fullfname = NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal);
   if (dll_build_name(fullfname, fullfnamelen + 1, fname)) {
     const size_t pnamelen = pname ? strlen(pname) : 0;
 
@@ -1329,7 +1329,7 @@
     return NULL;
   }
   const char psepchar = *os::path_separator();
-  char* inpath = (char*)NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal);
+  char* inpath = NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal);
   if (inpath == NULL) {
     return NULL;
   }
@@ -1342,7 +1342,8 @@
     p++;
     p = strchr(p, psepchar);
   }
-  char** opath = (char**) NEW_C_HEAP_ARRAY(char*, count, mtInternal);
+
+  char** opath = NEW_C_HEAP_ARRAY(char*, count, mtInternal);
 
   // do the actual splitting
   p = inpath;
@@ -1356,7 +1357,8 @@
                                     "sun.boot.library.path, to identify potential sources for this path.");
     }
     // allocate the string and add terminator storage
-    char* s  = (char*)NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal);
+    char* s  = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal);
+
     if (s == NULL) {
       // release allocated storage before returning null
       free_array_of_char_arrays(opath, i++);
--- a/src/hotspot/share/runtime/perfData.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/runtime/perfData.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,7 @@
   const char* prefix = PerfDataManager::ns_to_string(ns);
 
   _name = NEW_C_HEAP_ARRAY(char, strlen(name) + strlen(prefix) + 2, mtInternal);
-  assert(_name != NULL && strlen(name) != 0, "invalid name");
+  assert(strlen(name) != 0, "invalid name");
 
   if (ns == NULL_NS) {
      // No prefix is added to counters with the NULL_NS namespace.
--- a/src/hotspot/share/runtime/synchronizer.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/runtime/synchronizer.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1075,17 +1075,8 @@
     size_t neededsize = sizeof(PaddedObjectMonitor) * _BLOCKSIZE;
     PaddedObjectMonitor* temp;
     size_t aligned_size = neededsize + (DEFAULT_CACHE_LINE_SIZE - 1);
-    void* real_malloc_addr = (void*)NEW_C_HEAP_ARRAY(char, aligned_size,
-                                                     mtInternal);
+    void* real_malloc_addr = NEW_C_HEAP_ARRAY(char, aligned_size, mtInternal);
     temp = (PaddedObjectMonitor*)align_up(real_malloc_addr, DEFAULT_CACHE_LINE_SIZE);
-
-    // NOTE: (almost) no way to recover if allocation failed.
-    // We might be able to induce a STW safepoint and scavenge enough
-    // ObjectMonitors to permit progress.
-    if (temp == NULL) {
-      vm_exit_out_of_memory(neededsize, OOM_MALLOC_ERROR,
-                            "Allocate ObjectMonitors");
-    }
     (void)memset((void *) temp, 0, neededsize);
 
     // Format the block.
--- a/src/hotspot/share/runtime/thread.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/runtime/thread.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -1337,7 +1337,6 @@
 void NamedThread::set_name(const char* format, ...) {
   guarantee(_name == NULL, "Only get to set name once.");
   _name = NEW_C_HEAP_ARRAY(char, max_name_len, mtThread);
-  guarantee(_name != NULL, "alloc failure");
   va_list ap;
   va_start(ap, format);
   jio_vsnprintf(_name, max_name_len, format, ap);
--- a/src/hotspot/share/services/memoryManager.cpp	Wed Sep 11 10:19:09 2019 +0200
+++ b/src/hotspot/share/services/memoryManager.cpp	Wed Sep 11 14:16:27 2019 +0200
@@ -143,8 +143,8 @@
 
 GCStatInfo::GCStatInfo(int num_pools) {
   // initialize the arrays for memory usage
-  _before_gc_usage_array = (MemoryUsage*) NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
-  _after_gc_usage_array  = (MemoryUsage*) NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
+  _before_gc_usage_array = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
+  _after_gc_usage_array  = NEW_C_HEAP_ARRAY(MemoryUsage, num_pools, mtInternal);
   _usage_array_size = num_pools;
   clear();
 }