1 /* 2 * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25 26 class VM_ReportJavaOutOfMemory; 27 28 class VMError : public StackObj { 29 friend class VM_ReportJavaOutOfMemory; 30 31 enum ErrorType { 32 internal_error = 0xe0000000, 33 oom_error = 0xe0000001 34 }; 35 int _id; // Solaris/Linux signals: 0 - SIGRTMAX 36 // Windows exceptions: 0xCxxxxxxx system errors 37 // 0x8xxxxxxx system warnings 38 39 const char * _message; 40 41 Thread * _thread; // NULL if it's native thread 42 43 44 // additional info for crashes 45 address _pc; // faulting PC 46 void * _siginfo; // ExceptionRecord on Windows, 47 // siginfo_t on Solaris/Linux 48 void * _context; // ContextRecord on Windows, 49 // ucontext_t on Solaris/Linux 50 51 // additional info for VM internal errors 52 const char * _filename; 53 int _lineno; 54 55 // used by fatal error handler 56 int _current_step; 57 const char * _current_step_info; 58 int _verbose; 59 60 // used by reporting about OOM 61 size_t _size; 62 63 // set signal handlers on Solaris/Linux or the default exception filter 64 // on Windows, to handle recursive crashes. 65 void reset_signal_handlers(); 66 67 // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string 68 void show_message_box(char* buf, int buflen); 69 70 // generate an error report 71 void report(outputStream* st); 72 73 // generate a stack trace 74 static void print_stack_trace(outputStream* st, JavaThread* jt, 75 char* buf, int buflen, bool verbose = false); 76 77 // accessor 78 const char* message() { return _message; } 79 80 public: 81 // Constructor for crashes 82 VMError(Thread* thread, int sig, address pc, void* siginfo, void* context); 83 // Constructor for VM internal errors 84 VMError(Thread* thread, const char* message, const char* filename, int lineno); 85 86 // Constructors for VM OOM errors 87 VMError(Thread* thread, size_t size, const char* message, const char* filename, int lineno); 88 // Constructor for non-fatal errors 89 VMError(const char* message); 90 91 // return a string to describe the error 92 char *error_string(char* buf, int buflen); 93 94 // main error reporting function 95 void report_and_die(); 96 97 // reporting OutOfMemoryError 98 void report_java_out_of_memory(); 99 100 // returns original flags for signal, if it was resetted, or -1 if 101 // signal was not changed by error reporter 102 static int get_resetted_sigflags(int sig); 103 104 // returns original handler for signal, if it was resetted, or NULL if 105 // signal was not changed by error reporter 106 static address get_resetted_sighandler(int sig); 107 };