1 /*
   2  * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2017, 2020 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "jvm.h"
  28 #include "cds/metaspaceShared.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "compiler/disassembler.hpp"
  32 #include "gc/shared/gcConfig.hpp"
  33 #include "gc/shared/gcLogPrecious.hpp"
  34 #include "logging/logConfiguration.hpp"
  35 #include "memory/metaspace.hpp"
  36 #include "memory/metaspaceUtils.hpp"
  37 #include "memory/resourceArea.inline.hpp"
  38 #include "memory/universe.hpp"
  39 #include "oops/compressedOops.hpp"
  40 #include "prims/whitebox.hpp"
  41 #include "runtime/arguments.hpp"
  42 #include "runtime/atomic.hpp"
  43 #include "runtime/frame.inline.hpp"
  44 #include "runtime/init.hpp"
  45 #include "runtime/os.hpp"
  46 #include "runtime/osThread.hpp"
  47 #include "runtime/safefetch.inline.hpp"
  48 #include "runtime/safepointMechanism.hpp"
  49 #include "runtime/stackFrameStream.inline.hpp"
  50 #include "runtime/thread.inline.hpp"
  51 #include "runtime/threadSMR.hpp"
  52 #include "runtime/vmThread.hpp"
  53 #include "runtime/vmOperations.hpp"
  54 #include "runtime/vm_version.hpp"
  55 #include "runtime/flags/jvmFlag.hpp"
  56 #include "services/memTracker.hpp"
  57 #include "utilities/debug.hpp"
  58 #include "utilities/decoder.hpp"
  59 #include "utilities/defaultStream.hpp"
  60 #include "utilities/events.hpp"
  61 #include "utilities/vmError.hpp"
  62 #include "utilities/macros.hpp"
  63 #if INCLUDE_JFR
  64 #include "jfr/jfr.hpp"
  65 #endif
  66 #if INCLUDE_JVMCI
  67 #include "jvmci/jvmci.hpp"
  68 #endif
  69 
  70 #ifndef PRODUCT
  71 #include <signal.h>
  72 #endif // PRODUCT
  73 
  74 bool              VMError::coredump_status;
  75 char              VMError::coredump_message[O_BUFLEN];
  76 int               VMError::_current_step;
  77 const char*       VMError::_current_step_info;
  78 volatile jlong    VMError::_reporting_start_time = -1;
  79 volatile bool     VMError::_reporting_did_timeout = false;
  80 volatile jlong    VMError::_step_start_time = -1;
  81 volatile bool     VMError::_step_did_timeout = false;
  82 volatile intptr_t VMError::_first_error_tid = -1;
  83 int               VMError::_id;
  84 const char*       VMError::_message;
  85 char              VMError::_detail_msg[1024];
  86 Thread*           VMError::_thread;
  87 address           VMError::_pc;
  88 void*             VMError::_siginfo;
  89 void*             VMError::_context;
  90 bool              VMError::_print_native_stack_used = false;
  91 const char*       VMError::_filename;
  92 int               VMError::_lineno;
  93 size_t            VMError::_size;
  94 
  95 // List of environment variables that should be reported in error log file.
  96 static const char* env_list[] = {
  97   // All platforms
  98   "JAVA_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
  99   "PATH", "USERNAME",
 100 
 101   // Env variables that are defined on Linux/BSD
 102   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
 103   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
 104   "LANG", "LC_ALL", "LC_CTYPE", "TZ",
 105 
 106   // defined on AIX
 107   "LIBPATH", "LDR_PRELOAD", "LDR_PRELOAD64",
 108 
 109   // defined on Linux/AIX/BSD
 110   "_JAVA_SR_SIGNUM",
 111 
 112   // defined on Darwin
 113   "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
 114   "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
 115   "DYLD_INSERT_LIBRARIES",
 116 
 117   // defined on Windows
 118   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
 119 
 120   (const char *)0
 121 };
 122 
 123 // A simple parser for -XX:OnError, usage:
 124 //  ptr = OnError;
 125 //  while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL)
 126 //     ... ...
 127 static char* next_OnError_command(char* buf, int buflen, const char** ptr) {
 128   if (ptr == NULL || *ptr == NULL) return NULL;
 129 
 130   const char* cmd = *ptr;
 131 
 132   // skip leading blanks or ';'
 133   while (*cmd == ' ' || *cmd == ';') cmd++;
 134 
 135   if (*cmd == '\0') return NULL;
 136 
 137   const char * cmdend = cmd;
 138   while (*cmdend != '\0' && *cmdend != ';') cmdend++;
 139 
 140   Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen);
 141 
 142   *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1);
 143   return buf;
 144 }
 145 
 146 static void print_bug_submit_message(outputStream *out, Thread *thread) {
 147   if (out == NULL) return;
 148   const char *url = Arguments::java_vendor_url_bug();
 149   if (url == NULL || *url == '\0')
 150     url = JDK_Version::runtime_vendor_vm_bug_url();
 151   if (url != NULL && *url != '\0') {
 152     out->print_raw_cr("# If you would like to submit a bug report, please visit:");
 153     out->print_raw   ("#   ");
 154     out->print_raw_cr(url);
 155   }
 156   // If the crash is in native code, encourage user to submit a bug to the
 157   // provider of that code.
 158   if (thread && thread->is_Java_thread() &&
 159       !thread->is_hidden_from_external_view()) {
 160     if (JavaThread::cast(thread)->thread_state() == _thread_in_native) {
 161       out->print_cr("# The crash happened outside the Java Virtual Machine in native code.\n# See problematic frame for where to report the bug.");
 162     }
 163   }
 164   out->print_raw_cr("#");
 165 }
 166 
 167 void VMError::record_coredump_status(const char* message, bool status) {
 168   coredump_status = status;
 169   strncpy(coredump_message, message, sizeof(coredump_message));
 170   coredump_message[sizeof(coredump_message)-1] = 0;
 171 }
 172 
 173 // Return a string to describe the error
 174 char* VMError::error_string(char* buf, int buflen) {
 175   char signame_buf[64];
 176   const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf));
 177 
 178   if (signame) {
 179     jio_snprintf(buf, buflen,
 180                  "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" UINTX_FORMAT,
 181                  signame, _id, _pc,
 182                  os::current_process_id(), os::current_thread_id());
 183   } else if (_filename != NULL && _lineno > 0) {
 184     // skip directory names
 185     char separator = os::file_separator()[0];
 186     const char *p = strrchr(_filename, separator);
 187     int n = jio_snprintf(buf, buflen,
 188                          "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT,
 189                          p ? p + 1 : _filename, _lineno,
 190                          os::current_process_id(), os::current_thread_id());
 191     if (n >= 0 && n < buflen && _message) {
 192       if (strlen(_detail_msg) > 0) {
 193         jio_snprintf(buf + n, buflen - n, "%s%s: %s",
 194         os::line_separator(), _message, _detail_msg);
 195       } else {
 196         jio_snprintf(buf + n, buflen - n, "%sError: %s",
 197                      os::line_separator(), _message);
 198       }
 199     }
 200   } else {
 201     jio_snprintf(buf, buflen,
 202                  "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT,
 203                  _id, os::current_process_id(), os::current_thread_id());
 204   }
 205 
 206   return buf;
 207 }
 208 
 209 void VMError::print_stack_trace(outputStream* st, JavaThread* jt,
 210                                 char* buf, int buflen, bool verbose) {
 211 #ifdef ZERO
 212   if (jt->zero_stack()->sp() && jt->top_zero_frame()) {
 213     // StackFrameStream uses the frame anchor, which may not have
 214     // been set up.  This can be done at any time in Zero, however,
 215     // so if it hasn't been set up then we just set it up now and
 216     // clear it again when we're done.
 217     bool has_last_Java_frame = jt->has_last_Java_frame();
 218     if (!has_last_Java_frame)
 219       jt->set_last_Java_frame();
 220     st->print("Java frames:");
 221     st->cr();
 222 
 223     // Print the frames
 224     StackFrameStream sfs(jt, true /* update */, true /* process_frames */);
 225     for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
 226       sfs.current()->zero_print_on_error(i, st, buf, buflen);
 227       st->cr();
 228     }
 229 
 230     // Reset the frame anchor if necessary
 231     if (!has_last_Java_frame)
 232       jt->reset_last_Java_frame();
 233   }
 234 #else
 235   if (jt->has_last_Java_frame()) {
 236     st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
 237     for (StackFrameStream sfs(jt, true /* update */, true /* process_frames */); !sfs.is_done(); sfs.next()) {
 238       sfs.current()->print_on_error(st, buf, buflen, verbose);
 239       st->cr();
 240     }
 241   }
 242 #endif // ZERO
 243 }
 244 
 245 /**
 246  * Adds `value` to `list` iff it's not already present and there is sufficient
 247  * capacity (i.e. length(list) < `list_capacity`). The length of the list
 248  * is the index of the first nullptr entry or `list_capacity` if there are
 249  * no nullptr entries.
 250  *
 251  * @ return true if the value was added, false otherwise
 252  */
 253 static bool add_if_absent(address value, address* list, int list_capacity) {
 254   for (int i = 0; i < list_capacity; i++) {
 255     if (list[i] == value) {
 256       return false;
 257     }
 258     if (list[i] == nullptr) {
 259       list[i] = value;
 260       if (i + 1 < list_capacity) {
 261         list[i + 1] = nullptr;
 262       }
 263       return true;
 264     }
 265   }
 266   return false;
 267 }
 268 
 269 /**
 270  * Prints the VM generated code unit, if any, containing `pc` if it has not already
 271  * been printed. If the code unit is an InterpreterCodelet or StubCodeDesc, it is
 272  * only printed if `is_crash_pc` is true.
 273  *
 274  * @param printed array of code units that have already been printed (delimited by NULL entry)
 275  * @param printed_capacity the capacity of `printed`
 276  * @return true if the code unit was printed, false otherwise
 277  */
 278 static bool print_code(outputStream* st, Thread* thread, address pc, bool is_crash_pc,
 279                        address* printed, int printed_capacity) {
 280   if (Interpreter::contains(pc)) {
 281     if (is_crash_pc) {
 282       // The interpreter CodeBlob is very large so try to print the codelet instead.
 283       InterpreterCodelet* codelet = Interpreter::codelet_containing(pc);
 284       if (codelet != nullptr) {
 285         if (add_if_absent((address) codelet, printed, printed_capacity)) {
 286           codelet->print_on(st);
 287           Disassembler::decode(codelet->code_begin(), codelet->code_end(), st);
 288           return true;
 289         }
 290       }
 291     }
 292   } else {
 293     StubCodeDesc* desc = StubCodeDesc::desc_for(pc);
 294     if (desc != nullptr) {
 295       if (is_crash_pc) {
 296         if (add_if_absent((address) desc, printed, printed_capacity)) {
 297           desc->print_on(st);
 298           Disassembler::decode(desc->begin(), desc->end(), st);
 299           return true;
 300         }
 301       }
 302     } else if (thread != nullptr) {
 303       CodeBlob* cb = CodeCache::find_blob(pc);
 304       if (cb != nullptr && add_if_absent((address) cb, printed, printed_capacity)) {
 305         // Disassembling nmethod will incur resource memory allocation,
 306         // only do so when thread is valid.
 307         ResourceMark rm(thread);
 308         Disassembler::decode(cb, st);
 309         st->cr();
 310         return true;
 311       }
 312     }
 313   }
 314   return false;
 315 }
 316 
 317 /**
 318  * Gets the caller frame of `fr`.
 319  *
 320  * @returns an invalid frame (i.e. fr.pc() === 0) if the caller cannot be obtained
 321  */
 322 static frame next_frame(frame fr, Thread* t) {
 323   // Compiled code may use EBP register on x86 so it looks like
 324   // non-walkable C frame. Use frame.sender() for java frames.
 325   frame invalid;
 326   if (t != nullptr && t->is_Java_thread()) {
 327     // Catch very first native frame by using stack address.
 328     // For JavaThread stack_base and stack_size should be set.
 329     if (!t->is_in_full_stack((address)(fr.real_fp() + 1))) {
 330       return invalid;
 331     }
 332     if (fr.is_java_frame() || fr.is_native_frame() || fr.is_runtime_frame()) {
 333       RegisterMap map(JavaThread::cast(t), false); // No update
 334       return fr.sender(&map);
 335     } else {
 336       // is_first_C_frame() does only simple checks for frame pointer,
 337       // it will pass if java compiled code has a pointer in EBP.
 338       if (os::is_first_C_frame(&fr)) return invalid;
 339       return os::get_sender_for_C_frame(&fr);
 340     }
 341   } else {
 342     if (os::is_first_C_frame(&fr)) return invalid;
 343     return os::get_sender_for_C_frame(&fr);
 344   }
 345 }
 346 
 347 void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) {
 348 
 349   // see if it's a valid frame
 350   if (fr.pc()) {
 351     st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)");
 352 
 353     int count = 0;
 354     while (count++ < StackPrintLimit) {
 355       fr.print_on_error(st, buf, buf_size);
 356       if (fr.pc()) { // print source file and line, if available
 357         char buf[128];
 358         int line_no;
 359         if (Decoder::get_source_info(fr.pc(), buf, sizeof(buf), &line_no)) {
 360           st->print("  (%s:%d)", buf, line_no);
 361         }
 362       }
 363       st->cr();
 364       fr = next_frame(fr, t);
 365       if (fr.pc() == nullptr) {
 366         break;
 367       }
 368     }
 369 
 370     if (count > StackPrintLimit) {
 371       st->print_cr("...<more frames>...");
 372     }
 373 
 374     st->cr();
 375   }
 376 }
 377 
 378 static void print_oom_reasons(outputStream* st) {
 379   st->print_cr("# Possible reasons:");
 380   st->print_cr("#   The system is out of physical RAM or swap space");
 381   if (UseCompressedOops) {
 382     st->print_cr("#   The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap");
 383   }
 384   if (LogBytesPerWord == 2) {
 385     st->print_cr("#   In 32 bit mode, the process size limit was hit");
 386   }
 387   st->print_cr("# Possible solutions:");
 388   st->print_cr("#   Reduce memory load on the system");
 389   st->print_cr("#   Increase physical memory or swap space");
 390   st->print_cr("#   Check if swap backing store is full");
 391   if (LogBytesPerWord == 2) {
 392     st->print_cr("#   Use 64 bit Java on a 64 bit OS");
 393   }
 394   st->print_cr("#   Decrease Java heap size (-Xmx/-Xms)");
 395   st->print_cr("#   Decrease number of Java threads");
 396   st->print_cr("#   Decrease Java thread stack sizes (-Xss)");
 397   st->print_cr("#   Set larger code cache with -XX:ReservedCodeCacheSize=");
 398   if (UseCompressedOops) {
 399     switch (CompressedOops::mode()) {
 400       case CompressedOops::UnscaledNarrowOop:
 401         st->print_cr("#   JVM is running with Unscaled Compressed Oops mode in which the Java heap is");
 402         st->print_cr("#     placed in the first 4GB address space. The Java Heap base address is the");
 403         st->print_cr("#     maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress");
 404         st->print_cr("#     to set the Java Heap base and to place the Java Heap above 4GB virtual address.");
 405         break;
 406       case CompressedOops::ZeroBasedNarrowOop:
 407         st->print_cr("#   JVM is running with Zero Based Compressed Oops mode in which the Java heap is");
 408         st->print_cr("#     placed in the first 32GB address space. The Java Heap base address is the");
 409         st->print_cr("#     maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress");
 410         st->print_cr("#     to set the Java Heap base and to place the Java Heap above 32GB virtual address.");
 411         break;
 412       default:
 413         break;
 414     }
 415   }
 416   st->print_cr("# This output file may be truncated or incomplete.");
 417 }
 418 
 419 static void report_vm_version(outputStream* st, char* buf, int buflen) {
 420    // VM version
 421    st->print_cr("#");
 422    JDK_Version::current().to_string(buf, buflen);
 423    const char* runtime_name = JDK_Version::runtime_name() != NULL ?
 424                                 JDK_Version::runtime_name() : "";
 425    const char* runtime_version = JDK_Version::runtime_version() != NULL ?
 426                                    JDK_Version::runtime_version() : "";
 427    const char* vendor_version = JDK_Version::runtime_vendor_version() != NULL ?
 428                                   JDK_Version::runtime_vendor_version() : "";
 429    const char* jdk_debug_level = VM_Version::printable_jdk_debug_level() != NULL ?
 430                                    VM_Version::printable_jdk_debug_level() : "";
 431 
 432    st->print_cr("# JRE version: %s%s%s (%s) (%sbuild %s)", runtime_name,
 433                 (*vendor_version != '\0') ? " " : "", vendor_version,
 434                 buf, jdk_debug_level, runtime_version);
 435 
 436    // This is the long version with some default settings added
 437    st->print_cr("# Java VM: %s%s%s (%s%s, %s%s%s%s%s%s, %s, %s)",
 438                  VM_Version::vm_name(),
 439                 (*vendor_version != '\0') ? " " : "", vendor_version,
 440                  jdk_debug_level,
 441                  VM_Version::vm_release(),
 442                  VM_Version::vm_info_string(),
 443                  TieredCompilation ? ", tiered" : "",
 444 #if INCLUDE_JVMCI
 445                  EnableJVMCI ? ", jvmci" : "",
 446                  UseJVMCICompiler ? ", jvmci compiler" : "",
 447 #else
 448                  "", "",
 449 #endif
 450                  UseCompressedOops ? ", compressed oops" : "",
 451                  UseCompressedClassPointers ? ", compressed class ptrs" : "",
 452                  GCConfig::hs_err_name(),
 453                  VM_Version::vm_platform_string()
 454                );
 455 }
 456 
 457 // Returns true if at least one thread reported a fatal error and fatal error handling is in process.
 458 bool VMError::is_error_reported() {
 459   return _first_error_tid != -1;
 460 }
 461 
 462 // Returns true if the current thread reported a fatal error.
 463 bool VMError::is_error_reported_in_current_thread() {
 464   return _first_error_tid == os::current_thread_id();
 465 }
 466 
 467 // Helper, return current timestamp for timeout handling.
 468 jlong VMError::get_current_timestamp() {
 469   return os::javaTimeNanos();
 470 }
 471 // Factor to translate the timestamp to seconds.
 472 #define TIMESTAMP_TO_SECONDS_FACTOR (1000 * 1000 * 1000)
 473 
 474 void VMError::record_reporting_start_time() {
 475   const jlong now = get_current_timestamp();
 476   Atomic::store(&_reporting_start_time, now);
 477 }
 478 
 479 jlong VMError::get_reporting_start_time() {
 480   return Atomic::load(&_reporting_start_time);
 481 }
 482 
 483 void VMError::record_step_start_time() {
 484   const jlong now = get_current_timestamp();
 485   Atomic::store(&_step_start_time, now);
 486 }
 487 
 488 jlong VMError::get_step_start_time() {
 489   return Atomic::load(&_step_start_time);
 490 }
 491 
 492 void VMError::clear_step_start_time() {
 493   return Atomic::store(&_step_start_time, (jlong)0);
 494 }
 495 
 496 // This is the main function to report a fatal error. Only one thread can
 497 // call this function, so we don't need to worry about MT-safety. But it's
 498 // possible that the error handler itself may crash or die on an internal
 499 // error, for example, when the stack/heap is badly damaged. We must be
 500 // able to handle recursive errors that happen inside error handler.
 501 //
 502 // Error reporting is done in several steps. If a crash or internal error
 503 // occurred when reporting an error, the nested signal/exception handler
 504 // can skip steps that are already (or partially) done. Error reporting will
 505 // continue from the next step. This allows us to retrieve and print
 506 // information that may be unsafe to get after a fatal error. If it happens,
 507 // you may find nested report_and_die() frames when you look at the stack
 508 // in a debugger.
 509 //
 510 // In general, a hang in error handler is much worse than a crash or internal
 511 // error, as it's harder to recover from a hang. Deadlock can happen if we
 512 // try to grab a lock that is already owned by current thread, or if the
 513 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
 514 // error handler and all the functions it called should avoid grabbing any
 515 // lock. An important thing to notice is that memory allocation needs a lock.
 516 //
 517 // We should avoid using large stack allocated buffers. Many errors happen
 518 // when stack space is already low. Making things even worse is that there
 519 // could be nested report_and_die() calls on stack (see above). Only one
 520 // thread can report error, so large buffers are statically allocated in data
 521 // segment.
 522 void VMError::report(outputStream* st, bool _verbose) {
 523 
 524 # define BEGIN if (_current_step == 0) { _current_step = __LINE__;
 525 # define STEP(s) } if (_current_step < __LINE__) { _current_step = __LINE__; _current_step_info = s; \
 526   record_step_start_time(); _step_did_timeout = false;
 527 # define END clear_step_start_time(); }
 528 
 529   // don't allocate large buffer on stack
 530   static char buf[O_BUFLEN];
 531 
 532   BEGIN
 533 
 534   STEP("printing fatal error message")
 535 
 536     st->print_cr("#");
 537     if (should_report_bug(_id)) {
 538       st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
 539     } else {
 540       st->print_cr("# There is insufficient memory for the Java "
 541                    "Runtime Environment to continue.");
 542     }
 543 
 544 #ifdef ASSERT
 545   // Error handler self tests
 546 
 547   // test secondary error handling. Test it twice, to test that resetting
 548   // error handler after a secondary crash works.
 549   STEP("test secondary crash 1")
 550     if (_verbose && TestCrashInErrorHandler != 0) {
 551       st->print_cr("Will crash now (TestCrashInErrorHandler=" UINTX_FORMAT ")...",
 552         TestCrashInErrorHandler);
 553       controlled_crash(TestCrashInErrorHandler);
 554     }
 555 
 556   STEP("test secondary crash 2")
 557     if (_verbose && TestCrashInErrorHandler != 0) {
 558       st->print_cr("Will crash now (TestCrashInErrorHandler=" UINTX_FORMAT ")...",
 559         TestCrashInErrorHandler);
 560       controlled_crash(TestCrashInErrorHandler);
 561     }
 562 
 563   // TestUnresponsiveErrorHandler: We want to test both step timeouts and global timeout.
 564   // Step to global timeout ratio is 4:1, so in order to be absolutely sure we hit the
 565   // global timeout, let's execute the timeout step five times.
 566   // See corresponding test in test/runtime/ErrorHandling/TimeoutInErrorHandlingTest.java
 567   STEP("setup for test unresponsive error reporting step")
 568     if (_verbose && TestUnresponsiveErrorHandler) {
 569       // We record reporting_start_time for this test here because we
 570       // care about the time spent executing TIMEOUT_TEST_STEP and not
 571       // about the time it took us to get here.
 572       tty->print_cr("Recording reporting_start_time for TestUnresponsiveErrorHandler.");
 573       record_reporting_start_time();
 574     }
 575 
 576   #define TIMEOUT_TEST_STEP STEP("test unresponsive error reporting step") \
 577     if (_verbose && TestUnresponsiveErrorHandler) { os::infinite_sleep(); }
 578   TIMEOUT_TEST_STEP
 579   TIMEOUT_TEST_STEP
 580   TIMEOUT_TEST_STEP
 581   TIMEOUT_TEST_STEP
 582   TIMEOUT_TEST_STEP
 583 
 584   STEP("test safefetch in error handler")
 585     // test whether it is safe to use SafeFetch32 in Crash Handler. Test twice
 586     // to test that resetting the signal handler works correctly.
 587     if (_verbose && TestSafeFetchInErrorHandler) {
 588       st->print_cr("Will test SafeFetch...");
 589       if (CanUseSafeFetch32()) {
 590         int* const invalid_pointer = (int*)segfault_address;
 591         const int x = 0x76543210;
 592         int i1 = SafeFetch32(invalid_pointer, x);
 593         int i2 = SafeFetch32(invalid_pointer, x);
 594         if (i1 == x && i2 == x) {
 595           st->print_cr("SafeFetch OK."); // Correctly deflected and returned default pattern
 596         } else {
 597           st->print_cr("??");
 598         }
 599       } else {
 600         st->print_cr("not possible; skipped.");
 601       }
 602     }
 603 #endif // ASSERT
 604 
 605   STEP("printing type of error")
 606 
 607      switch(static_cast<unsigned int>(_id)) {
 608        case OOM_MALLOC_ERROR:
 609        case OOM_MMAP_ERROR:
 610        case OOM_MPROTECT_ERROR:
 611          if (_size) {
 612            st->print("# Native memory allocation ");
 613            st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
 614                      (_id == (int)OOM_MMAP_ERROR)   ? "(mmap) failed to map " :
 615                                                       "(mprotect) failed to protect ");
 616            jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
 617            st->print("%s", buf);
 618            st->print(" bytes");
 619            if (strlen(_detail_msg) > 0) {
 620              st->print(" for ");
 621              st->print("%s", _detail_msg);
 622            }
 623            st->cr();
 624          } else {
 625            if (strlen(_detail_msg) > 0) {
 626              st->print("# ");
 627              st->print_cr("%s", _detail_msg);
 628            }
 629          }
 630          // In error file give some solutions
 631          if (_verbose) {
 632            print_oom_reasons(st);
 633          } else {
 634            return;  // that's enough for the screen
 635          }
 636          break;
 637        case INTERNAL_ERROR:
 638        default:
 639          break;
 640      }
 641 
 642   STEP("printing exception/signal name")
 643 
 644      st->print_cr("#");
 645      st->print("#  ");
 646      // Is it an OS exception/signal?
 647      if (os::exception_name(_id, buf, sizeof(buf))) {
 648        st->print("%s", buf);
 649        st->print(" (0x%x)", _id);                // signal number
 650        st->print(" at pc=" PTR_FORMAT, p2i(_pc));
 651        if (_siginfo != NULL && os::signal_sent_by_kill(_siginfo)) {
 652          st->print(" (sent by kill)");
 653        }
 654      } else {
 655        if (should_report_bug(_id)) {
 656          st->print("Internal Error");
 657        } else {
 658          st->print("Out of Memory Error");
 659        }
 660        if (_filename != NULL && _lineno > 0) {
 661 #ifdef PRODUCT
 662          // In product mode chop off pathname?
 663          char separator = os::file_separator()[0];
 664          const char *p = strrchr(_filename, separator);
 665          const char *file = p ? p+1 : _filename;
 666 #else
 667          const char *file = _filename;
 668 #endif
 669          st->print(" (%s:%d)", file, _lineno);
 670        } else {
 671          st->print(" (0x%x)", _id);
 672        }
 673      }
 674 
 675   STEP("printing current thread and pid")
 676 
 677      // process id, thread id
 678      st->print(", pid=%d", os::current_process_id());
 679      st->print(", tid=" UINTX_FORMAT, os::current_thread_id());
 680      st->cr();
 681 
 682   STEP("printing error message")
 683 
 684      if (should_report_bug(_id)) {  // already printed the message.
 685        // error message
 686        if (strlen(_detail_msg) > 0) {
 687          st->print_cr("#  %s: %s", _message ? _message : "Error", _detail_msg);
 688        } else if (_message) {
 689          st->print_cr("#  Error: %s", _message);
 690        }
 691      }
 692 
 693   STEP("printing Java version string")
 694 
 695      report_vm_version(st, buf, sizeof(buf));
 696 
 697   STEP("printing problematic frame")
 698 
 699      // Print current frame if we have a context (i.e. it's a crash)
 700      if (_context) {
 701        st->print_cr("# Problematic frame:");
 702        st->print("# ");
 703        frame fr = os::fetch_frame_from_context(_context);
 704        fr.print_on_error(st, buf, sizeof(buf));
 705        st->cr();
 706        st->print_cr("#");
 707      }
 708 
 709   STEP("printing core file information")
 710     st->print("# ");
 711     if (CreateCoredumpOnCrash) {
 712       if (coredump_status) {
 713         st->print("Core dump will be written. Default location: %s", coredump_message);
 714       } else {
 715         st->print("No core dump will be written. %s", coredump_message);
 716       }
 717     } else {
 718       st->print("CreateCoredumpOnCrash turned off, no core file dumped");
 719     }
 720     st->cr();
 721     st->print_cr("#");
 722 
 723   JFR_ONLY(STEP("printing jfr information"))
 724   JFR_ONLY(Jfr::on_vm_error_report(st);)
 725 
 726   STEP("printing bug submit message")
 727 
 728      if (should_submit_bug_report(_id) && _verbose) {
 729        print_bug_submit_message(st, _thread);
 730      }
 731 
 732   STEP("printing summary")
 733 
 734      if (_verbose) {
 735        st->cr();
 736        st->print_cr("---------------  S U M M A R Y ------------");
 737        st->cr();
 738      }
 739 
 740   STEP("printing VM option summary")
 741 
 742      if (_verbose) {
 743        // VM options
 744        Arguments::print_summary_on(st);
 745        st->cr();
 746      }
 747 
 748   STEP("printing summary machine and OS info")
 749 
 750      if (_verbose) {
 751        os::print_summary_info(st, buf, sizeof(buf));
 752      }
 753 
 754   STEP("printing date and time")
 755 
 756      if (_verbose) {
 757        os::print_date_and_time(st, buf, sizeof(buf));
 758      }
 759 
 760   STEP("printing thread")
 761 
 762      if (_verbose) {
 763        st->cr();
 764        st->print_cr("---------------  T H R E A D  ---------------");
 765        st->cr();
 766      }
 767 
 768   STEP("printing current thread")
 769 
 770      // current thread
 771      if (_verbose) {
 772        if (_thread) {
 773          st->print("Current thread (" PTR_FORMAT "):  ", p2i(_thread));
 774          _thread->print_on_error(st, buf, sizeof(buf));
 775          st->cr();
 776        } else {
 777          st->print_cr("Current thread is native thread");
 778        }
 779        st->cr();
 780      }
 781 
 782   STEP("printing current compile task")
 783 
 784      if (_verbose && _thread && _thread->is_Compiler_thread()) {
 785         CompilerThread* t = (CompilerThread*)_thread;
 786         if (t->task()) {
 787            st->cr();
 788            st->print_cr("Current CompileTask:");
 789            t->task()->print_line_on_error(st, buf, sizeof(buf));
 790            st->cr();
 791         }
 792      }
 793 
 794   STEP("printing stack bounds")
 795 
 796      if (_verbose) {
 797        st->print("Stack: ");
 798 
 799        address stack_top;
 800        size_t stack_size;
 801 
 802        if (_thread) {
 803           stack_top = _thread->stack_base();
 804           stack_size = _thread->stack_size();
 805        } else {
 806           stack_top = os::current_stack_base();
 807           stack_size = os::current_stack_size();
 808        }
 809 
 810        address stack_bottom = stack_top - stack_size;
 811        st->print("[" PTR_FORMAT "," PTR_FORMAT "]", p2i(stack_bottom), p2i(stack_top));
 812 
 813        frame fr = _context ? os::fetch_frame_from_context(_context)
 814                            : os::current_frame();
 815 
 816        if (fr.sp()) {
 817          st->print(",  sp=" PTR_FORMAT, p2i(fr.sp()));
 818          size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024);
 819          st->print(",  free space=" SIZE_FORMAT "k", free_stack_size);
 820        }
 821 
 822        st->cr();
 823      }
 824 
 825   STEP("printing native stack")
 826 
 827    if (_verbose) {
 828      if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) {
 829        // We have printed the native stack in platform-specific code
 830        // Windows/x64 needs special handling.
 831      } else {
 832        frame fr = _context ? os::fetch_frame_from_context(_context)
 833                            : os::current_frame();
 834 
 835        print_native_stack(st, fr, _thread, buf, sizeof(buf));
 836        _print_native_stack_used = true;
 837      }
 838    }
 839 
 840   STEP("printing Java stack")
 841 
 842      if (_verbose && _thread && _thread->is_Java_thread()) {
 843        print_stack_trace(st, JavaThread::cast(_thread), buf, sizeof(buf));
 844      }
 845 
 846   STEP("printing target Java thread stack")
 847 
 848      // printing Java thread stack trace if it is involved in GC crash
 849      if (_verbose && _thread && (_thread->is_Named_thread())) {
 850        Thread* thread = ((NamedThread *)_thread)->processed_thread();
 851        if (thread != NULL && thread->is_Java_thread()) {
 852          JavaThread* jt = JavaThread::cast(thread);
 853          st->print_cr("JavaThread " PTR_FORMAT " (nid = %d) was being processed", p2i(jt), jt->osthread()->thread_id());
 854          print_stack_trace(st, jt, buf, sizeof(buf), true);
 855        }
 856      }
 857 
 858   STEP("printing siginfo")
 859 
 860      // signal no, signal code, address that caused the fault
 861      if (_verbose && _siginfo) {
 862        st->cr();
 863        os::print_siginfo(st, _siginfo);
 864        st->cr();
 865      }
 866 
 867   STEP("CDS archive access warning")
 868 
 869      // Print an explicit hint if we crashed on access to the CDS archive.
 870      if (_verbose && _siginfo) {
 871        check_failing_cds_access(st, _siginfo);
 872        st->cr();
 873      }
 874 
 875   STEP("printing register info")
 876 
 877      // decode register contents if possible
 878      if (_verbose && _context && _thread && Universe::is_fully_initialized()) {
 879        ResourceMark rm(_thread);
 880        os::print_register_info(st, _context);
 881        st->cr();
 882      }
 883 
 884   STEP("printing registers, top of stack, instructions near pc")
 885 
 886      // registers, top of stack, instructions near pc
 887      if (_verbose && _context) {
 888        os::print_context(st, _context);
 889        st->cr();
 890      }
 891 
 892   STEP("inspecting top of stack")
 893 
 894      // decode stack contents if possible
 895      if (_verbose && _context && _thread && Universe::is_fully_initialized()) {
 896        frame fr = os::fetch_frame_from_context(_context);
 897        const int slots = 8;
 898        const intptr_t *start = fr.sp();
 899        const intptr_t *end = start + slots;
 900        if (is_aligned(start, sizeof(intptr_t)) && os::is_readable_range(start, end)) {
 901          st->print_cr("Stack slot to memory mapping:");
 902          for (int i = 0; i < slots; ++i) {
 903            st->print("stack at sp + %d slots: ", i);
 904            ResourceMark rm(_thread);
 905            os::print_location(st, *(start + i));
 906          }
 907        }
 908        st->cr();
 909      }
 910 
 911   STEP("printing code blobs if possible")
 912 
 913      if (_verbose && _context) {
 914        const int printed_capacity = max_error_log_print_code;
 915        address printed[printed_capacity];
 916        printed[0] = nullptr;
 917        int printed_len = 0;
 918        // Even though ErrorLogPrintCodeLimit is ranged checked
 919        // during argument parsing, there's no way to prevent it
 920        // subsequently (i.e., after parsing) being set to a
 921        // value outside the range.
 922        int limit = MIN2(ErrorLogPrintCodeLimit, printed_capacity);
 923        if (limit > 0) {
 924          // Scan the native stack
 925          if (!_print_native_stack_used) {
 926            // Only try to print code of the crashing frame since
 927            // the native stack cannot be walked with next_frame.
 928            if (print_code(st, _thread, _pc, true, printed, printed_capacity)) {
 929              printed_len++;
 930            }
 931          } else {
 932            frame fr = os::fetch_frame_from_context(_context);
 933            while (printed_len < limit && fr.pc() != nullptr) {
 934              if (print_code(st, _thread, fr.pc(), fr.pc() == _pc, printed, printed_capacity)) {
 935                printed_len++;
 936              }
 937              fr = next_frame(fr, _thread);
 938            }
 939          }
 940 
 941          // Scan the Java stack
 942          if (_thread != nullptr && _thread->is_Java_thread()) {
 943            JavaThread* jt = JavaThread::cast(_thread);
 944            if (jt->has_last_Java_frame()) {
 945              for (StackFrameStream sfs(jt, true /* update */, true /* process_frames */); printed_len < limit && !sfs.is_done(); sfs.next()) {
 946                address pc = sfs.current()->pc();
 947                if (print_code(st, _thread, pc, pc == _pc, printed, printed_capacity)) {
 948                  printed_len++;
 949                }
 950              }
 951            }
 952          }
 953        }
 954      }
 955 
 956   STEP("printing VM operation")
 957 
 958      if (_verbose && _thread && _thread->is_VM_thread()) {
 959         VMThread* t = (VMThread*)_thread;
 960         VM_Operation* op = t->vm_operation();
 961         if (op) {
 962           op->print_on_error(st);
 963           st->cr();
 964           st->cr();
 965         }
 966      }
 967 
 968   STEP("printing process")
 969 
 970      if (_verbose) {
 971        st->cr();
 972        st->print_cr("---------------  P R O C E S S  ---------------");
 973        st->cr();
 974      }
 975 
 976 #ifndef _WIN32
 977   STEP("printing user info")
 978 
 979      if (ExtensiveErrorReports && _verbose) {
 980        os::Posix::print_user_info(st);
 981      }
 982 #endif
 983 
 984   STEP("printing all threads")
 985 
 986      // all threads
 987      if (_verbose && _thread) {
 988        Threads::print_on_error(st, _thread, buf, sizeof(buf));
 989        st->cr();
 990      }
 991 
 992   STEP("printing VM state")
 993 
 994      if (_verbose) {
 995        // Safepoint state
 996        st->print("VM state: ");
 997 
 998        if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing");
 999        else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint");
1000        else st->print("not at safepoint");
1001 
1002        // Also see if error occurred during initialization or shutdown
1003        if (!Universe::is_fully_initialized()) {
1004          st->print(" (not fully initialized)");
1005        } else if (VM_Exit::vm_exited()) {
1006          st->print(" (shutting down)");
1007        } else {
1008          st->print(" (normal execution)");
1009        }
1010        st->cr();
1011        st->cr();
1012      }
1013 
1014   STEP("printing owned locks on error")
1015 
1016      // mutexes/monitors that currently have an owner
1017      if (_verbose) {
1018        print_owned_locks_on_error(st);
1019        st->cr();
1020      }
1021 
1022   STEP("printing number of OutOfMemoryError and StackOverflow exceptions")
1023 
1024      if (_verbose && Exceptions::has_exception_counts()) {
1025        st->print_cr("OutOfMemory and StackOverflow Exception counts:");
1026        Exceptions::print_exception_counts_on_error(st);
1027        st->cr();
1028      }
1029 
1030 #ifdef _LP64
1031   STEP("printing compressed oops mode")
1032 
1033      if (_verbose && UseCompressedOops) {
1034        CompressedOops::print_mode(st);
1035        st->cr();
1036      }
1037 
1038   STEP("printing compressed klass pointers mode")
1039 
1040      if (_verbose && UseCompressedClassPointers) {
1041        CDS_ONLY(MetaspaceShared::print_on(st);)
1042        Metaspace::print_compressed_class_space(st);
1043        CompressedKlassPointers::print_mode(st);
1044        st->cr();
1045      }
1046 #endif
1047 
1048   STEP("printing heap information")
1049 
1050      if (_verbose) {
1051        GCLogPrecious::print_on_error(st);
1052 
1053        if (Universe::heap() != NULL) {
1054          Universe::heap()->print_on_error(st);
1055          st->cr();
1056        }
1057 
1058        if (Universe::is_fully_initialized()) {
1059          st->print_cr("Polling page: " INTPTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));
1060          st->cr();
1061        }
1062      }
1063 
1064   STEP("printing metaspace information")
1065 
1066      if (_verbose && Universe::is_fully_initialized()) {
1067        st->print_cr("Metaspace:");
1068        MetaspaceUtils::print_basic_report(st, 0);
1069      }
1070 
1071   STEP("printing code cache information")
1072 
1073      if (_verbose && Universe::is_fully_initialized()) {
1074        // print code cache information before vm abort
1075        CodeCache::print_summary(st);
1076        st->cr();
1077      }
1078 
1079   STEP("printing ring buffers")
1080 
1081      if (_verbose) {
1082        Events::print_all(st);
1083        st->cr();
1084      }
1085 
1086   STEP("printing dynamic libraries")
1087 
1088      if (_verbose) {
1089        // dynamic libraries, or memory map
1090        os::print_dll_info(st);
1091        st->cr();
1092      }
1093 
1094   STEP("printing native decoder state")
1095 
1096      if (_verbose) {
1097        Decoder::print_state_on(st);
1098        st->cr();
1099      }
1100 
1101   STEP("printing VM options")
1102 
1103      if (_verbose) {
1104        // VM options
1105        Arguments::print_on(st);
1106        st->cr();
1107      }
1108 
1109   STEP("printing flags")
1110 
1111     if (_verbose) {
1112       JVMFlag::printFlags(
1113         st,
1114         true, // with comments
1115         false, // no ranges
1116         true); // skip defaults
1117       st->cr();
1118     }
1119 
1120   STEP("printing warning if internal testing API used")
1121 
1122      if (WhiteBox::used()) {
1123        st->print_cr("Unsupported internal testing APIs have been used.");
1124        st->cr();
1125      }
1126 
1127   STEP("printing log configuration")
1128     if (_verbose){
1129       st->print_cr("Logging:");
1130       LogConfiguration::describe_current_configuration(st);
1131       st->cr();
1132     }
1133 
1134   STEP("printing all environment variables")
1135 
1136      if (_verbose) {
1137        os::print_environment_variables(st, env_list);
1138        st->cr();
1139      }
1140 
1141   STEP("printing signal handlers")
1142 
1143      if (_verbose) {
1144        os::print_signal_handlers(st, buf, sizeof(buf));
1145        st->cr();
1146      }
1147 
1148   STEP("Native Memory Tracking")
1149      if (_verbose) {
1150        MemTracker::error_report(st);
1151      }
1152 
1153   STEP("printing system")
1154 
1155      if (_verbose) {
1156        st->cr();
1157        st->print_cr("---------------  S Y S T E M  ---------------");
1158        st->cr();
1159      }
1160 
1161   STEP("printing OS information")
1162 
1163      if (_verbose) {
1164        os::print_os_info(st);
1165        st->cr();
1166      }
1167 
1168   STEP("printing CPU info")
1169      if (_verbose) {
1170        os::print_cpu_info(st, buf, sizeof(buf));
1171        st->cr();
1172      }
1173 
1174   STEP("printing memory info")
1175 
1176      if (_verbose) {
1177        os::print_memory_info(st);
1178        st->cr();
1179      }
1180 
1181   STEP("printing internal vm info")
1182 
1183      if (_verbose) {
1184        st->print_cr("vm_info: %s", VM_Version::internal_vm_info_string());
1185        st->cr();
1186      }
1187 
1188   // print a defined marker to show that error handling finished correctly.
1189   STEP("printing end marker")
1190 
1191      if (_verbose) {
1192        st->print_cr("END.");
1193      }
1194 
1195   END
1196 
1197 # undef BEGIN
1198 # undef STEP
1199 # undef END
1200 }
1201 
1202 // Report for the vm_info_cmd. This prints out the information above omitting
1203 // crash and thread specific information.  If output is added above, it should be added
1204 // here also, if it is safe to call during a running process.
1205 void VMError::print_vm_info(outputStream* st) {
1206 
1207   char buf[O_BUFLEN];
1208   report_vm_version(st, buf, sizeof(buf));
1209 
1210   // STEP("printing summary")
1211 
1212   st->cr();
1213   st->print_cr("---------------  S U M M A R Y ------------");
1214   st->cr();
1215 
1216   // STEP("printing VM option summary")
1217 
1218   // VM options
1219   Arguments::print_summary_on(st);
1220   st->cr();
1221 
1222   // STEP("printing summary machine and OS info")
1223 
1224   os::print_summary_info(st, buf, sizeof(buf));
1225 
1226   // STEP("printing date and time")
1227 
1228   os::print_date_and_time(st, buf, sizeof(buf));
1229 
1230   // Skip: STEP("printing thread")
1231 
1232   // STEP("printing process")
1233 
1234   st->cr();
1235   st->print_cr("---------------  P R O C E S S  ---------------");
1236   st->cr();
1237 
1238   // STEP("printing number of OutOfMemoryError and StackOverflow exceptions")
1239 
1240   if (Exceptions::has_exception_counts()) {
1241     st->print_cr("OutOfMemory and StackOverflow Exception counts:");
1242     Exceptions::print_exception_counts_on_error(st);
1243     st->cr();
1244   }
1245 
1246 #ifdef _LP64
1247   // STEP("printing compressed oops mode")
1248   if (UseCompressedOops) {
1249     CompressedOops::print_mode(st);
1250     st->cr();
1251   }
1252 
1253   // STEP("printing compressed class ptrs mode")
1254   if (UseCompressedClassPointers) {
1255     CDS_ONLY(MetaspaceShared::print_on(st);)
1256     Metaspace::print_compressed_class_space(st);
1257     CompressedKlassPointers::print_mode(st);
1258     st->cr();
1259   }
1260 #endif
1261 
1262   // STEP("printing heap information")
1263 
1264   if (Universe::is_fully_initialized()) {
1265     MutexLocker hl(Heap_lock);
1266     GCLogPrecious::print_on_error(st);
1267     Universe::heap()->print_on_error(st);
1268     st->cr();
1269     st->print_cr("Polling page: " INTPTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));
1270     st->cr();
1271   }
1272 
1273   // STEP("printing metaspace information")
1274 
1275   if (Universe::is_fully_initialized()) {
1276     st->print_cr("Metaspace:");
1277     MetaspaceUtils::print_basic_report(st, 0);
1278   }
1279 
1280   // STEP("printing code cache information")
1281 
1282   if (Universe::is_fully_initialized()) {
1283     // print code cache information before vm abort
1284     CodeCache::print_summary(st);
1285     st->cr();
1286   }
1287 
1288   // STEP("printing ring buffers")
1289 
1290   Events::print_all(st);
1291   st->cr();
1292 
1293   // STEP("printing dynamic libraries")
1294 
1295   // dynamic libraries, or memory map
1296   os::print_dll_info(st);
1297   st->cr();
1298 
1299   // STEP("printing VM options")
1300 
1301   // VM options
1302   Arguments::print_on(st);
1303   st->cr();
1304 
1305   // STEP("printing warning if internal testing API used")
1306 
1307   if (WhiteBox::used()) {
1308     st->print_cr("Unsupported internal testing APIs have been used.");
1309     st->cr();
1310   }
1311 
1312   // STEP("printing log configuration")
1313   st->print_cr("Logging:");
1314   LogConfiguration::describe(st);
1315   st->cr();
1316 
1317   // STEP("printing all environment variables")
1318 
1319   os::print_environment_variables(st, env_list);
1320   st->cr();
1321 
1322   // STEP("printing signal handlers")
1323 
1324   os::print_signal_handlers(st, buf, sizeof(buf));
1325   st->cr();
1326 
1327   // STEP("Native Memory Tracking")
1328 
1329   MemTracker::error_report(st);
1330 
1331   // STEP("printing system")
1332 
1333   st->cr();
1334   st->print_cr("---------------  S Y S T E M  ---------------");
1335   st->cr();
1336 
1337   // STEP("printing OS information")
1338 
1339   os::print_os_info(st);
1340   st->cr();
1341 
1342   // STEP("printing CPU info")
1343 
1344   os::print_cpu_info(st, buf, sizeof(buf));
1345   st->cr();
1346 
1347   // STEP("printing memory info")
1348 
1349   os::print_memory_info(st);
1350   st->cr();
1351 
1352   // STEP("printing internal vm info")
1353 
1354   st->print_cr("vm_info: %s", VM_Version::internal_vm_info_string());
1355   st->cr();
1356 
1357   // print a defined marker to show that error handling finished correctly.
1358   // STEP("printing end marker")
1359 
1360   st->print_cr("END.");
1361 }
1362 
1363 /** Expand a pattern into a buffer starting at pos and open a file using constructed path */
1364 static int expand_and_open(const char* pattern, bool overwrite_existing, char* buf, size_t buflen, size_t pos) {
1365   int fd = -1;
1366   int mode = O_RDWR | O_CREAT;
1367   if (overwrite_existing) {
1368     mode |= O_TRUNC;
1369   } else {
1370     mode |= O_EXCL;
1371   }
1372   if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) {
1373     fd = open(buf, mode, 0666);
1374   }
1375   return fd;
1376 }
1377 
1378 /**
1379  * Construct file name for a log file and return it's file descriptor.
1380  * Name and location depends on pattern, default_pattern params and access
1381  * permissions.
1382  */
1383 int VMError::prepare_log_file(const char* pattern, const char* default_pattern, bool overwrite_existing, char* buf, size_t buflen) {
1384   int fd = -1;
1385 
1386   // If possible, use specified pattern to construct log file name
1387   if (pattern != NULL) {
1388     fd = expand_and_open(pattern, overwrite_existing, buf, buflen, 0);
1389   }
1390 
1391   // Either user didn't specify, or the user's location failed,
1392   // so use the default name in the current directory
1393   if (fd == -1) {
1394     const char* cwd = os::get_current_directory(buf, buflen);
1395     if (cwd != NULL) {
1396       size_t pos = strlen(cwd);
1397       int fsep_len = jio_snprintf(&buf[pos], buflen-pos, "%s", os::file_separator());
1398       pos += fsep_len;
1399       if (fsep_len > 0) {
1400         fd = expand_and_open(default_pattern, overwrite_existing, buf, buflen, pos);
1401       }
1402     }
1403   }
1404 
1405    // try temp directory if it exists.
1406    if (fd == -1) {
1407      const char* tmpdir = os::get_temp_directory();
1408      if (tmpdir != NULL && strlen(tmpdir) > 0) {
1409        int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator());
1410        if (pos > 0) {
1411          fd = expand_and_open(default_pattern, overwrite_existing, buf, buflen, pos);
1412        }
1413      }
1414    }
1415 
1416   return fd;
1417 }
1418 
1419 void VMError::report_and_die(Thread* thread, unsigned int sig, address pc, void* siginfo,
1420                              void* context, const char* detail_fmt, ...)
1421 {
1422   va_list detail_args;
1423   va_start(detail_args, detail_fmt);
1424   report_and_die(sig, NULL, detail_fmt, detail_args, thread, pc, siginfo, context, NULL, 0, 0);
1425   va_end(detail_args);
1426 }
1427 
1428 void VMError::report_and_die(Thread* thread, unsigned int sig, address pc, void* siginfo, void* context)
1429 {
1430   report_and_die(thread, sig, pc, siginfo, context, "%s", "");
1431 }
1432 
1433 void VMError::report_and_die(Thread* thread, void* context, const char* filename, int lineno, const char* message,
1434                              const char* detail_fmt, va_list detail_args)
1435 {
1436   report_and_die(INTERNAL_ERROR, message, detail_fmt, detail_args, thread, NULL, NULL, context, filename, lineno, 0);
1437 }
1438 
1439 void VMError::report_and_die(Thread* thread, const char* filename, int lineno, size_t size,
1440                              VMErrorType vm_err_type, const char* detail_fmt, va_list detail_args) {
1441   report_and_die(vm_err_type, NULL, detail_fmt, detail_args, thread, NULL, NULL, NULL, filename, lineno, size);
1442 }
1443 
1444 void VMError::report_and_die(int id, const char* message, const char* detail_fmt, va_list detail_args,
1445                              Thread* thread, address pc, void* siginfo, void* context, const char* filename,
1446                              int lineno, size_t size)
1447 {
1448   // A single scratch buffer to be used from here on.
1449   // Do not rely on it being preserved across function calls.
1450   static char buffer[O_BUFLEN];
1451 
1452   // File descriptor to tty to print an error summary to.
1453   // Hard wired to stdout; see JDK-8215004 (compatibility concerns).
1454   static const int fd_out = 1; // stdout
1455 
1456   // File descriptor to the error log file.
1457   static int fd_log = -1;
1458 
1459 #ifdef CAN_SHOW_REGISTERS_ON_ASSERT
1460   // Disarm assertion poison page, since from this point on we do not need this mechanism anymore and it may
1461   // cause problems in error handling during native OOM, see JDK-8227275.
1462   disarm_assert_poison();
1463 #endif
1464 
1465   // Use local fdStream objects only. Do not use global instances whose initialization
1466   // relies on dynamic initialization (see JDK-8214975). Do not rely on these instances
1467   // to carry over into recursions or invocations from other threads.
1468   fdStream out(fd_out);
1469   out.set_scratch_buffer(buffer, sizeof(buffer));
1470 
1471   // Depending on the re-entrance depth at this point, fd_log may be -1 or point to an open hs-err file.
1472   fdStream log(fd_log);
1473   log.set_scratch_buffer(buffer, sizeof(buffer));
1474 
1475   // How many errors occurred in error handler when reporting first_error.
1476   static int recursive_error_count;
1477 
1478   // We will first print a brief message to standard out (verbose = false),
1479   // then save detailed information in log file (verbose = true).
1480   static bool out_done = false;         // done printing to standard out
1481   static bool log_done = false;         // done saving error log
1482 
1483   intptr_t mytid = os::current_thread_id();
1484   if (_first_error_tid == -1 &&
1485       Atomic::cmpxchg(&_first_error_tid, (intptr_t)-1, mytid) == -1) {
1486 
1487     if (SuppressFatalErrorMessage) {
1488       os::abort(CreateCoredumpOnCrash);
1489     }
1490 
1491     // Initialize time stamps to use the same base.
1492     out.time_stamp().update_to(1);
1493     log.time_stamp().update_to(1);
1494 
1495     _id = id;
1496     _message = message;
1497     _thread = thread;
1498     _pc = pc;
1499     _siginfo = siginfo;
1500     _context = context;
1501     _filename = filename;
1502     _lineno = lineno;
1503     _size = size;
1504     jio_vsnprintf(_detail_msg, sizeof(_detail_msg), detail_fmt, detail_args);
1505 
1506     reporting_started();
1507     if (!TestUnresponsiveErrorHandler) {
1508       // Record reporting_start_time unless we're running the
1509       // TestUnresponsiveErrorHandler test. For that test we record
1510       // reporting_start_time at the beginning of the test.
1511       record_reporting_start_time();
1512     } else {
1513       out.print_raw_cr("Delaying recording reporting_start_time for TestUnresponsiveErrorHandler.");
1514     }
1515 
1516     if (ShowMessageBoxOnError || PauseAtExit) {
1517       show_message_box(buffer, sizeof(buffer));
1518 
1519       // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
1520       // WatcherThread can kill JVM if the error handler hangs.
1521       ShowMessageBoxOnError = false;
1522     }
1523 
1524     os::check_dump_limit(buffer, sizeof(buffer));
1525 
1526     // reset signal handlers or exception filter; make sure recursive crashes
1527     // are handled properly.
1528     install_secondary_signal_handler();
1529   } else {
1530 #if defined(_WINDOWS)
1531     // If UseOSErrorReporting we call this for each level of the call stack
1532     // while searching for the exception handler.  Only the first level needs
1533     // to be reported.
1534     if (UseOSErrorReporting && log_done) return;
1535 #endif
1536 
1537     // This is not the first error, see if it happened in a different thread
1538     // or in the same thread during error reporting.
1539     if (_first_error_tid != mytid) {
1540       if (!SuppressFatalErrorMessage) {
1541         char msgbuf[64];
1542         jio_snprintf(msgbuf, sizeof(msgbuf),
1543                      "[thread " INTX_FORMAT " also had an error]",
1544                      mytid);
1545         out.print_raw_cr(msgbuf);
1546       }
1547 
1548       // Error reporting is not MT-safe, nor can we let the current thread
1549       // proceed, so we block it.
1550       os::infinite_sleep();
1551 
1552     } else {
1553       if (recursive_error_count++ > 30) {
1554         if (!SuppressFatalErrorMessage) {
1555           out.print_raw_cr("[Too many errors, abort]");
1556         }
1557         os::die();
1558       }
1559 
1560       if (SuppressFatalErrorMessage) {
1561         // If we already hit a secondary error during abort, then calling
1562         // it again is likely to hit another one. But eventually, if we
1563         // don't deadlock somewhere, we will call os::die() above.
1564         os::abort(CreateCoredumpOnCrash);
1565       }
1566 
1567       outputStream* const st = log.is_open() ? &log : &out;
1568       st->cr();
1569 
1570       // Timeout handling.
1571       if (_step_did_timeout) {
1572         // The current step had a timeout. Lets continue reporting with the next step.
1573         st->print_raw("[timeout occurred during error reporting in step \"");
1574         st->print_raw(_current_step_info);
1575         st->print_cr("\"] after " INT64_FORMAT " s.",
1576                      (int64_t)
1577                      ((get_current_timestamp() - _step_start_time) / TIMESTAMP_TO_SECONDS_FACTOR));
1578       } else if (_reporting_did_timeout) {
1579         // We hit ErrorLogTimeout. Reporting will stop altogether. Let's wrap things
1580         // up, the process is about to be stopped by the WatcherThread.
1581         st->print_cr("------ Timeout during error reporting after " INT64_FORMAT " s. ------",
1582                      (int64_t)
1583                      ((get_current_timestamp() - _reporting_start_time) / TIMESTAMP_TO_SECONDS_FACTOR));
1584         st->flush();
1585         // Watcherthread is about to call os::die. Lets just wait.
1586         os::infinite_sleep();
1587       } else {
1588         // Crash or assert during error reporting. Lets continue reporting with the next step.
1589         stringStream ss(buffer, sizeof(buffer));
1590         // Note: this string does get parsed by a number of jtreg tests,
1591         // see hotspot/jtreg/runtime/ErrorHandling.
1592         ss.print("[error occurred during error reporting (%s), id 0x%x",
1593                    _current_step_info, id);
1594         char signal_name[64];
1595         if (os::exception_name(id, signal_name, sizeof(signal_name))) {
1596           ss.print(", %s (0x%x) at pc=" PTR_FORMAT, signal_name, id, p2i(pc));
1597         } else {
1598           if (should_report_bug(id)) {
1599             ss.print(", Internal Error (%s:%d)",
1600               filename == NULL ? "??" : filename, lineno);
1601           } else {
1602             ss.print(", Out of Memory Error (%s:%d)",
1603               filename == NULL ? "??" : filename, lineno);
1604           }
1605         }
1606         ss.print("]");
1607         st->print_raw_cr(buffer);
1608         st->cr();
1609       }
1610     }
1611   }
1612 
1613   // Part 1: print an abbreviated version (the '#' section) to stdout.
1614   if (!out_done) {
1615     // Suppress this output if we plan to print Part 2 to stdout too.
1616     // No need to have the "#" section twice.
1617     if (!(ErrorFileToStdout && out.fd() == 1)) {
1618       report(&out, false);
1619     }
1620 
1621     out_done = true;
1622 
1623     _current_step = 0;
1624     _current_step_info = "";
1625   }
1626 
1627   // Part 2: print a full error log file (optionally to stdout or stderr).
1628   // print to error log file
1629   if (!log_done) {
1630     // see if log file is already open
1631     if (!log.is_open()) {
1632       // open log file
1633       if (ErrorFileToStdout) {
1634         fd_log = 1;
1635       } else if (ErrorFileToStderr) {
1636         fd_log = 2;
1637       } else {
1638         fd_log = prepare_log_file(ErrorFile, "hs_err_pid%p.log", true,
1639                  buffer, sizeof(buffer));
1640         if (fd_log != -1) {
1641           out.print_raw("# An error report file with more information is saved as:\n# ");
1642           out.print_raw_cr(buffer);
1643         } else {
1644           out.print_raw_cr("# Can not save log file, dump to screen..");
1645           fd_log = 1;
1646         }
1647       }
1648       log.set_fd(fd_log);
1649     }
1650 
1651     report(&log, true);
1652     log_done = true;
1653     _current_step = 0;
1654     _current_step_info = "";
1655 
1656     if (fd_log > 3) {
1657       close(fd_log);
1658       fd_log = -1;
1659     }
1660 
1661     log.set_fd(-1);
1662   }
1663 
1664   JFR_ONLY(Jfr::on_vm_shutdown(true);)
1665 
1666   if (PrintNMTStatistics) {
1667     fdStream fds(fd_out);
1668     MemTracker::final_report(&fds);
1669   }
1670 
1671   static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay
1672   if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) {
1673     skip_replay = true;
1674     ciEnv* env = ciEnv::current();
1675     if (env != NULL) {
1676       const bool overwrite = false; // We do not overwrite an existing replay file.
1677       int fd = prepare_log_file(ReplayDataFile, "replay_pid%p.log", overwrite, buffer, sizeof(buffer));
1678       if (fd != -1) {
1679         FILE* replay_data_file = os::open(fd, "w");
1680         if (replay_data_file != NULL) {
1681           fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
1682           env->dump_replay_data_unsafe(&replay_data_stream);
1683           out.print_raw("#\n# Compiler replay data is saved as:\n# ");
1684           out.print_raw_cr(buffer);
1685         } else {
1686           int e = errno;
1687           out.print_raw("#\n# Can't open file to dump replay data. Error: ");
1688           out.print_raw_cr(os::strerror(e));
1689         }
1690       }
1691     }
1692   }
1693 
1694 #if INCLUDE_JVMCI
1695   if (JVMCI::fatal_log_filename() != NULL) {
1696     out.print_raw("#\n# The JVMCI shared library error report file is saved as:\n# ");
1697     out.print_raw_cr(JVMCI::fatal_log_filename());
1698   }
1699 #endif
1700 
1701   static bool skip_bug_url = !should_submit_bug_report(_id);
1702   if (!skip_bug_url) {
1703     skip_bug_url = true;
1704 
1705     out.print_raw_cr("#");
1706     print_bug_submit_message(&out, _thread);
1707   }
1708 
1709   static bool skip_OnError = false;
1710   if (!skip_OnError && OnError && OnError[0]) {
1711     skip_OnError = true;
1712 
1713     // Flush output and finish logs before running OnError commands.
1714     ostream_abort();
1715 
1716     out.print_raw_cr("#");
1717     out.print_raw   ("# -XX:OnError=\"");
1718     out.print_raw   (OnError);
1719     out.print_raw_cr("\"");
1720 
1721     char* cmd;
1722     const char* ptr = OnError;
1723     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1724       out.print_raw   ("#   Executing ");
1725 #if defined(LINUX) || defined(_ALLBSD_SOURCE)
1726       out.print_raw   ("/bin/sh -c ");
1727 #elif defined(_WINDOWS)
1728       out.print_raw   ("cmd /C ");
1729 #endif
1730       out.print_raw   ("\"");
1731       out.print_raw   (cmd);
1732       out.print_raw_cr("\" ...");
1733 
1734       if (os::fork_and_exec(cmd) < 0) {
1735         out.print_cr("os::fork_and_exec failed: %s (%s=%d)",
1736                      os::strerror(errno), os::errno_name(errno), errno);
1737       }
1738     }
1739 
1740     // done with OnError
1741     OnError = NULL;
1742   }
1743 
1744   if (WINDOWS_ONLY(!UseOSErrorReporting) NOT_WINDOWS(true)) {
1745     // os::abort() will call abort hooks, try it first.
1746     static bool skip_os_abort = false;
1747     if (!skip_os_abort) {
1748       skip_os_abort = true;
1749       bool dump_core = should_report_bug(_id);
1750       os::abort(dump_core && CreateCoredumpOnCrash, _siginfo, _context);
1751     }
1752 
1753     // if os::abort() doesn't abort, try os::die();
1754     os::die();
1755   }
1756 }
1757 
1758 /*
1759  * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this
1760  * ensures utilities such as jmap can observe the process is a consistent state.
1761  */
1762 class VM_ReportJavaOutOfMemory : public VM_Operation {
1763  private:
1764   const char* _message;
1765  public:
1766   VM_ReportJavaOutOfMemory(const char* message) { _message = message; }
1767   VMOp_Type type() const                        { return VMOp_ReportJavaOutOfMemory; }
1768   void doit();
1769 };
1770 
1771 void VM_ReportJavaOutOfMemory::doit() {
1772   // Don't allocate large buffer on stack
1773   static char buffer[O_BUFLEN];
1774 
1775   tty->print_cr("#");
1776   tty->print_cr("# java.lang.OutOfMemoryError: %s", _message);
1777   tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError);
1778 
1779   // make heap parsability
1780   Universe::heap()->ensure_parsability(false);  // no need to retire TLABs
1781 
1782   char* cmd;
1783   const char* ptr = OnOutOfMemoryError;
1784   while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1785     tty->print("#   Executing ");
1786 #if defined(LINUX)
1787     tty->print  ("/bin/sh -c ");
1788 #endif
1789     tty->print_cr("\"%s\"...", cmd);
1790 
1791     if (os::fork_and_exec(cmd, true) < 0) {
1792       tty->print_cr("os::fork_and_exec failed: %s (%s=%d)",
1793                      os::strerror(errno), os::errno_name(errno), errno);
1794     }
1795   }
1796 }
1797 
1798 void VMError::report_java_out_of_memory(const char* message) {
1799   if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
1800     MutexLocker ml(Heap_lock);
1801     VM_ReportJavaOutOfMemory op(message);
1802     VMThread::execute(&op);
1803   }
1804 }
1805 
1806 void VMError::show_message_box(char *buf, int buflen) {
1807   bool yes;
1808   do {
1809     error_string(buf, buflen);
1810     yes = os::start_debugging(buf,buflen);
1811   } while (yes);
1812 }
1813 
1814 // Timeout handling: check if a timeout happened (either a single step did
1815 // timeout or the whole of error reporting hit ErrorLogTimeout). Interrupt
1816 // the reporting thread if that is the case.
1817 bool VMError::check_timeout() {
1818 
1819   if (ErrorLogTimeout == 0) {
1820     return false;
1821   }
1822 
1823   // Do not check for timeouts if we still have a message box to show to the
1824   // user or if there are OnError handlers to be run.
1825   if (ShowMessageBoxOnError
1826       || (OnError != NULL && OnError[0] != '\0')
1827       || Arguments::abort_hook() != NULL) {
1828     return false;
1829   }
1830 
1831   const jlong reporting_start_time_l = get_reporting_start_time();
1832   const jlong now = get_current_timestamp();
1833   // Timestamp is stored in nanos.
1834   if (reporting_start_time_l > 0) {
1835     const jlong end = reporting_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR;
1836     if (end <= now && !_reporting_did_timeout) {
1837       // We hit ErrorLogTimeout and we haven't interrupted the reporting
1838       // thread yet.
1839       _reporting_did_timeout = true;
1840       interrupt_reporting_thread();
1841       return true; // global timeout
1842     }
1843   }
1844 
1845   const jlong step_start_time_l = get_step_start_time();
1846   if (step_start_time_l > 0) {
1847     // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
1848     // hang for some reason, so this simple rule allows for three hanging step and still
1849     // hopefully leaves time enough for the rest of the steps to finish.
1850     const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
1851     if (end <= now && !_step_did_timeout) {
1852       // The step timed out and we haven't interrupted the reporting
1853       // thread yet.
1854       _step_did_timeout = true;
1855       interrupt_reporting_thread();
1856       return false; // (Not a global timeout)
1857     }
1858   }
1859 
1860   return false;
1861 
1862 }
1863 
1864 #ifdef ASSERT
1865 typedef void (*voidfun_t)();
1866 
1867 // Crash with an authentic sigfpe
1868 volatile int sigfpe_int = 0;
1869 static void crash_with_sigfpe() {
1870 
1871   // generate a native synchronous SIGFPE where possible;
1872   sigfpe_int = sigfpe_int/sigfpe_int;
1873 
1874   // if that did not cause a signal (e.g. on ppc), just
1875   // raise the signal.
1876 #ifndef _WIN32
1877   // OSX implements raise(sig) incorrectly so we need to
1878   // explicitly target the current thread
1879   pthread_kill(pthread_self(), SIGFPE);
1880 #endif
1881 
1882 } // end: crash_with_sigfpe
1883 
1884 // crash with sigsegv at non-null address.
1885 static void crash_with_segfault() {
1886 
1887   int* crash_addr = reinterpret_cast<int*>(VMError::segfault_address);
1888   *crash_addr = 1;
1889 
1890 } // end: crash_with_segfault
1891 
1892 // crash in a controlled way:
1893 // 1  - assert
1894 // 2  - guarantee
1895 // 14 - SIGSEGV
1896 // 15 - SIGFPE
1897 void VMError::controlled_crash(int how) {
1898 
1899   // Case 14 is tested by test/hotspot/jtreg/runtime/ErrorHandling/SafeFetchInErrorHandlingTest.java.
1900   // Case 15 is tested by test/hotspot/jtreg/runtime/ErrorHandling/SecondaryErrorTest.java.
1901   // Case 16 is tested by test/hotspot/jtreg/runtime/ErrorHandling/ThreadsListHandleInErrorHandlingTest.java.
1902   // Case 17 is tested by test/hotspot/jtreg/runtime/ErrorHandling/NestedThreadsListHandleInErrorHandlingTest.java.
1903 
1904   // We try to grab Threads_lock to keep ThreadsSMRSupport::print_info_on()
1905   // from racing with Threads::add() or Threads::remove() as we
1906   // generate the hs_err_pid file. This makes our ErrorHandling tests
1907   // more stable.
1908   if (!Threads_lock->owned_by_self()) {
1909     Threads_lock->try_lock();
1910     // The VM is going to die so no need to unlock Thread_lock.
1911   }
1912 
1913   switch (how) {
1914     case 1: assert(how == 0, "test assert"); break;
1915     case 2: guarantee(how == 0, "test guarantee"); break;
1916 
1917     // The other cases are unused.
1918     case 14: crash_with_segfault(); break;
1919     case 15: crash_with_sigfpe(); break;
1920     case 16: {
1921       ThreadsListHandle tlh;
1922       fatal("Force crash with an active ThreadsListHandle.");
1923     }
1924     case 17: {
1925       ThreadsListHandle tlh;
1926       {
1927         ThreadsListHandle tlh2;
1928         fatal("Force crash with a nested ThreadsListHandle.");
1929       }
1930     }
1931     default:
1932       // If another number is given, give a generic crash.
1933       fatal("Crashing with number %d", how);
1934   }
1935   tty->print_cr("controlled_crash: survived intentional crash. Did you suppress the assert?");
1936   ShouldNotReachHere();
1937 }
1938 #endif // !ASSERT