# HG changeset patch # User stuefe # Date 1562055900 -7200 # Node ID e846a51e8966d70e3c15ef0c75306940fc3655bd # Parent 448d63614b6b8ad0e636f6d0a2fb6feb2eb0fc62 8227035: JVM::printFlags fails in native OOM situations Reviewed-by: goetz, gziemski diff -r 448d63614b6b -r e846a51e8966 src/hotspot/share/runtime/flags/jvmFlag.cpp --- a/src/hotspot/share/runtime/flags/jvmFlag.cpp Mon Jul 01 17:08:04 2019 -0700 +++ b/src/hotspot/share/runtime/flags/jvmFlag.cpp Tue Jul 02 10:25:00 2019 +0200 @@ -1475,19 +1475,13 @@ void JVMFlag::printFlags(outputStream* out, bool withComments, bool printRanges, bool skipDefaults) { // Print the flags sorted by name - // note: this method is called before the thread structure is in place - // which means resource allocation cannot be used. + // Note: This method may be called before the thread structure is in place + // which means resource allocation cannot be used. Also, it may be + // called as part of error reporting, so handle native OOMs gracefully. // The last entry is the null entry. const size_t length = JVMFlag::numFlags - 1; - // Sort - JVMFlag** array = NEW_C_HEAP_ARRAY(JVMFlag*, length, mtArguments); - for (size_t i = 0; i < length; i++) { - array[i] = &flagTable[i]; - } - qsort(array, length, sizeof(JVMFlag*), compare_flags); - // Print if (!printRanges) { out->print_cr("[Global flags]"); @@ -1495,12 +1489,28 @@ out->print_cr("[Global flags ranges]"); } - for (size_t i = 0; i < length; i++) { - if (array[i]->is_unlocked() && !(skipDefaults && array[i]->is_default())) { - array[i]->print_on(out, withComments, printRanges); + // Sort + JVMFlag** array = NEW_C_HEAP_ARRAY_RETURN_NULL(JVMFlag*, length, mtArguments); + if (array != NULL) { + for (size_t i = 0; i < length; i++) { + array[i] = &flagTable[i]; + } + qsort(array, length, sizeof(JVMFlag*), compare_flags); + + for (size_t i = 0; i < length; i++) { + if (array[i]->is_unlocked() && !(skipDefaults && array[i]->is_default())) { + array[i]->print_on(out, withComments, printRanges); + } + } + FREE_C_HEAP_ARRAY(JVMFlag*, array); + } else { + // OOM? Print unsorted. + for (size_t i = 0; i < length; i++) { + if (flagTable[i].is_unlocked() && !(skipDefaults && flagTable[i].is_default())) { + flagTable[i].print_on(out, withComments, printRanges); + } } } - FREE_C_HEAP_ARRAY(JVMFlag*, array); } void JVMFlag::printError(bool verbose, const char* msg, ...) {