duke@435: /* ctornqvi@2520: * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_UTILITIES_VMERROR_HPP stefank@2314: #define SHARE_VM_UTILITIES_VMERROR_HPP stefank@2314: stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: duke@435: duke@435: class VM_ReportJavaOutOfMemory; duke@435: duke@435: class VMError : public StackObj { duke@435: friend class VM_ReportJavaOutOfMemory; duke@435: duke@435: enum ErrorType { duke@435: internal_error = 0xe0000000, duke@435: oom_error = 0xe0000001 duke@435: }; duke@435: int _id; // Solaris/Linux signals: 0 - SIGRTMAX duke@435: // Windows exceptions: 0xCxxxxxxx system errors duke@435: // 0x8xxxxxxx system warnings duke@435: duke@435: const char * _message; jcoomes@1845: const char * _detail_msg; duke@435: duke@435: Thread * _thread; // NULL if it's native thread duke@435: duke@435: duke@435: // additional info for crashes duke@435: address _pc; // faulting PC duke@435: void * _siginfo; // ExceptionRecord on Windows, duke@435: // siginfo_t on Solaris/Linux duke@435: void * _context; // ContextRecord on Windows, duke@435: // ucontext_t on Solaris/Linux duke@435: duke@435: // additional info for VM internal errors duke@435: const char * _filename; twisti@1038: int _lineno; duke@435: duke@435: // used by fatal error handler duke@435: int _current_step; duke@435: const char * _current_step_info; duke@435: int _verbose; bobv@2036: // First error, and its thread id. We must be able to handle native thread, bobv@2036: // so use thread id instead of Thread* to identify thread. bobv@2036: static VMError* volatile first_error; bobv@2036: static volatile jlong first_error_tid; duke@435: ctornqvi@2520: // Core dump status, false if we have been unable to write a core/minidump for some reason ctornqvi@2520: static bool coredump_status; ctornqvi@2520: ctornqvi@2520: // When coredump_status is set to true this will contain the name/path to the core/minidump, ctornqvi@2520: // if coredump_status if false, this will (hopefully) contain a useful error explaining why ctornqvi@2520: // no core/minidump has been written to disk ctornqvi@2520: static char coredump_message[O_BUFLEN]; ctornqvi@2520: duke@435: // used by reporting about OOM duke@435: size_t _size; duke@435: duke@435: // set signal handlers on Solaris/Linux or the default exception filter duke@435: // on Windows, to handle recursive crashes. duke@435: void reset_signal_handlers(); duke@435: duke@435: // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string duke@435: void show_message_box(char* buf, int buflen); duke@435: duke@435: // generate an error report duke@435: void report(outputStream* st); duke@435: twisti@1819: // generate a stack trace twisti@1819: static void print_stack_trace(outputStream* st, JavaThread* jt, twisti@1819: char* buf, int buflen, bool verbose = false); twisti@1819: duke@435: // accessor jcoomes@1845: const char* message() const { return _message; } jcoomes@1845: const char* detail_msg() const { return _detail_msg; } coleenp@2418: bool should_report_bug(unsigned int id) { return id != oom_error; } duke@435: duke@435: public: duke@435: // Constructor for crashes coleenp@2418: VMError(Thread* thread, unsigned int sig, address pc, void* siginfo, coleenp@2418: void* context); duke@435: // Constructor for VM internal errors jcoomes@1845: VMError(Thread* thread, const char* filename, int lineno, jcoomes@1845: const char* message, const char * detail_msg); duke@435: jcoomes@1845: // Constructor for VM OOM errors jcoomes@1845: VMError(Thread* thread, const char* filename, int lineno, size_t size, jcoomes@1845: const char* message); duke@435: // Constructor for non-fatal errors duke@435: VMError(const char* message); duke@435: duke@435: // return a string to describe the error duke@435: char *error_string(char* buf, int buflen); duke@435: ctornqvi@2520: // Report status of core/minidump ctornqvi@2520: static void report_coredump_status(const char* message, bool status); ctornqvi@2520: duke@435: // main error reporting function duke@435: void report_and_die(); duke@435: duke@435: // reporting OutOfMemoryError duke@435: void report_java_out_of_memory(); duke@435: duke@435: // returns original flags for signal, if it was resetted, or -1 if duke@435: // signal was not changed by error reporter duke@435: static int get_resetted_sigflags(int sig); duke@435: duke@435: // returns original handler for signal, if it was resetted, or NULL if duke@435: // signal was not changed by error reporter duke@435: static address get_resetted_sighandler(int sig); bobv@2036: bobv@2036: // check to see if fatal error reporting is in progress bobv@2036: static bool fatal_error_in_progress() { return first_error != NULL; } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_UTILITIES_VMERROR_HPP