1 /* 2 * Copyright (c) 2003, 2020, 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 #ifndef SHARE_UTILITIES_VMERROR_HPP 27 #define SHARE_UTILITIES_VMERROR_HPP 28 29 #include "utilities/globalDefinitions.hpp" 30 31 class Decoder; 32 class frame; 33 class VM_ReportJavaOutOfMemory; 34 35 class VMError : public AllStatic { 36 friend class VMStructs; 37 38 static int _id; // Solaris/Linux signals: 0 - SIGRTMAX 39 // Windows exceptions: 0xCxxxxxxx system errors 40 // 0x8xxxxxxx system warnings 41 42 static const char* _message; 43 static char _detail_msg[1024]; 44 45 static Thread* _thread; // NULL if it's native thread 46 47 // additional info for crashes 48 static address _pc; // faulting PC 49 static void* _siginfo; // ExceptionRecord on Windows, 50 // siginfo_t on Solaris/Linux 51 static void* _context; // ContextRecord on Windows, 52 // ucontext_t on Solaris/Linux 53 54 // additional info for VM internal errors 55 static const char* _filename; 56 static int _lineno; 57 58 // used by reporting about OOM 59 static size_t _size; 60 61 // used by fatal error handler 62 static int _current_step; 63 static const char* _current_step_info; 64 65 // Thread id of the first error. We must be able to handle native thread, 66 // so use thread id instead of Thread* to identify thread. 67 static volatile intptr_t _first_error_tid; 68 69 // Core dump status, false if we have been unable to write a core/minidump for some reason 70 static bool coredump_status; 71 72 // When coredump_status is set to true this will contain the name/path to the core/minidump, 73 // if coredump_status if false, this will (hopefully) contain a useful error explaining why 74 // no core/minidump has been written to disk 75 static char coredump_message[O_BUFLEN]; 76 77 // Timeout handling: 78 // Timestamp at which error reporting started; -1 if no error reporting in progress. 79 static volatile jlong _reporting_start_time; 80 // Whether or not error reporting did timeout. 81 static volatile bool _reporting_did_timeout; 82 // Timestamp at which the last error reporting step started; -1 if no error reporting 83 // in progress. 84 static volatile jlong _step_start_time; 85 // Whether or not the last error reporting step did timeout. 86 static volatile bool _step_did_timeout; 87 88 // Install secondary signal handler to handle secondary faults during error reporting 89 // (see VMError::crash_handler) 90 static void install_secondary_signal_handler(); 91 92 // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string 93 static void show_message_box(char* buf, int buflen); 94 95 // generate an error report 96 static void report(outputStream* st, bool verbose); 97 98 // generate a stack trace 99 static void print_stack_trace(outputStream* st, JavaThread* jt, 100 char* buf, int buflen, bool verbose = false); 101 102 // public for use by the internal non-product debugger. 103 NOT_PRODUCT(public:) 104 static void print_native_stack(outputStream* st, frame fr, Thread* t, 105 char* buf, int buf_size); 106 NOT_PRODUCT(private:) 107 should_report_bug(unsigned int id)108 static bool should_report_bug(unsigned int id) { 109 return (id != OOM_MALLOC_ERROR) && (id != OOM_MMAP_ERROR); 110 } 111 should_submit_bug_report(unsigned int id)112 static bool should_submit_bug_report(unsigned int id) { 113 return should_report_bug(id) && (id != OOM_JAVA_HEAP_FATAL); 114 } 115 116 // Write a hint to the stream in case siginfo relates to a segv/bus error 117 // and the offending address points into CDS store. 118 static void check_failing_cds_access(outputStream* st, const void* siginfo); 119 120 // Timeout handling. 121 // Hook functions for platform dependend functionality: 122 static void reporting_started(); 123 static void interrupt_reporting_thread(); 124 125 // Helper function to get the current timestamp. 126 static jlong get_current_timestamp(); 127 128 // Accessors to get/set the start times for step and total timeout. 129 static void record_reporting_start_time(); 130 static jlong get_reporting_start_time(); 131 static void record_step_start_time(); 132 static jlong get_step_start_time(); 133 static void clear_step_start_time(); 134 135 public: 136 137 // return a string to describe the error 138 static char* error_string(char* buf, int buflen); 139 140 // Record status of core/minidump 141 static void record_coredump_status(const char* message, bool status); 142 143 // support for VM.info diagnostic command 144 static void print_vm_info(outputStream* st); 145 146 // main error reporting function 147 static void report_and_die(Thread* thread, unsigned int sig, address pc, void* siginfo, 148 void* context, const char* detail_fmt, ...) ATTRIBUTE_PRINTF(6, 7); 149 150 static void report_and_die(int id, const char* message, const char* detail_fmt, va_list detail_args, 151 Thread* thread, address pc, void* siginfo, void* context, 152 const char* filename, int lineno, size_t size) ATTRIBUTE_PRINTF(3, 0); 153 154 static void report_and_die(Thread* thread, unsigned int sig, address pc, 155 void* siginfo, void* context); 156 157 static void report_and_die(Thread* thread, void* context, const char* filename, int lineno, const char* message, 158 const char* detail_fmt, va_list detail_args) ATTRIBUTE_PRINTF(6, 0); 159 160 static void report_and_die(Thread* thread, const char* filename, int lineno, size_t size, 161 VMErrorType vm_err_type, const char* detail_fmt, 162 va_list detail_args) ATTRIBUTE_PRINTF(6, 0); 163 164 // reporting OutOfMemoryError 165 static void report_java_out_of_memory(const char* message); 166 167 // Called by the WatcherThread to check if error reporting has timed-out. 168 // Returns true if error reporting has not completed within the ErrorLogTimeout limit. 169 static bool check_timeout(); 170 171 // Returns true if at least one thread reported a fatal error and 172 // fatal error handling is in process. 173 static bool is_error_reported(); 174 175 // Returns true if the current thread reported a fatal error. 176 static bool is_error_reported_in_current_thread(); 177 178 DEBUG_ONLY(static void controlled_crash(int how);) 179 180 // Address which is guaranteed to generate a fault on read, for test purposes, 181 // which is not NULL and contains bits in every word. 182 static const intptr_t segfault_address = LP64_ONLY(0xABC0000000000ABCULL) NOT_LP64(0x00000ABC); 183 184 // Needed when printing signal handlers. 185 NOT_WINDOWS(static const void* crash_handler_address;) 186 187 }; 188 #endif // SHARE_UTILITIES_VMERROR_HPP 189