aoqi@0: /* shshahma@9301: * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@9137: /* aoqi@9137: * This file has been modified by Loongson Technology in 2018. These aoqi@9137: * modifications are Copyright (c) 2018 Loongson Technology, and are made aoqi@9137: * available on the same license terms set forth above. aoqi@9137: * aoqi@9137: */ aoqi@9137: gthornbr@7493: #include aoqi@0: #include "precompiled.hpp" aoqi@0: #include "compiler/compileBroker.hpp" aoqi@0: #include "gc_interface/collectedHeap.hpp" aoqi@0: #include "prims/whitebox.hpp" aoqi@0: #include "runtime/arguments.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/init.hpp" aoqi@0: #include "runtime/os.hpp" goetz@6911: #include "runtime/thread.inline.hpp" aoqi@0: #include "runtime/vmThread.hpp" aoqi@0: #include "runtime/vm_operations.hpp" aoqi@0: #include "services/memTracker.hpp" aoqi@0: #include "utilities/debug.hpp" aoqi@0: #include "utilities/decoder.hpp" aoqi@0: #include "utilities/defaultStream.hpp" aoqi@0: #include "utilities/errorReporter.hpp" aoqi@0: #include "utilities/events.hpp" aoqi@0: #include "utilities/top.hpp" aoqi@0: #include "utilities/vmError.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: // List of environment variables that should be reported in error log file. aoqi@0: const char *env_list[] = { aoqi@0: // All platforms aoqi@0: "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH", aoqi@0: "JAVA_COMPILER", "PATH", "USERNAME", aoqi@0: aoqi@0: // Env variables that are defined on Solaris/Linux/BSD aoqi@0: "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY", aoqi@0: "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE", aoqi@0: aoqi@0: // defined on Linux aoqi@0: "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM", aoqi@0: aoqi@0: // defined on Darwin aoqi@0: "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH", aoqi@0: "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH", aoqi@0: "DYLD_INSERT_LIBRARIES", aoqi@0: aoqi@0: // defined on Windows aoqi@0: "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR", aoqi@0: aoqi@0: (const char *)0 aoqi@0: }; aoqi@0: aoqi@0: // Fatal error handler for internal errors and crashes. aoqi@0: // aoqi@0: // The default behavior of fatal error handler is to print a brief message aoqi@0: // to standard out (defaultStream::output_fd()), then save detailed information aoqi@0: // into an error report file (hs_err_pid.log) and abort VM. If multiple aoqi@0: // threads are having troubles at the same time, only one error is reported. aoqi@0: // The thread that is reporting error will abort VM when it is done, all other aoqi@0: // threads are blocked forever inside report_and_die(). aoqi@0: aoqi@0: // Constructor for crashes aoqi@0: VMError::VMError(Thread* thread, unsigned int sig, address pc, void* siginfo, void* context) { aoqi@0: _thread = thread; aoqi@0: _id = sig; aoqi@0: _pc = pc; aoqi@0: _siginfo = siginfo; aoqi@0: _context = context; aoqi@0: aoqi@0: _verbose = false; aoqi@0: _current_step = 0; aoqi@0: _current_step_info = NULL; aoqi@0: aoqi@0: _message = NULL; aoqi@0: _detail_msg = NULL; aoqi@0: _filename = NULL; aoqi@0: _lineno = 0; aoqi@0: aoqi@0: _size = 0; aoqi@0: } aoqi@0: aoqi@0: // Constructor for internal errors aoqi@0: VMError::VMError(Thread* thread, const char* filename, int lineno, aoqi@0: const char* message, const char * detail_msg) aoqi@0: { aoqi@0: _thread = thread; aoqi@0: _id = INTERNAL_ERROR; // Value that's not an OS exception/signal aoqi@0: _filename = filename; aoqi@0: _lineno = lineno; aoqi@0: _message = message; aoqi@0: _detail_msg = detail_msg; aoqi@0: aoqi@0: _verbose = false; aoqi@0: _current_step = 0; aoqi@0: _current_step_info = NULL; aoqi@0: aoqi@0: _pc = NULL; aoqi@0: _siginfo = NULL; aoqi@0: _context = NULL; aoqi@0: aoqi@0: _size = 0; aoqi@0: } aoqi@0: aoqi@0: // Constructor for OOM errors aoqi@0: VMError::VMError(Thread* thread, const char* filename, int lineno, size_t size, aoqi@0: VMErrorType vm_err_type, const char* message) { aoqi@0: _thread = thread; aoqi@0: _id = vm_err_type; // Value that's not an OS exception/signal aoqi@0: _filename = filename; aoqi@0: _lineno = lineno; aoqi@0: _message = message; aoqi@0: _detail_msg = NULL; aoqi@0: aoqi@0: _verbose = false; aoqi@0: _current_step = 0; aoqi@0: _current_step_info = NULL; aoqi@0: aoqi@0: _pc = NULL; aoqi@0: _siginfo = NULL; aoqi@0: _context = NULL; aoqi@0: aoqi@0: _size = size; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Constructor for non-fatal errors aoqi@0: VMError::VMError(const char* message) { aoqi@0: _thread = NULL; aoqi@0: _id = INTERNAL_ERROR; // Value that's not an OS exception/signal aoqi@0: _filename = NULL; aoqi@0: _lineno = 0; aoqi@0: _message = message; aoqi@0: _detail_msg = NULL; aoqi@0: aoqi@0: _verbose = false; aoqi@0: _current_step = 0; aoqi@0: _current_step_info = NULL; aoqi@0: aoqi@0: _pc = NULL; aoqi@0: _siginfo = NULL; aoqi@0: _context = NULL; aoqi@0: aoqi@0: _size = 0; aoqi@0: } aoqi@0: aoqi@0: // -XX:OnError=, where can be a list of commands, separated aoqi@0: // by ';'. "%p" is replaced by current process id (pid); "%%" is replaced by aoqi@0: // a single "%". Some examples: aoqi@0: // aoqi@0: // -XX:OnError="pmap %p" // show memory map aoqi@0: // -XX:OnError="gcore %p; dbx - %p" // dump core and launch debugger aoqi@0: // -XX:OnError="cat hs_err_pid%p.log | mail my_email@sun.com" aoqi@0: // -XX:OnError="kill -9 %p" // ?#!@# aoqi@0: aoqi@0: // A simple parser for -XX:OnError, usage: aoqi@0: // ptr = OnError; aoqi@0: // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL) aoqi@0: // ... ... aoqi@0: static char* next_OnError_command(char* buf, int buflen, const char** ptr) { aoqi@0: if (ptr == NULL || *ptr == NULL) return NULL; aoqi@0: aoqi@0: const char* cmd = *ptr; aoqi@0: aoqi@0: // skip leading blanks or ';' aoqi@0: while (*cmd == ' ' || *cmd == ';') cmd++; aoqi@0: aoqi@0: if (*cmd == '\0') return NULL; aoqi@0: aoqi@0: const char * cmdend = cmd; aoqi@0: while (*cmdend != '\0' && *cmdend != ';') cmdend++; aoqi@0: aoqi@0: Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen); aoqi@0: aoqi@0: *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1); aoqi@0: return buf; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static void print_bug_submit_message(outputStream *out, Thread *thread) { aoqi@0: if (out == NULL) return; aoqi@0: out->print_raw_cr("# If you would like to submit a bug report, please visit:"); aoqi@0: out->print_raw ("# "); aoqi@0: out->print_raw_cr(Arguments::java_vendor_url_bug()); aoqi@0: // If the crash is in native code, encourage user to submit a bug to the aoqi@0: // provider of that code. aoqi@0: if (thread && thread->is_Java_thread() && aoqi@0: !thread->is_hidden_from_external_view()) { aoqi@0: JavaThread* jt = (JavaThread*)thread; aoqi@0: if (jt->thread_state() == _thread_in_native) { aoqi@0: out->print_cr("# The crash happened outside the Java Virtual Machine in native code.\n# See problematic frame for where to report the bug."); aoqi@0: } aoqi@0: } aoqi@0: out->print_raw_cr("#"); aoqi@0: } aoqi@0: aoqi@0: bool VMError::coredump_status; aoqi@0: char VMError::coredump_message[O_BUFLEN]; aoqi@0: aoqi@0: void VMError::report_coredump_status(const char* message, bool status) { aoqi@0: coredump_status = status; aoqi@0: strncpy(coredump_message, message, sizeof(coredump_message)); aoqi@0: coredump_message[sizeof(coredump_message)-1] = 0; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Return a string to describe the error aoqi@0: char* VMError::error_string(char* buf, int buflen) { aoqi@0: char signame_buf[64]; aoqi@0: const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf)); aoqi@0: aoqi@0: if (signame) { aoqi@0: jio_snprintf(buf, buflen, dbuck@8186: "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" INTPTR_FORMAT, aoqi@0: signame, _id, _pc, aoqi@0: os::current_process_id(), os::current_thread_id()); aoqi@0: } else if (_filename != NULL && _lineno > 0) { aoqi@0: // skip directory names aoqi@0: char separator = os::file_separator()[0]; aoqi@0: const char *p = strrchr(_filename, separator); aoqi@0: int n = jio_snprintf(buf, buflen, dbuck@8186: "Internal Error at %s:%d, pid=%d, tid=" INTPTR_FORMAT, aoqi@0: p ? p + 1 : _filename, _lineno, aoqi@0: os::current_process_id(), os::current_thread_id()); aoqi@0: if (n >= 0 && n < buflen && _message) { aoqi@0: if (_detail_msg) { aoqi@0: jio_snprintf(buf + n, buflen - n, "%s%s: %s", aoqi@0: os::line_separator(), _message, _detail_msg); aoqi@0: } else { aoqi@0: jio_snprintf(buf + n, buflen - n, "%sError: %s", aoqi@0: os::line_separator(), _message); aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: jio_snprintf(buf, buflen, dbuck@8186: "Internal Error (0x%x), pid=%d, tid=" INTPTR_FORMAT, aoqi@0: _id, os::current_process_id(), os::current_thread_id()); aoqi@0: } aoqi@0: aoqi@0: return buf; aoqi@0: } aoqi@0: aoqi@0: void VMError::print_stack_trace(outputStream* st, JavaThread* jt, aoqi@0: char* buf, int buflen, bool verbose) { aoqi@0: #ifdef ZERO aoqi@0: if (jt->zero_stack()->sp() && jt->top_zero_frame()) { aoqi@0: // StackFrameStream uses the frame anchor, which may not have aoqi@0: // been set up. This can be done at any time in Zero, however, aoqi@0: // so if it hasn't been set up then we just set it up now and aoqi@0: // clear it again when we're done. aoqi@0: bool has_last_Java_frame = jt->has_last_Java_frame(); aoqi@0: if (!has_last_Java_frame) aoqi@0: jt->set_last_Java_frame(); aoqi@0: st->print("Java frames:"); aoqi@0: aoqi@0: // If the top frame is a Shark frame and the frame anchor isn't aoqi@0: // set up then it's possible that the information in the frame aoqi@0: // is garbage: it could be from a previous decache, or it could aoqi@0: // simply have never been written. So we print a warning... aoqi@0: StackFrameStream sfs(jt); aoqi@0: if (!has_last_Java_frame && !sfs.is_done()) { aoqi@0: if (sfs.current()->zeroframe()->is_shark_frame()) { aoqi@0: st->print(" (TOP FRAME MAY BE JUNK)"); aoqi@0: } aoqi@0: } aoqi@0: st->cr(); aoqi@0: aoqi@0: // Print the frames aoqi@0: for(int i = 0; !sfs.is_done(); sfs.next(), i++) { aoqi@0: sfs.current()->zero_print_on_error(i, st, buf, buflen); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: // Reset the frame anchor if necessary aoqi@0: if (!has_last_Java_frame) aoqi@0: jt->reset_last_Java_frame(); aoqi@0: } aoqi@0: #else aoqi@0: if (jt->has_last_Java_frame()) { aoqi@0: st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)"); aoqi@0: for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) { aoqi@0: sfs.current()->print_on_error(st, buf, buflen, verbose); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: #endif // ZERO aoqi@0: } aoqi@0: fmatte@9304: static void print_oom_reasons(outputStream* st) { fmatte@9304: st->print_cr("# Possible reasons:"); fmatte@9304: st->print_cr("# The system is out of physical RAM or swap space"); fmatte@9304: if (UseCompressedOops) { fmatte@9304: st->print_cr("# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap"); fmatte@9304: } fmatte@9304: if (LogBytesPerWord == 2) { fmatte@9304: st->print_cr("# In 32 bit mode, the process size limit was hit"); fmatte@9304: } fmatte@9304: st->print_cr("# Possible solutions:"); fmatte@9304: st->print_cr("# Reduce memory load on the system"); fmatte@9304: st->print_cr("# Increase physical memory or swap space"); fmatte@9304: st->print_cr("# Check if swap backing store is full"); fmatte@9304: if (LogBytesPerWord == 2) { fmatte@9304: st->print_cr("# Use 64 bit Java on a 64 bit OS"); fmatte@9304: } fmatte@9304: st->print_cr("# Decrease Java heap size (-Xmx/-Xms)"); fmatte@9304: st->print_cr("# Decrease number of Java threads"); fmatte@9304: st->print_cr("# Decrease Java thread stack sizes (-Xss)"); fmatte@9304: st->print_cr("# Set larger code cache with -XX:ReservedCodeCacheSize="); fmatte@9304: if (UseCompressedOops) { fmatte@9304: switch (Universe::narrow_oop_mode()) { fmatte@9304: case Universe::UnscaledNarrowOop: fmatte@9304: st->print_cr("# JVM is running with Unscaled Compressed Oops mode in which the Java heap is"); fmatte@9304: st->print_cr("# placed in the first 4GB address space. The Java Heap base address is the"); fmatte@9304: st->print_cr("# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress"); fmatte@9304: st->print_cr("# to set the Java Heap base and to place the Java Heap above 4GB virtual address."); fmatte@9304: break; fmatte@9304: case Universe::ZeroBasedNarrowOop: fmatte@9304: st->print_cr("# JVM is running with Zero Based Compressed Oops mode in which the Java heap is"); fmatte@9304: st->print_cr("# placed in the first 32GB address space. The Java Heap base address is the"); fmatte@9304: st->print_cr("# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress"); fmatte@9304: st->print_cr("# to set the Java Heap base and to place the Java Heap above 32GB virtual address."); fmatte@9304: break; fmatte@9304: default: fmatte@9304: break; fmatte@9304: } fmatte@9304: } fmatte@9304: st->print_cr("# This output file may be truncated or incomplete."); fmatte@9304: } fmatte@9304: aoqi@0: // This is the main function to report a fatal error. Only one thread can aoqi@0: // call this function, so we don't need to worry about MT-safety. But it's aoqi@0: // possible that the error handler itself may crash or die on an internal aoqi@0: // error, for example, when the stack/heap is badly damaged. We must be aoqi@0: // able to handle recursive errors that happen inside error handler. aoqi@0: // aoqi@0: // Error reporting is done in several steps. If a crash or internal error aoqi@0: // occurred when reporting an error, the nested signal/exception handler aoqi@0: // can skip steps that are already (or partially) done. Error reporting will aoqi@0: // continue from the next step. This allows us to retrieve and print aoqi@0: // information that may be unsafe to get after a fatal error. If it happens, aoqi@0: // you may find nested report_and_die() frames when you look at the stack aoqi@0: // in a debugger. aoqi@0: // aoqi@0: // In general, a hang in error handler is much worse than a crash or internal aoqi@0: // error, as it's harder to recover from a hang. Deadlock can happen if we aoqi@0: // try to grab a lock that is already owned by current thread, or if the aoqi@0: // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the aoqi@0: // error handler and all the functions it called should avoid grabbing any aoqi@0: // lock. An important thing to notice is that memory allocation needs a lock. aoqi@0: // aoqi@0: // We should avoid using large stack allocated buffers. Many errors happen aoqi@0: // when stack space is already low. Making things even worse is that there aoqi@0: // could be nested report_and_die() calls on stack (see above). Only one aoqi@0: // thread can report error, so large buffers are statically allocated in data aoqi@0: // segment. aoqi@0: aoqi@0: void VMError::report(outputStream* st) { aoqi@0: # define BEGIN if (_current_step == 0) { _current_step = 1; aoqi@0: # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s; aoqi@0: # define END } aoqi@0: aoqi@0: // don't allocate large buffer on stack aoqi@0: static char buf[O_BUFLEN]; aoqi@0: aoqi@0: BEGIN aoqi@0: aoqi@0: STEP(10, "(printing fatal error message)") aoqi@0: aoqi@0: st->print_cr("#"); aoqi@0: if (should_report_bug(_id)) { aoqi@0: st->print_cr("# A fatal error has been detected by the Java Runtime Environment:"); aoqi@0: } else { aoqi@0: st->print_cr("# There is insufficient memory for the Java " aoqi@0: "Runtime Environment to continue."); aoqi@0: } aoqi@0: aoqi@0: STEP(15, "(printing type of error)") aoqi@0: aoqi@0: switch(_id) { aoqi@0: case OOM_MALLOC_ERROR: aoqi@0: case OOM_MMAP_ERROR: aoqi@0: if (_size) { aoqi@0: st->print("# Native memory allocation "); aoqi@0: st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " : aoqi@0: "(mmap) failed to map "); aoqi@0: jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size); aoqi@0: st->print("%s", buf); aoqi@0: st->print(" bytes"); aoqi@0: if (_message != NULL) { aoqi@0: st->print(" for "); aoqi@0: st->print("%s", _message); aoqi@0: } aoqi@0: st->cr(); aoqi@0: } else { aoqi@0: if (_message != NULL) aoqi@0: st->print("# "); aoqi@0: st->print_cr("%s", _message); aoqi@0: } aoqi@0: // In error file give some solutions aoqi@0: if (_verbose) { fmatte@9304: print_oom_reasons(st); aoqi@0: } else { aoqi@0: return; // that's enough for the screen aoqi@0: } aoqi@0: break; aoqi@0: case INTERNAL_ERROR: aoqi@0: default: aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: STEP(20, "(printing exception/signal name)") aoqi@0: aoqi@0: st->print_cr("#"); aoqi@0: st->print("# "); aoqi@0: // Is it an OS exception/signal? aoqi@0: if (os::exception_name(_id, buf, sizeof(buf))) { aoqi@0: st->print("%s", buf); aoqi@0: st->print(" (0x%x)", _id); // signal number aoqi@0: st->print(" at pc=" PTR_FORMAT, _pc); aoqi@0: } else { aoqi@0: if (should_report_bug(_id)) { aoqi@0: st->print("Internal Error"); aoqi@0: } else { aoqi@0: st->print("Out of Memory Error"); aoqi@0: } aoqi@0: if (_filename != NULL && _lineno > 0) { aoqi@0: #ifdef PRODUCT aoqi@0: // In product mode chop off pathname? aoqi@0: char separator = os::file_separator()[0]; aoqi@0: const char *p = strrchr(_filename, separator); aoqi@0: const char *file = p ? p+1 : _filename; aoqi@0: #else aoqi@0: const char *file = _filename; aoqi@0: #endif aoqi@0: size_t len = strlen(file); aoqi@0: size_t buflen = sizeof(buf); aoqi@0: aoqi@0: strncpy(buf, file, buflen); aoqi@0: if (len + 10 < buflen) { aoqi@0: sprintf(buf + len, ":%d", _lineno); aoqi@0: } aoqi@0: st->print(" (%s)", buf); aoqi@0: } else { aoqi@0: st->print(" (0x%x)", _id); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(30, "(printing current thread and pid)") aoqi@0: aoqi@0: // process id, thread id aoqi@0: st->print(", pid=%d", os::current_process_id()); dbuck@8186: st->print(", tid=" INTPTR_FORMAT, os::current_thread_id()); aoqi@0: st->cr(); aoqi@0: aoqi@0: STEP(40, "(printing error message)") aoqi@0: aoqi@0: if (should_report_bug(_id)) { // already printed the message. aoqi@0: // error message aoqi@0: if (_detail_msg) { aoqi@0: st->print_cr("# %s: %s", _message ? _message : "Error", _detail_msg); aoqi@0: } else if (_message) { aoqi@0: st->print_cr("# Error: %s", _message); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(50, "(printing Java version string)") aoqi@0: aoqi@0: // VM version aoqi@0: st->print_cr("#"); aoqi@0: JDK_Version::current().to_string(buf, sizeof(buf)); aoqi@0: const char* runtime_name = JDK_Version::runtime_name() != NULL ? aoqi@0: JDK_Version::runtime_name() : ""; aoqi@0: const char* runtime_version = JDK_Version::runtime_version() != NULL ? aoqi@0: JDK_Version::runtime_version() : ""; aoqi@9137: #ifdef LOONGSON_RUNTIME_NAME aoqi@9137: const char* loongson_runtime_name_and_version = LOONGSON_RUNTIME_NAME; aoqi@9137: #else aoqi@9137: const char* loongson_runtime_name_and_version = ""; aoqi@9137: #endif aoqi@9137: st->print_cr("# JRE version: %s (%s) (build %s) (%s)", runtime_name, buf, runtime_version, loongson_runtime_name_and_version); aoqi@0: st->print_cr("# Java VM: %s (%s %s %s %s)", aoqi@0: Abstract_VM_Version::vm_name(), aoqi@0: Abstract_VM_Version::vm_release(), aoqi@0: Abstract_VM_Version::vm_info_string(), aoqi@0: Abstract_VM_Version::vm_platform_string(), aoqi@0: UseCompressedOops ? "compressed oops" : "" aoqi@0: ); aoqi@0: aoqi@0: STEP(60, "(printing problematic frame)") aoqi@0: aoqi@0: // Print current frame if we have a context (i.e. it's a crash) aoqi@0: if (_context) { aoqi@0: st->print_cr("# Problematic frame:"); aoqi@0: st->print("# "); aoqi@0: frame fr = os::fetch_frame_from_context(_context); aoqi@0: fr.print_on_error(st, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: st->print_cr("#"); aoqi@0: } aoqi@0: STEP(63, "(printing core file information)") aoqi@0: st->print("# "); aoqi@0: if (coredump_status) { aoqi@0: st->print("Core dump written. Default location: %s", coredump_message); aoqi@0: } else { aoqi@0: st->print("Failed to write core dump. %s", coredump_message); aoqi@0: } aoqi@0: st->cr(); aoqi@0: st->print_cr("#"); aoqi@0: aoqi@0: STEP(65, "(printing bug submit message)") aoqi@0: aoqi@0: if (should_report_bug(_id) && _verbose) { aoqi@0: print_bug_submit_message(st, _thread); aoqi@0: } aoqi@0: aoqi@0: STEP(70, "(printing thread)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: st->cr(); aoqi@0: st->print_cr("--------------- T H R E A D ---------------"); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(80, "(printing current thread)" ) aoqi@0: aoqi@0: // current thread aoqi@0: if (_verbose) { aoqi@0: if (_thread) { aoqi@0: st->print("Current thread (" PTR_FORMAT "): ", _thread); aoqi@0: _thread->print_on_error(st, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } else { aoqi@0: st->print_cr("Current thread is native thread"); aoqi@0: } aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(90, "(printing siginfo)" ) aoqi@0: aoqi@0: // signal no, signal code, address that caused the fault aoqi@0: if (_verbose && _siginfo) { aoqi@0: os::print_siginfo(st, _siginfo); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(100, "(printing registers, top of stack, instructions near pc)") aoqi@0: aoqi@0: // registers, top of stack, instructions near pc aoqi@0: if (_verbose && _context) { aoqi@0: os::print_context(st, _context); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(105, "(printing register info)") aoqi@0: aoqi@0: // decode register contents if possible aoqi@0: if (_verbose && _context && Universe::is_fully_initialized()) { aoqi@0: os::print_register_info(st, _context); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(110, "(printing stack bounds)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: st->print("Stack: "); aoqi@0: aoqi@0: address stack_top; aoqi@0: size_t stack_size; aoqi@0: aoqi@0: if (_thread) { aoqi@0: stack_top = _thread->stack_base(); aoqi@0: stack_size = _thread->stack_size(); aoqi@0: } else { aoqi@0: stack_top = os::current_stack_base(); aoqi@0: stack_size = os::current_stack_size(); aoqi@0: } aoqi@0: aoqi@0: address stack_bottom = stack_top - stack_size; aoqi@0: st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top); aoqi@0: aoqi@0: frame fr = _context ? os::fetch_frame_from_context(_context) aoqi@0: : os::current_frame(); aoqi@0: aoqi@0: if (fr.sp()) { aoqi@0: st->print(", sp=" PTR_FORMAT, fr.sp()); aoqi@0: size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024); aoqi@0: st->print(", free space=" SIZE_FORMAT "k", free_stack_size); aoqi@0: } aoqi@0: aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(120, "(printing native stack)" ) aoqi@0: simonis@7553: if (_verbose) { aoqi@0: if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) { aoqi@0: // We have printed the native stack in platform-specific code aoqi@0: // Windows/x64 needs special handling. aoqi@0: } else { aoqi@0: frame fr = _context ? os::fetch_frame_from_context(_context) aoqi@0: : os::current_frame(); aoqi@0: simonis@7553: print_native_stack(st, fr, _thread, buf, sizeof(buf)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(130, "(printing Java stack)" ) aoqi@0: aoqi@0: if (_verbose && _thread && _thread->is_Java_thread()) { aoqi@0: print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf)); aoqi@0: } aoqi@0: aoqi@0: STEP(135, "(printing target Java thread stack)" ) aoqi@0: aoqi@0: // printing Java thread stack trace if it is involved in GC crash aoqi@0: if (_verbose && _thread && (_thread->is_Named_thread())) { aoqi@0: JavaThread* jt = ((NamedThread *)_thread)->processed_thread(); aoqi@0: if (jt != NULL) { aoqi@0: st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id()); aoqi@0: print_stack_trace(st, jt, buf, sizeof(buf), true); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(140, "(printing VM operation)" ) aoqi@0: aoqi@0: if (_verbose && _thread && _thread->is_VM_thread()) { aoqi@0: VMThread* t = (VMThread*)_thread; aoqi@0: VM_Operation* op = t->vm_operation(); aoqi@0: if (op) { aoqi@0: op->print_on_error(st); aoqi@0: st->cr(); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(150, "(printing current compile task)" ) aoqi@0: aoqi@0: if (_verbose && _thread && _thread->is_Compiler_thread()) { aoqi@0: CompilerThread* t = (CompilerThread*)_thread; aoqi@0: if (t->task()) { aoqi@0: st->cr(); aoqi@0: st->print_cr("Current CompileTask:"); aoqi@0: t->task()->print_line_on_error(st, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: STEP(160, "(printing process)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: st->cr(); aoqi@0: st->print_cr("--------------- P R O C E S S ---------------"); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(170, "(printing all threads)" ) aoqi@0: aoqi@0: // all threads aoqi@0: if (_verbose && _thread) { aoqi@0: Threads::print_on_error(st, _thread, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(175, "(printing VM state)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: // Safepoint state aoqi@0: st->print("VM state:"); aoqi@0: aoqi@0: if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing"); aoqi@0: else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint"); aoqi@0: else st->print("not at safepoint"); aoqi@0: aoqi@0: // Also see if error occurred during initialization or shutdown aoqi@0: if (!Universe::is_fully_initialized()) { aoqi@0: st->print(" (not fully initialized)"); aoqi@0: } else if (VM_Exit::vm_exited()) { aoqi@0: st->print(" (shutting down)"); aoqi@0: } else { aoqi@0: st->print(" (normal execution)"); aoqi@0: } aoqi@0: st->cr(); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(180, "(printing owned locks on error)" ) aoqi@0: aoqi@0: // mutexes/monitors that currently have an owner aoqi@0: if (_verbose) { aoqi@0: print_owned_locks_on_error(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: shshahma@9301: STEP(182, "(printing number of OutOfMemoryError and StackOverflow exceptions)") shshahma@9301: shshahma@9301: if (_verbose && Exceptions::has_exception_counts()) { shshahma@9301: st->print_cr("OutOfMemory and StackOverflow Exception counts:"); shshahma@9301: Exceptions::print_exception_counts_on_error(st); shshahma@9301: st->cr(); shshahma@9301: } shshahma@9301: shshahma@9301: STEP(185, "(printing compressed oops mode") shshahma@9301: shshahma@9301: if (_verbose && UseCompressedOops) { shshahma@9301: Universe::print_compressed_oops_mode(st); shshahma@9301: if (UseCompressedClassPointers) { shshahma@9301: Metaspace::print_compressed_class_space(st); shshahma@9301: } shshahma@9301: st->cr(); shshahma@9301: } shshahma@9301: aoqi@0: STEP(190, "(printing heap information)" ) aoqi@0: aoqi@0: if (_verbose && Universe::is_fully_initialized()) { aoqi@0: Universe::heap()->print_on_error(st); aoqi@0: st->cr(); aoqi@0: aoqi@0: st->print_cr("Polling page: " INTPTR_FORMAT, os::get_polling_page()); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(195, "(printing code cache information)" ) aoqi@0: aoqi@0: if (_verbose && Universe::is_fully_initialized()) { aoqi@0: // print code cache information before vm abort aoqi@0: CodeCache::print_summary(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(200, "(printing ring buffers)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: Events::print_all(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(205, "(printing dynamic libraries)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: // dynamic libraries, or memory map aoqi@0: os::print_dll_info(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(210, "(printing VM options)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: // VM options aoqi@0: Arguments::print_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(215, "(printing warning if internal testing API used)" ) aoqi@0: aoqi@0: if (WhiteBox::used()) { aoqi@0: st->print_cr("Unsupported internal testing APIs have been used."); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(220, "(printing environment variables)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: os::print_environment_variables(st, env_list, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(225, "(printing signal handlers)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: os::print_signal_handlers(st, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: zgu@7074: STEP(228, "(Native Memory Tracking)" ) zgu@7074: if (_verbose) { coleenp@7267: MemTracker::error_report(st); zgu@7074: } zgu@7074: aoqi@0: STEP(230, "" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: st->cr(); aoqi@0: st->print_cr("--------------- S Y S T E M ---------------"); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(240, "(printing OS information)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: os::print_os_info(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(250, "(printing CPU info)" ) aoqi@0: if (_verbose) { aoqi@0: os::print_cpu_info(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(260, "(printing memory info)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: os::print_memory_info(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(270, "(printing internal vm info)" ) aoqi@0: aoqi@0: if (_verbose) { aoqi@0: st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string()); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: STEP(280, "(printing date and time)" ) aoqi@0: aoqi@0: if (_verbose) { shshahma@9301: os::print_date_and_time(st, buf, sizeof(buf)); aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: END aoqi@0: aoqi@0: # undef BEGIN aoqi@0: # undef STEP aoqi@0: # undef END aoqi@0: } aoqi@0: aoqi@0: VMError* volatile VMError::first_error = NULL; aoqi@0: volatile jlong VMError::first_error_tid = -1; aoqi@0: aoqi@0: // An error could happen before tty is initialized or after it has been aoqi@0: // destroyed. Here we use a very simple unbuffered fdStream for printing. aoqi@0: // Only out.print_raw() and out.print_raw_cr() should be used, as other aoqi@0: // printing methods need to allocate large buffer on stack. To format a aoqi@0: // string, use jio_snprintf() with a static buffer or use staticBufferStream. aoqi@0: fdStream VMError::out(defaultStream::output_fd()); aoqi@0: fdStream VMError::log; // error log used by VMError::report_and_die() aoqi@0: aoqi@0: /** Expand a pattern into a buffer starting at pos and open a file using constructed path */ aoqi@0: static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) { aoqi@0: int fd = -1; aoqi@0: if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) { gthornbr@7493: // the O_EXCL flag will cause the open to fail if the file exists gthornbr@7493: fd = open(buf, O_RDWR | O_CREAT | O_EXCL, 0666); aoqi@0: } aoqi@0: return fd; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct file name for a log file and return it's file descriptor. aoqi@0: * Name and location depends on pattern, default_pattern params and access aoqi@0: * permissions. aoqi@0: */ aoqi@0: static int prepare_log_file(const char* pattern, const char* default_pattern, char* buf, size_t buflen) { aoqi@0: int fd = -1; aoqi@0: aoqi@0: // If possible, use specified pattern to construct log file name aoqi@0: if (pattern != NULL) { aoqi@0: fd = expand_and_open(pattern, buf, buflen, 0); aoqi@0: } aoqi@0: aoqi@0: // Either user didn't specify, or the user's location failed, aoqi@0: // so use the default name in the current directory aoqi@0: if (fd == -1) { aoqi@0: const char* cwd = os::get_current_directory(buf, buflen); aoqi@0: if (cwd != NULL) { aoqi@0: size_t pos = strlen(cwd); aoqi@0: int fsep_len = jio_snprintf(&buf[pos], buflen-pos, "%s", os::file_separator()); aoqi@0: pos += fsep_len; aoqi@0: if (fsep_len > 0) { aoqi@0: fd = expand_and_open(default_pattern, buf, buflen, pos); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // try temp directory if it exists. aoqi@0: if (fd == -1) { aoqi@0: const char* tmpdir = os::get_temp_directory(); aoqi@0: if (tmpdir != NULL && strlen(tmpdir) > 0) { aoqi@0: int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator()); aoqi@0: if (pos > 0) { aoqi@0: fd = expand_and_open(default_pattern, buf, buflen, pos); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: return fd; aoqi@0: } aoqi@0: aoqi@0: void VMError::report_and_die() { aoqi@0: // Don't allocate large buffer on stack aoqi@0: static char buffer[O_BUFLEN]; aoqi@0: aoqi@0: // How many errors occurred in error handler when reporting first_error. aoqi@0: static int recursive_error_count; aoqi@0: aoqi@0: // We will first print a brief message to standard out (verbose = false), aoqi@0: // then save detailed information in log file (verbose = true). aoqi@0: static bool out_done = false; // done printing to standard out aoqi@0: static bool log_done = false; // done saving error log aoqi@0: static bool transmit_report_done = false; // done error reporting aoqi@0: aoqi@0: if (SuppressFatalErrorMessage) { aoqi@0: os::abort(); aoqi@0: } aoqi@0: jlong mytid = os::current_thread_id(); aoqi@0: if (first_error == NULL && aoqi@0: Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) { aoqi@0: aoqi@0: // first time aoqi@0: first_error_tid = mytid; aoqi@0: set_error_reported(); aoqi@0: aoqi@0: if (ShowMessageBoxOnError || PauseAtExit) { aoqi@0: show_message_box(buffer, sizeof(buffer)); aoqi@0: aoqi@0: // User has asked JVM to abort. Reset ShowMessageBoxOnError so the aoqi@0: // WatcherThread can kill JVM if the error handler hangs. aoqi@0: ShowMessageBoxOnError = false; aoqi@0: } aoqi@0: aoqi@0: // Write a minidump on Windows, check core dump limits on Linux/Solaris aoqi@0: os::check_or_create_dump(_siginfo, _context, buffer, sizeof(buffer)); aoqi@0: aoqi@0: // reset signal handlers or exception filter; make sure recursive crashes aoqi@0: // are handled properly. aoqi@0: reset_signal_handlers(); aoqi@0: aoqi@0: } else { aoqi@0: // If UseOsErrorReporting we call this for each level of the call stack aoqi@0: // while searching for the exception handler. Only the first level needs aoqi@0: // to be reported. aoqi@0: if (UseOSErrorReporting && log_done) return; aoqi@0: aoqi@0: // This is not the first error, see if it happened in a different thread aoqi@0: // or in the same thread during error reporting. aoqi@0: if (first_error_tid != mytid) { aoqi@0: char msgbuf[64]; aoqi@0: jio_snprintf(msgbuf, sizeof(msgbuf), aoqi@0: "[thread " INT64_FORMAT " also had an error]", aoqi@0: mytid); aoqi@0: out.print_raw_cr(msgbuf); aoqi@0: aoqi@0: // error reporting is not MT-safe, block current thread aoqi@0: os::infinite_sleep(); aoqi@0: aoqi@0: } else { aoqi@0: if (recursive_error_count++ > 30) { aoqi@0: out.print_raw_cr("[Too many errors, abort]"); aoqi@0: os::die(); aoqi@0: } aoqi@0: aoqi@0: jio_snprintf(buffer, sizeof(buffer), aoqi@0: "[error occurred during error reporting %s, id 0x%x]", aoqi@0: first_error ? first_error->_current_step_info : "", aoqi@0: _id); aoqi@0: if (log.is_open()) { aoqi@0: log.cr(); aoqi@0: log.print_raw_cr(buffer); aoqi@0: log.cr(); aoqi@0: } else { aoqi@0: out.cr(); aoqi@0: out.print_raw_cr(buffer); aoqi@0: out.cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // print to screen aoqi@0: if (!out_done) { aoqi@0: first_error->_verbose = false; aoqi@0: aoqi@0: staticBufferStream sbs(buffer, sizeof(buffer), &out); aoqi@0: first_error->report(&sbs); aoqi@0: aoqi@0: out_done = true; aoqi@0: aoqi@0: first_error->_current_step = 0; // reset current_step aoqi@0: first_error->_current_step_info = ""; // reset current_step string aoqi@0: } aoqi@0: aoqi@0: // print to error log file aoqi@0: if (!log_done) { aoqi@0: first_error->_verbose = true; aoqi@0: aoqi@0: // see if log file is already open aoqi@0: if (!log.is_open()) { aoqi@0: // open log file aoqi@0: int fd = prepare_log_file(ErrorFile, "hs_err_pid%p.log", buffer, sizeof(buffer)); aoqi@0: if (fd != -1) { aoqi@0: out.print_raw("# An error report file with more information is saved as:\n# "); aoqi@0: out.print_raw_cr(buffer); aoqi@0: aoqi@0: log.set_fd(fd); aoqi@0: } else { aoqi@0: out.print_raw_cr("# Can not save log file, dump to screen.."); aoqi@0: log.set_fd(defaultStream::output_fd()); aoqi@0: /* Error reporting currently needs dumpfile. aoqi@0: * Maybe implement direct streaming in the future.*/ aoqi@0: transmit_report_done = true; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: staticBufferStream sbs(buffer, O_BUFLEN, &log); aoqi@0: first_error->report(&sbs); aoqi@0: first_error->_current_step = 0; // reset current_step aoqi@0: first_error->_current_step_info = ""; // reset current_step string aoqi@0: aoqi@0: // Run error reporting to determine whether or not to report the crash. aoqi@0: if (!transmit_report_done && should_report_bug(first_error->_id)) { aoqi@0: transmit_report_done = true; aoqi@0: FILE* hs_err = os::open(log.fd(), "r"); aoqi@0: if (NULL != hs_err) { aoqi@0: ErrorReporter er; aoqi@0: er.call(hs_err, buffer, O_BUFLEN); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (log.fd() != defaultStream::output_fd()) { aoqi@0: close(log.fd()); aoqi@0: } aoqi@0: aoqi@0: log.set_fd(-1); aoqi@0: log_done = true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static bool skip_OnError = false; aoqi@0: if (!skip_OnError && OnError && OnError[0]) { aoqi@0: skip_OnError = true; aoqi@0: aoqi@0: out.print_raw_cr("#"); aoqi@0: out.print_raw ("# -XX:OnError=\""); aoqi@0: out.print_raw (OnError); aoqi@0: out.print_raw_cr("\""); aoqi@0: aoqi@0: char* cmd; aoqi@0: const char* ptr = OnError; aoqi@0: while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ aoqi@0: out.print_raw ("# Executing "); aoqi@0: #if defined(LINUX) || defined(_ALLBSD_SOURCE) aoqi@0: out.print_raw ("/bin/sh -c "); aoqi@0: #elif defined(SOLARIS) aoqi@0: out.print_raw ("/usr/bin/sh -c "); aoqi@0: #endif aoqi@0: out.print_raw ("\""); aoqi@0: out.print_raw (cmd); aoqi@0: out.print_raw_cr("\" ..."); aoqi@0: dholmes@7793: if (os::fork_and_exec(cmd) < 0) { dholmes@7793: out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); dholmes@7793: } aoqi@0: } aoqi@0: aoqi@0: // done with OnError aoqi@0: OnError = NULL; aoqi@0: } aoqi@0: aoqi@0: static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay aoqi@0: if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) { aoqi@0: skip_replay = true; aoqi@0: ciEnv* env = ciEnv::current(); aoqi@0: if (env != NULL) { aoqi@0: int fd = prepare_log_file(ReplayDataFile, "replay_pid%p.log", buffer, sizeof(buffer)); aoqi@0: if (fd != -1) { aoqi@0: FILE* replay_data_file = os::open(fd, "w"); aoqi@0: if (replay_data_file != NULL) { aoqi@0: fileStream replay_data_stream(replay_data_file, /*need_close=*/true); aoqi@0: env->dump_replay_data_unsafe(&replay_data_stream); aoqi@0: out.print_raw("#\n# Compiler replay data is saved as:\n# "); aoqi@0: out.print_raw_cr(buffer); aoqi@0: } else { aoqi@0: out.print_raw("#\n# Can't open file to dump replay data. Error: "); aoqi@0: out.print_raw_cr(strerror(os::get_last_error())); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static bool skip_bug_url = !should_report_bug(first_error->_id); aoqi@0: if (!skip_bug_url) { aoqi@0: skip_bug_url = true; aoqi@0: aoqi@0: out.print_raw_cr("#"); aoqi@0: print_bug_submit_message(&out, _thread); aoqi@0: } aoqi@0: aoqi@0: if (!UseOSErrorReporting) { aoqi@0: // os::abort() will call abort hooks, try it first. aoqi@0: static bool skip_os_abort = false; aoqi@0: if (!skip_os_abort) { aoqi@0: skip_os_abort = true; aoqi@0: bool dump_core = should_report_bug(first_error->_id); aoqi@0: os::abort(dump_core); aoqi@0: } aoqi@0: aoqi@0: // if os::abort() doesn't abort, try os::die(); aoqi@0: os::die(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /* aoqi@0: * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this aoqi@0: * ensures utilities such as jmap can observe the process is a consistent state. aoqi@0: */ aoqi@0: class VM_ReportJavaOutOfMemory : public VM_Operation { aoqi@0: private: aoqi@0: VMError *_err; aoqi@0: public: aoqi@0: VM_ReportJavaOutOfMemory(VMError *err) { _err = err; } aoqi@0: VMOp_Type type() const { return VMOp_ReportJavaOutOfMemory; } aoqi@0: void doit(); aoqi@0: }; aoqi@0: aoqi@0: void VM_ReportJavaOutOfMemory::doit() { aoqi@0: // Don't allocate large buffer on stack aoqi@0: static char buffer[O_BUFLEN]; aoqi@0: aoqi@0: tty->print_cr("#"); aoqi@0: tty->print_cr("# java.lang.OutOfMemoryError: %s", _err->message()); aoqi@0: tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError); aoqi@0: aoqi@0: // make heap parsability aoqi@0: Universe::heap()->ensure_parsability(false); // no need to retire TLABs aoqi@0: aoqi@0: char* cmd; aoqi@0: const char* ptr = OnOutOfMemoryError; aoqi@0: while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ aoqi@0: tty->print("# Executing "); aoqi@0: #if defined(LINUX) aoqi@0: tty->print ("/bin/sh -c "); aoqi@0: #elif defined(SOLARIS) aoqi@0: tty->print ("/usr/bin/sh -c "); aoqi@0: #endif aoqi@0: tty->print_cr("\"%s\"...", cmd); aoqi@0: dholmes@7793: if (os::fork_and_exec(cmd) < 0) { dholmes@7793: tty->print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); dholmes@7793: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void VMError::report_java_out_of_memory() { aoqi@0: if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { aoqi@0: MutexLocker ml(Heap_lock); aoqi@0: VM_ReportJavaOutOfMemory op(this); aoqi@0: VMThread::execute(&op); aoqi@0: } aoqi@0: }