diff a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -552,11 +552,11 @@ // Note that the space for the trailing null is provided // by the nulls included by the sizeof operator. 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 { char *pslash; os::jvm_path(buf, bufsize); @@ -594,11 +594,11 @@ const char *v_colon = ":"; if (v == NULL) { v = ""; v_colon = ""; } // 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); // Extensions directories. diff a/src/hotspot/os/aix/os_perf_aix.cpp b/src/hotspot/os/aix/os_perf_aix.cpp --- a/src/hotspot/os/aix/os_perf_aix.cpp +++ b/src/hotspot/os/aix/os_perf_aix.cpp @@ -441,16 +441,16 @@ _counters.nProcs = os::active_processor_count(); _counters.cpus = NULL; } 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]); // For each CPU diff a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -335,11 +335,11 @@ // Note that the space for the colon and the trailing null are provided // by the nulls included by the sizeof operator. 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 { char *pslash; os::jvm_path(buf, bufsize); @@ -385,14 +385,14 @@ // addressed). const char *v = ::getenv("LD_LIBRARY_PATH"); 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); } @@ -416,11 +416,11 @@ // Note that the space for the colon and the trailing null are provided // by the nulls included by the sizeof operator. 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 { char *pslash; os::jvm_path(buf, bufsize); @@ -478,14 +478,14 @@ // at all. To ease the transition from Apple's Java6 to OpenJDK7, // "." is appended to the end of java.library.path. Yes, this // 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); FREE_C_HEAP_ARRAY(char, ld_library_path); } diff a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -426,11 +426,11 @@ // Note that the space for the colon and the trailing null are provided // by the nulls included by the sizeof operator. 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 { char *pslash; os::jvm_path(buf, bufsize); @@ -475,14 +475,14 @@ // addressed). const char *v = ::getenv("LD_LIBRARY_PATH"); 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); } diff a/src/hotspot/os/linux/os_perf_linux.cpp b/src/hotspot/os/linux/os_perf_linux.cpp --- a/src/hotspot/os/linux/os_perf_linux.cpp +++ b/src/hotspot/os/linux/os_perf_linux.cpp @@ -501,16 +501,16 @@ _counters.nProcs = os::active_processor_count(); _counters.cpus = NULL; } 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); // For each CPU diff a/src/hotspot/os/solaris/os_perf_solaris.cpp b/src/hotspot/os/solaris/os_perf_solaris.cpp --- a/src/hotspot/os/solaris/os_perf_solaris.cpp +++ b/src/hotspot/os/solaris/os_perf_solaris.cpp @@ -298,16 +298,16 @@ if (_counters.nProcs == 0) { return false; } // 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) int i = 0; for (kstat_t* kstat = _counters.kstat_ctrl->kc_chain; kstat != NULL; kstat = kstat->ks_next) { diff a/src/hotspot/os/solaris/os_solaris.cpp b/src/hotspot/os/solaris/os_solaris.cpp --- a/src/hotspot/os/solaris/os_solaris.cpp +++ b/src/hotspot/os/solaris/os_solaris.cpp @@ -560,11 +560,11 @@ // by the nulls included by the sizeof operator. const size_t bufsize = 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 { char *pslash; os::jvm_path(buf, bufsize); @@ -646,11 +646,11 @@ // Struct size is more than sufficient for the path components obtained // 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 // search path. // diff a/src/hotspot/os/windows/os_perf_windows.cpp b/src/hotspot/os/windows/os_perf_windows.cpp --- a/src/hotspot/os/windows/os_perf_windows.cpp +++ b/src/hotspot/os/windows/os_perf_windows.cpp @@ -134,11 +134,11 @@ *query = NULL; } } 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; } static void destroy_counter_query(CounterQueryP query) { @@ -142,11 +142,11 @@ } 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() { MultiCounterQueryP const query = NEW_C_HEAP_ARRAY(MultiCounterQueryS, 1, mtInternal); memset(query, 0, sizeof(MultiCounterQueryS)); @@ -180,11 +180,11 @@ FREE_C_HEAP_ARRAY(MultiCounterQuerySetS, counter_query_set); } 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) { return PdhDll::PdhOpenQuery(NULL, 0, query); } @@ -197,11 +197,11 @@ static int allocate_counters(MultiCounterQueryP query, size_t nofCounters) { assert(query != NULL, "invariant"); 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; } memset(query->counters, 0, nofCounters * sizeof(HCOUNTER)); query->noOfCounters = (int)nofCounters; @@ -386,11 +386,11 @@ static ProcessQueryP create_process_query() { const int current_process_idx = current_query_index_for_process(); 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)); process_query->process_index = current_process_idx; process_query->set.size = current_process_idx + 1; diff a/src/hotspot/os/windows/perfMemory_windows.cpp b/src/hotspot/os/windows/perfMemory_windows.cpp --- a/src/hotspot/os/windows/perfMemory_windows.cpp +++ b/src/hotspot/os/windows/perfMemory_windows.cpp @@ -1,7 +1,7 @@ /* - * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. @@ -762,11 +762,11 @@ // free the contained security descriptor and the ACL free_security_desc(lpSA->lpSecurityDescriptor); lpSA->lpSecurityDescriptor = NULL; // free the security attributes structure - FREE_C_HEAP_ARRAY(char, lpSA); + FREE_C_HEAP_OBJ(lpSA); } } // get the user SID for the process indicated by the process handle // @@ -1071,12 +1071,12 @@ } // 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; return(lpSA); diff a/src/hotspot/share/classfile/moduleEntry.cpp b/src/hotspot/share/classfile/moduleEntry.cpp --- a/src/hotspot/share/classfile/moduleEntry.cpp +++ b/src/hotspot/share/classfile/moduleEntry.cpp @@ -282,11 +282,11 @@ // When creating an unnamed module, this is called without holding the Module_lock. // 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); entry->set_hash(0); entry->set_literal(NULL); @@ -309,11 +309,11 @@ return entry; } 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) : Hashtable(table_size, sizeof(ModuleEntry)) { diff a/src/hotspot/share/compiler/oopMap.cpp b/src/hotspot/share/compiler/oopMap.cpp --- a/src/hotspot/share/compiler/oopMap.cpp +++ b/src/hotspot/share/compiler/oopMap.cpp @@ -730,11 +730,11 @@ ImmutableOopMapSet* ImmutableOopMapBuilder::build() { _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); } ImmutableOopMapSet* ImmutableOopMapSet::build_from(const OopMapSet* oopmap_set) { ResourceMark mark; diff a/src/hotspot/share/gc/cms/parNewGeneration.cpp b/src/hotspot/share/gc/cms/parNewGeneration.cpp --- a/src/hotspot/share/gc/cms/parNewGeneration.cpp +++ b/src/hotspot/share/gc/cms/parNewGeneration.cpp @@ -1243,11 +1243,11 @@ #ifndef PRODUCT Atomic::inc(&_num_par_pushes); 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; } oop observed_overflow_list = _overflow_list; oop cur_overflow_list; @@ -1400,11 +1400,11 @@ // space, cur, is not in the Java heap, but rather in the C-heap and should be freed. if (!is_in_reserved(cur)) { // 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; } bool ok = work_q->push(obj_to_push); diff a/src/hotspot/share/gc/parallel/psCompactionManager.cpp b/src/hotspot/share/gc/parallel/psCompactionManager.cpp --- a/src/hotspot/share/gc/parallel/psCompactionManager.cpp +++ b/src/hotspot/share/gc/parallel/psCompactionManager.cpp @@ -74,11 +74,10 @@ uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers(); 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"); _objarray_queues = new ObjArrayTaskQueueSet(parallel_gc_threads); guarantee(_objarray_queues != NULL, "Could not allocate objarray_queues"); diff a/src/hotspot/share/gc/shared/cardTableRS.cpp b/src/hotspot/share/gc/shared/cardTableRS.cpp --- a/src/hotspot/share/gc/shared/cardTableRS.cpp +++ b/src/hotspot/share/gc/shared/cardTableRS.cpp @@ -1,7 +1,7 @@ /* - * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. @@ -654,15 +654,11 @@ NEW_C_HEAP_ARRAY(size_t, _max_covered_regions, mtGC); _lowest_non_clean_base_chunk_index = 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; _last_LNC_resizing_collection[i] = -1; } diff a/src/hotspot/share/gc/shared/referenceProcessor.cpp b/src/hotspot/share/gc/shared/referenceProcessor.cpp --- a/src/hotspot/share/gc/shared/referenceProcessor.cpp +++ b/src/hotspot/share/gc/shared/referenceProcessor.cpp @@ -1,7 +1,7 @@ /* - * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. @@ -117,13 +117,10 @@ _num_queues = MAX2(1U, mt_processing_degree); _max_num_queues = MAX2(_num_queues, mt_discovery_degree); _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]; _discoveredPhantomRefs = &_discoveredFinalRefs[_max_num_queues]; diff a/src/hotspot/share/gc/shared/workgroup.cpp b/src/hotspot/share/gc/shared/workgroup.cpp --- a/src/hotspot/share/gc/shared/workgroup.cpp +++ b/src/hotspot/share/gc/shared/workgroup.cpp @@ -38,14 +38,10 @@ // The current implementation will exit if the allocation // of any worker fails. 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); } AbstractGangWorker* AbstractWorkGang::install_worker(uint worker_id) { @@ -407,11 +403,10 @@ // SubTasksDone functions. 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(); } bool SubTasksDone::valid() { return _tasks != NULL; diff a/src/hotspot/share/interpreter/oopMapCache.cpp b/src/hotspot/share/interpreter/oopMapCache.cpp --- a/src/hotspot/share/interpreter/oopMapCache.cpp +++ b/src/hotspot/share/interpreter/oopMapCache.cpp @@ -1,7 +1,7 @@ /* - * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. @@ -592,11 +592,11 @@ } } 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); } diff a/src/hotspot/share/memory/allocation.hpp b/src/hotspot/share/memory/allocation.hpp --- a/src/hotspot/share/memory/allocation.hpp +++ b/src/hotspot/share/memory/allocation.hpp @@ -78,20 +78,10 @@ // WARNING: The array variant must only be used for a homogenous array // where all objects are of the exact type specified. If subtypes are // 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); -// - // 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. #ifdef PRODUCT diff a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -295,11 +295,11 @@ bool os::dll_locate_lib(char *buffer, size_t buflen, const char* pname, const char* fname) { 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; if (pnamelen == 0) { // If no path given, use current working directory. @@ -1333,11 +1333,11 @@ *elements = (size_t)0; if (path == NULL || strlen(path) == 0 || file_name_length == (size_t)NULL) { 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; } strcpy(inpath, path); size_t count = 1; @@ -1346,11 +1346,12 @@ while (p != NULL) { count++; 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; for (size_t i = 0 ; i < count ; i++) { size_t len = strcspn(p, os::path_separator()); @@ -1360,11 +1361,12 @@ vm_exit_during_initialization("The VM tried to use a path that exceeds the maximum path length for " "this system. Review path-containing parameters and properties, such as " "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++); return NULL; } diff a/src/hotspot/share/runtime/perfData.cpp b/src/hotspot/share/runtime/perfData.cpp --- a/src/hotspot/share/runtime/perfData.cpp +++ b/src/hotspot/share/runtime/perfData.cpp @@ -1,7 +1,7 @@ /* - * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. @@ -83,11 +83,11 @@ : _name(NULL), _v(v), _u(u), _on_c_heap(false), _valuep(NULL) { 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. strcpy(_name, name); // set the F_Supported flag based on the counter name prefix. diff a/src/hotspot/share/runtime/synchronizer.cpp b/src/hotspot/share/runtime/synchronizer.cpp --- a/src/hotspot/share/runtime/synchronizer.cpp +++ b/src/hotspot/share/runtime/synchronizer.cpp @@ -1073,21 +1073,12 @@ // BEWARE: As it stands currently, we don't run the ctors! assert(_BLOCKSIZE > 1, "invariant"); 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. // initialize the linked list, each monitor points to its next // forming the single linked free list, the very first monitor diff a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -1335,11 +1335,10 @@ } 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); va_end(ap); } diff a/src/hotspot/share/services/memoryManager.cpp b/src/hotspot/share/services/memoryManager.cpp --- a/src/hotspot/share/services/memoryManager.cpp +++ b/src/hotspot/share/services/memoryManager.cpp @@ -141,12 +141,12 @@ f->do_oop((oop*) &_memory_mgr_obj); } 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(); } GCStatInfo::~GCStatInfo() {