aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, 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@0: #ifndef SHARE_VM_UTILITIES_VMERROR_HPP aoqi@0: #define SHARE_VM_UTILITIES_VMERROR_HPP aoqi@0: aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: aoqi@0: class Decoder; aoqi@0: class VM_ReportJavaOutOfMemory; aoqi@0: aoqi@0: class VMError : public StackObj { aoqi@0: friend class VM_ReportJavaOutOfMemory; aoqi@0: friend class Decoder; aoqi@0: aoqi@0: int _id; // Solaris/Linux signals: 0 - SIGRTMAX aoqi@0: // Windows exceptions: 0xCxxxxxxx system errors aoqi@0: // 0x8xxxxxxx system warnings aoqi@0: aoqi@0: const char * _message; aoqi@0: const char * _detail_msg; aoqi@0: aoqi@0: Thread * _thread; // NULL if it's native thread aoqi@0: aoqi@0: aoqi@0: // additional info for crashes aoqi@0: address _pc; // faulting PC aoqi@0: void * _siginfo; // ExceptionRecord on Windows, aoqi@0: // siginfo_t on Solaris/Linux aoqi@0: void * _context; // ContextRecord on Windows, aoqi@0: // ucontext_t on Solaris/Linux aoqi@0: aoqi@0: // additional info for VM internal errors aoqi@0: const char * _filename; aoqi@0: int _lineno; aoqi@0: aoqi@0: // used by fatal error handler aoqi@0: int _current_step; aoqi@0: const char * _current_step_info; aoqi@0: int _verbose; aoqi@0: // First error, and its thread id. We must be able to handle native thread, aoqi@0: // so use thread id instead of Thread* to identify thread. aoqi@0: static VMError* volatile first_error; aoqi@0: static volatile jlong first_error_tid; aoqi@0: aoqi@0: // Core dump status, false if we have been unable to write a core/minidump for some reason aoqi@0: static bool coredump_status; aoqi@0: aoqi@0: // When coredump_status is set to true this will contain the name/path to the core/minidump, aoqi@0: // if coredump_status if false, this will (hopefully) contain a useful error explaining why aoqi@0: // no core/minidump has been written to disk aoqi@0: static char coredump_message[O_BUFLEN]; aoqi@0: aoqi@0: // used by reporting about OOM aoqi@0: size_t _size; aoqi@0: aoqi@0: // set signal handlers on Solaris/Linux or the default exception filter aoqi@0: // on Windows, to handle recursive crashes. aoqi@0: void reset_signal_handlers(); aoqi@0: aoqi@0: // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string aoqi@0: void show_message_box(char* buf, int buflen); aoqi@0: aoqi@0: // generate an error report aoqi@0: void report(outputStream* st); aoqi@0: aoqi@0: // generate a stack trace aoqi@0: static void print_stack_trace(outputStream* st, JavaThread* jt, aoqi@0: char* buf, int buflen, bool verbose = false); aoqi@0: aoqi@0: // accessor aoqi@0: const char* message() const { return _message; } aoqi@0: const char* detail_msg() const { return _detail_msg; } aoqi@0: bool should_report_bug(unsigned int id) { aoqi@0: return (id != OOM_MALLOC_ERROR) && (id != OOM_MMAP_ERROR); aoqi@0: } aoqi@0: aoqi@0: static fdStream out; aoqi@0: static fdStream log; // error log used by VMError::report_and_die() aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: // Constructor for crashes aoqi@0: VMError(Thread* thread, unsigned int sig, address pc, void* siginfo, aoqi@0: void* context); aoqi@0: // Constructor for VM internal errors aoqi@0: VMError(Thread* thread, const char* filename, int lineno, aoqi@0: const char* message, const char * detail_msg); aoqi@0: aoqi@0: // Constructor for VM OOM errors aoqi@0: VMError(Thread* thread, const char* filename, int lineno, size_t size, aoqi@0: VMErrorType vm_err_type, const char* message); aoqi@0: // Constructor for non-fatal errors aoqi@0: VMError(const char* message); aoqi@0: aoqi@0: // return a string to describe the error aoqi@0: char *error_string(char* buf, int buflen); aoqi@0: aoqi@0: // Report status of core/minidump aoqi@0: static void report_coredump_status(const char* message, bool status); aoqi@0: aoqi@0: // main error reporting function aoqi@0: void report_and_die(); aoqi@0: aoqi@0: // reporting OutOfMemoryError aoqi@0: void report_java_out_of_memory(); aoqi@0: aoqi@0: // returns original flags for signal, if it was resetted, or -1 if aoqi@0: // signal was not changed by error reporter aoqi@0: static int get_resetted_sigflags(int sig); aoqi@0: aoqi@0: // returns original handler for signal, if it was resetted, or NULL if aoqi@0: // signal was not changed by error reporter aoqi@0: static address get_resetted_sighandler(int sig); aoqi@0: aoqi@0: // check to see if fatal error reporting is in progress aoqi@0: static bool fatal_error_in_progress() { return first_error != NULL; } aoqi@0: aoqi@0: static jlong get_first_error_tid() { aoqi@0: return first_error_tid; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_UTILITIES_VMERROR_HPP