Tue, 24 Jul 2018 13:22:11 +0800
#7048 added Loongson release info to hs_err crash files
aoqi@0 | 1 | /* |
dholmes@7793 | 2 | * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@9137 | 25 | /* |
aoqi@9137 | 26 | * This file has been modified by Loongson Technology in 2018. These |
aoqi@9137 | 27 | * modifications are Copyright (c) 2018 Loongson Technology, and are made |
aoqi@9137 | 28 | * available on the same license terms set forth above. |
aoqi@9137 | 29 | * |
aoqi@9137 | 30 | */ |
aoqi@9137 | 31 | |
gthornbr@7493 | 32 | #include <fcntl.h> |
aoqi@0 | 33 | #include "precompiled.hpp" |
aoqi@0 | 34 | #include "compiler/compileBroker.hpp" |
aoqi@0 | 35 | #include "gc_interface/collectedHeap.hpp" |
aoqi@0 | 36 | #include "prims/whitebox.hpp" |
aoqi@0 | 37 | #include "runtime/arguments.hpp" |
aoqi@0 | 38 | #include "runtime/frame.inline.hpp" |
aoqi@0 | 39 | #include "runtime/init.hpp" |
aoqi@0 | 40 | #include "runtime/os.hpp" |
goetz@6911 | 41 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 42 | #include "runtime/vmThread.hpp" |
aoqi@0 | 43 | #include "runtime/vm_operations.hpp" |
aoqi@0 | 44 | #include "services/memTracker.hpp" |
aoqi@0 | 45 | #include "utilities/debug.hpp" |
aoqi@0 | 46 | #include "utilities/decoder.hpp" |
aoqi@0 | 47 | #include "utilities/defaultStream.hpp" |
aoqi@0 | 48 | #include "utilities/errorReporter.hpp" |
aoqi@0 | 49 | #include "utilities/events.hpp" |
aoqi@0 | 50 | #include "utilities/top.hpp" |
aoqi@0 | 51 | #include "utilities/vmError.hpp" |
aoqi@0 | 52 | |
aoqi@0 | 53 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 54 | |
aoqi@0 | 55 | // List of environment variables that should be reported in error log file. |
aoqi@0 | 56 | const char *env_list[] = { |
aoqi@0 | 57 | // All platforms |
aoqi@0 | 58 | "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH", |
aoqi@0 | 59 | "JAVA_COMPILER", "PATH", "USERNAME", |
aoqi@0 | 60 | |
aoqi@0 | 61 | // Env variables that are defined on Solaris/Linux/BSD |
aoqi@0 | 62 | "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY", |
aoqi@0 | 63 | "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE", |
aoqi@0 | 64 | |
aoqi@0 | 65 | // defined on Linux |
aoqi@0 | 66 | "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM", |
aoqi@0 | 67 | |
aoqi@0 | 68 | // defined on Darwin |
aoqi@0 | 69 | "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH", |
aoqi@0 | 70 | "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH", |
aoqi@0 | 71 | "DYLD_INSERT_LIBRARIES", |
aoqi@0 | 72 | |
aoqi@0 | 73 | // defined on Windows |
aoqi@0 | 74 | "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR", |
aoqi@0 | 75 | |
aoqi@0 | 76 | (const char *)0 |
aoqi@0 | 77 | }; |
aoqi@0 | 78 | |
aoqi@0 | 79 | // Fatal error handler for internal errors and crashes. |
aoqi@0 | 80 | // |
aoqi@0 | 81 | // The default behavior of fatal error handler is to print a brief message |
aoqi@0 | 82 | // to standard out (defaultStream::output_fd()), then save detailed information |
aoqi@0 | 83 | // into an error report file (hs_err_pid<pid>.log) and abort VM. If multiple |
aoqi@0 | 84 | // threads are having troubles at the same time, only one error is reported. |
aoqi@0 | 85 | // The thread that is reporting error will abort VM when it is done, all other |
aoqi@0 | 86 | // threads are blocked forever inside report_and_die(). |
aoqi@0 | 87 | |
aoqi@0 | 88 | // Constructor for crashes |
aoqi@0 | 89 | VMError::VMError(Thread* thread, unsigned int sig, address pc, void* siginfo, void* context) { |
aoqi@0 | 90 | _thread = thread; |
aoqi@0 | 91 | _id = sig; |
aoqi@0 | 92 | _pc = pc; |
aoqi@0 | 93 | _siginfo = siginfo; |
aoqi@0 | 94 | _context = context; |
aoqi@0 | 95 | |
aoqi@0 | 96 | _verbose = false; |
aoqi@0 | 97 | _current_step = 0; |
aoqi@0 | 98 | _current_step_info = NULL; |
aoqi@0 | 99 | |
aoqi@0 | 100 | _message = NULL; |
aoqi@0 | 101 | _detail_msg = NULL; |
aoqi@0 | 102 | _filename = NULL; |
aoqi@0 | 103 | _lineno = 0; |
aoqi@0 | 104 | |
aoqi@0 | 105 | _size = 0; |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | // Constructor for internal errors |
aoqi@0 | 109 | VMError::VMError(Thread* thread, const char* filename, int lineno, |
aoqi@0 | 110 | const char* message, const char * detail_msg) |
aoqi@0 | 111 | { |
aoqi@0 | 112 | _thread = thread; |
aoqi@0 | 113 | _id = INTERNAL_ERROR; // Value that's not an OS exception/signal |
aoqi@0 | 114 | _filename = filename; |
aoqi@0 | 115 | _lineno = lineno; |
aoqi@0 | 116 | _message = message; |
aoqi@0 | 117 | _detail_msg = detail_msg; |
aoqi@0 | 118 | |
aoqi@0 | 119 | _verbose = false; |
aoqi@0 | 120 | _current_step = 0; |
aoqi@0 | 121 | _current_step_info = NULL; |
aoqi@0 | 122 | |
aoqi@0 | 123 | _pc = NULL; |
aoqi@0 | 124 | _siginfo = NULL; |
aoqi@0 | 125 | _context = NULL; |
aoqi@0 | 126 | |
aoqi@0 | 127 | _size = 0; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | // Constructor for OOM errors |
aoqi@0 | 131 | VMError::VMError(Thread* thread, const char* filename, int lineno, size_t size, |
aoqi@0 | 132 | VMErrorType vm_err_type, const char* message) { |
aoqi@0 | 133 | _thread = thread; |
aoqi@0 | 134 | _id = vm_err_type; // Value that's not an OS exception/signal |
aoqi@0 | 135 | _filename = filename; |
aoqi@0 | 136 | _lineno = lineno; |
aoqi@0 | 137 | _message = message; |
aoqi@0 | 138 | _detail_msg = NULL; |
aoqi@0 | 139 | |
aoqi@0 | 140 | _verbose = false; |
aoqi@0 | 141 | _current_step = 0; |
aoqi@0 | 142 | _current_step_info = NULL; |
aoqi@0 | 143 | |
aoqi@0 | 144 | _pc = NULL; |
aoqi@0 | 145 | _siginfo = NULL; |
aoqi@0 | 146 | _context = NULL; |
aoqi@0 | 147 | |
aoqi@0 | 148 | _size = size; |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | |
aoqi@0 | 152 | // Constructor for non-fatal errors |
aoqi@0 | 153 | VMError::VMError(const char* message) { |
aoqi@0 | 154 | _thread = NULL; |
aoqi@0 | 155 | _id = INTERNAL_ERROR; // Value that's not an OS exception/signal |
aoqi@0 | 156 | _filename = NULL; |
aoqi@0 | 157 | _lineno = 0; |
aoqi@0 | 158 | _message = message; |
aoqi@0 | 159 | _detail_msg = NULL; |
aoqi@0 | 160 | |
aoqi@0 | 161 | _verbose = false; |
aoqi@0 | 162 | _current_step = 0; |
aoqi@0 | 163 | _current_step_info = NULL; |
aoqi@0 | 164 | |
aoqi@0 | 165 | _pc = NULL; |
aoqi@0 | 166 | _siginfo = NULL; |
aoqi@0 | 167 | _context = NULL; |
aoqi@0 | 168 | |
aoqi@0 | 169 | _size = 0; |
aoqi@0 | 170 | } |
aoqi@0 | 171 | |
aoqi@0 | 172 | // -XX:OnError=<string>, where <string> can be a list of commands, separated |
aoqi@0 | 173 | // by ';'. "%p" is replaced by current process id (pid); "%%" is replaced by |
aoqi@0 | 174 | // a single "%". Some examples: |
aoqi@0 | 175 | // |
aoqi@0 | 176 | // -XX:OnError="pmap %p" // show memory map |
aoqi@0 | 177 | // -XX:OnError="gcore %p; dbx - %p" // dump core and launch debugger |
aoqi@0 | 178 | // -XX:OnError="cat hs_err_pid%p.log | mail my_email@sun.com" |
aoqi@0 | 179 | // -XX:OnError="kill -9 %p" // ?#!@# |
aoqi@0 | 180 | |
aoqi@0 | 181 | // A simple parser for -XX:OnError, usage: |
aoqi@0 | 182 | // ptr = OnError; |
aoqi@0 | 183 | // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL) |
aoqi@0 | 184 | // ... ... |
aoqi@0 | 185 | static char* next_OnError_command(char* buf, int buflen, const char** ptr) { |
aoqi@0 | 186 | if (ptr == NULL || *ptr == NULL) return NULL; |
aoqi@0 | 187 | |
aoqi@0 | 188 | const char* cmd = *ptr; |
aoqi@0 | 189 | |
aoqi@0 | 190 | // skip leading blanks or ';' |
aoqi@0 | 191 | while (*cmd == ' ' || *cmd == ';') cmd++; |
aoqi@0 | 192 | |
aoqi@0 | 193 | if (*cmd == '\0') return NULL; |
aoqi@0 | 194 | |
aoqi@0 | 195 | const char * cmdend = cmd; |
aoqi@0 | 196 | while (*cmdend != '\0' && *cmdend != ';') cmdend++; |
aoqi@0 | 197 | |
aoqi@0 | 198 | Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen); |
aoqi@0 | 199 | |
aoqi@0 | 200 | *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1); |
aoqi@0 | 201 | return buf; |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | |
aoqi@0 | 205 | static void print_bug_submit_message(outputStream *out, Thread *thread) { |
aoqi@0 | 206 | if (out == NULL) return; |
aoqi@0 | 207 | out->print_raw_cr("# If you would like to submit a bug report, please visit:"); |
aoqi@0 | 208 | out->print_raw ("# "); |
aoqi@0 | 209 | out->print_raw_cr(Arguments::java_vendor_url_bug()); |
aoqi@0 | 210 | // If the crash is in native code, encourage user to submit a bug to the |
aoqi@0 | 211 | // provider of that code. |
aoqi@0 | 212 | if (thread && thread->is_Java_thread() && |
aoqi@0 | 213 | !thread->is_hidden_from_external_view()) { |
aoqi@0 | 214 | JavaThread* jt = (JavaThread*)thread; |
aoqi@0 | 215 | if (jt->thread_state() == _thread_in_native) { |
aoqi@0 | 216 | 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 | 217 | } |
aoqi@0 | 218 | } |
aoqi@0 | 219 | out->print_raw_cr("#"); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | bool VMError::coredump_status; |
aoqi@0 | 223 | char VMError::coredump_message[O_BUFLEN]; |
aoqi@0 | 224 | |
aoqi@0 | 225 | void VMError::report_coredump_status(const char* message, bool status) { |
aoqi@0 | 226 | coredump_status = status; |
aoqi@0 | 227 | strncpy(coredump_message, message, sizeof(coredump_message)); |
aoqi@0 | 228 | coredump_message[sizeof(coredump_message)-1] = 0; |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | |
aoqi@0 | 232 | // Return a string to describe the error |
aoqi@0 | 233 | char* VMError::error_string(char* buf, int buflen) { |
aoqi@0 | 234 | char signame_buf[64]; |
aoqi@0 | 235 | const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf)); |
aoqi@0 | 236 | |
aoqi@0 | 237 | if (signame) { |
aoqi@0 | 238 | jio_snprintf(buf, buflen, |
dbuck@8186 | 239 | "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" INTPTR_FORMAT, |
aoqi@0 | 240 | signame, _id, _pc, |
aoqi@0 | 241 | os::current_process_id(), os::current_thread_id()); |
aoqi@0 | 242 | } else if (_filename != NULL && _lineno > 0) { |
aoqi@0 | 243 | // skip directory names |
aoqi@0 | 244 | char separator = os::file_separator()[0]; |
aoqi@0 | 245 | const char *p = strrchr(_filename, separator); |
aoqi@0 | 246 | int n = jio_snprintf(buf, buflen, |
dbuck@8186 | 247 | "Internal Error at %s:%d, pid=%d, tid=" INTPTR_FORMAT, |
aoqi@0 | 248 | p ? p + 1 : _filename, _lineno, |
aoqi@0 | 249 | os::current_process_id(), os::current_thread_id()); |
aoqi@0 | 250 | if (n >= 0 && n < buflen && _message) { |
aoqi@0 | 251 | if (_detail_msg) { |
aoqi@0 | 252 | jio_snprintf(buf + n, buflen - n, "%s%s: %s", |
aoqi@0 | 253 | os::line_separator(), _message, _detail_msg); |
aoqi@0 | 254 | } else { |
aoqi@0 | 255 | jio_snprintf(buf + n, buflen - n, "%sError: %s", |
aoqi@0 | 256 | os::line_separator(), _message); |
aoqi@0 | 257 | } |
aoqi@0 | 258 | } |
aoqi@0 | 259 | } else { |
aoqi@0 | 260 | jio_snprintf(buf, buflen, |
dbuck@8186 | 261 | "Internal Error (0x%x), pid=%d, tid=" INTPTR_FORMAT, |
aoqi@0 | 262 | _id, os::current_process_id(), os::current_thread_id()); |
aoqi@0 | 263 | } |
aoqi@0 | 264 | |
aoqi@0 | 265 | return buf; |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | void VMError::print_stack_trace(outputStream* st, JavaThread* jt, |
aoqi@0 | 269 | char* buf, int buflen, bool verbose) { |
aoqi@0 | 270 | #ifdef ZERO |
aoqi@0 | 271 | if (jt->zero_stack()->sp() && jt->top_zero_frame()) { |
aoqi@0 | 272 | // StackFrameStream uses the frame anchor, which may not have |
aoqi@0 | 273 | // been set up. This can be done at any time in Zero, however, |
aoqi@0 | 274 | // so if it hasn't been set up then we just set it up now and |
aoqi@0 | 275 | // clear it again when we're done. |
aoqi@0 | 276 | bool has_last_Java_frame = jt->has_last_Java_frame(); |
aoqi@0 | 277 | if (!has_last_Java_frame) |
aoqi@0 | 278 | jt->set_last_Java_frame(); |
aoqi@0 | 279 | st->print("Java frames:"); |
aoqi@0 | 280 | |
aoqi@0 | 281 | // If the top frame is a Shark frame and the frame anchor isn't |
aoqi@0 | 282 | // set up then it's possible that the information in the frame |
aoqi@0 | 283 | // is garbage: it could be from a previous decache, or it could |
aoqi@0 | 284 | // simply have never been written. So we print a warning... |
aoqi@0 | 285 | StackFrameStream sfs(jt); |
aoqi@0 | 286 | if (!has_last_Java_frame && !sfs.is_done()) { |
aoqi@0 | 287 | if (sfs.current()->zeroframe()->is_shark_frame()) { |
aoqi@0 | 288 | st->print(" (TOP FRAME MAY BE JUNK)"); |
aoqi@0 | 289 | } |
aoqi@0 | 290 | } |
aoqi@0 | 291 | st->cr(); |
aoqi@0 | 292 | |
aoqi@0 | 293 | // Print the frames |
aoqi@0 | 294 | for(int i = 0; !sfs.is_done(); sfs.next(), i++) { |
aoqi@0 | 295 | sfs.current()->zero_print_on_error(i, st, buf, buflen); |
aoqi@0 | 296 | st->cr(); |
aoqi@0 | 297 | } |
aoqi@0 | 298 | |
aoqi@0 | 299 | // Reset the frame anchor if necessary |
aoqi@0 | 300 | if (!has_last_Java_frame) |
aoqi@0 | 301 | jt->reset_last_Java_frame(); |
aoqi@0 | 302 | } |
aoqi@0 | 303 | #else |
aoqi@0 | 304 | if (jt->has_last_Java_frame()) { |
aoqi@0 | 305 | st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)"); |
aoqi@0 | 306 | for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) { |
aoqi@0 | 307 | sfs.current()->print_on_error(st, buf, buflen, verbose); |
aoqi@0 | 308 | st->cr(); |
aoqi@0 | 309 | } |
aoqi@0 | 310 | } |
aoqi@0 | 311 | #endif // ZERO |
aoqi@0 | 312 | } |
aoqi@0 | 313 | |
aoqi@0 | 314 | // This is the main function to report a fatal error. Only one thread can |
aoqi@0 | 315 | // call this function, so we don't need to worry about MT-safety. But it's |
aoqi@0 | 316 | // possible that the error handler itself may crash or die on an internal |
aoqi@0 | 317 | // error, for example, when the stack/heap is badly damaged. We must be |
aoqi@0 | 318 | // able to handle recursive errors that happen inside error handler. |
aoqi@0 | 319 | // |
aoqi@0 | 320 | // Error reporting is done in several steps. If a crash or internal error |
aoqi@0 | 321 | // occurred when reporting an error, the nested signal/exception handler |
aoqi@0 | 322 | // can skip steps that are already (or partially) done. Error reporting will |
aoqi@0 | 323 | // continue from the next step. This allows us to retrieve and print |
aoqi@0 | 324 | // information that may be unsafe to get after a fatal error. If it happens, |
aoqi@0 | 325 | // you may find nested report_and_die() frames when you look at the stack |
aoqi@0 | 326 | // in a debugger. |
aoqi@0 | 327 | // |
aoqi@0 | 328 | // In general, a hang in error handler is much worse than a crash or internal |
aoqi@0 | 329 | // error, as it's harder to recover from a hang. Deadlock can happen if we |
aoqi@0 | 330 | // try to grab a lock that is already owned by current thread, or if the |
aoqi@0 | 331 | // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the |
aoqi@0 | 332 | // error handler and all the functions it called should avoid grabbing any |
aoqi@0 | 333 | // lock. An important thing to notice is that memory allocation needs a lock. |
aoqi@0 | 334 | // |
aoqi@0 | 335 | // We should avoid using large stack allocated buffers. Many errors happen |
aoqi@0 | 336 | // when stack space is already low. Making things even worse is that there |
aoqi@0 | 337 | // could be nested report_and_die() calls on stack (see above). Only one |
aoqi@0 | 338 | // thread can report error, so large buffers are statically allocated in data |
aoqi@0 | 339 | // segment. |
aoqi@0 | 340 | |
aoqi@0 | 341 | void VMError::report(outputStream* st) { |
aoqi@0 | 342 | # define BEGIN if (_current_step == 0) { _current_step = 1; |
aoqi@0 | 343 | # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s; |
aoqi@0 | 344 | # define END } |
aoqi@0 | 345 | |
aoqi@0 | 346 | // don't allocate large buffer on stack |
aoqi@0 | 347 | static char buf[O_BUFLEN]; |
aoqi@0 | 348 | |
aoqi@0 | 349 | BEGIN |
aoqi@0 | 350 | |
aoqi@0 | 351 | STEP(10, "(printing fatal error message)") |
aoqi@0 | 352 | |
aoqi@0 | 353 | st->print_cr("#"); |
aoqi@0 | 354 | if (should_report_bug(_id)) { |
aoqi@0 | 355 | st->print_cr("# A fatal error has been detected by the Java Runtime Environment:"); |
aoqi@0 | 356 | } else { |
aoqi@0 | 357 | st->print_cr("# There is insufficient memory for the Java " |
aoqi@0 | 358 | "Runtime Environment to continue."); |
aoqi@0 | 359 | } |
aoqi@0 | 360 | |
aoqi@0 | 361 | STEP(15, "(printing type of error)") |
aoqi@0 | 362 | |
aoqi@0 | 363 | switch(_id) { |
aoqi@0 | 364 | case OOM_MALLOC_ERROR: |
aoqi@0 | 365 | case OOM_MMAP_ERROR: |
aoqi@0 | 366 | if (_size) { |
aoqi@0 | 367 | st->print("# Native memory allocation "); |
aoqi@0 | 368 | st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " : |
aoqi@0 | 369 | "(mmap) failed to map "); |
aoqi@0 | 370 | jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size); |
aoqi@0 | 371 | st->print("%s", buf); |
aoqi@0 | 372 | st->print(" bytes"); |
aoqi@0 | 373 | if (_message != NULL) { |
aoqi@0 | 374 | st->print(" for "); |
aoqi@0 | 375 | st->print("%s", _message); |
aoqi@0 | 376 | } |
aoqi@0 | 377 | st->cr(); |
aoqi@0 | 378 | } else { |
aoqi@0 | 379 | if (_message != NULL) |
aoqi@0 | 380 | st->print("# "); |
aoqi@0 | 381 | st->print_cr("%s", _message); |
aoqi@0 | 382 | } |
aoqi@0 | 383 | // In error file give some solutions |
aoqi@0 | 384 | if (_verbose) { |
aoqi@0 | 385 | st->print_cr("# Possible reasons:"); |
aoqi@0 | 386 | st->print_cr("# The system is out of physical RAM or swap space"); |
aoqi@0 | 387 | st->print_cr("# In 32 bit mode, the process size limit was hit"); |
aoqi@0 | 388 | st->print_cr("# Possible solutions:"); |
aoqi@0 | 389 | st->print_cr("# Reduce memory load on the system"); |
aoqi@0 | 390 | st->print_cr("# Increase physical memory or swap space"); |
aoqi@0 | 391 | st->print_cr("# Check if swap backing store is full"); |
aoqi@0 | 392 | st->print_cr("# Use 64 bit Java on a 64 bit OS"); |
aoqi@0 | 393 | st->print_cr("# Decrease Java heap size (-Xmx/-Xms)"); |
aoqi@0 | 394 | st->print_cr("# Decrease number of Java threads"); |
aoqi@0 | 395 | st->print_cr("# Decrease Java thread stack sizes (-Xss)"); |
aoqi@0 | 396 | st->print_cr("# Set larger code cache with -XX:ReservedCodeCacheSize="); |
aoqi@0 | 397 | st->print_cr("# This output file may be truncated or incomplete."); |
aoqi@0 | 398 | } else { |
aoqi@0 | 399 | return; // that's enough for the screen |
aoqi@0 | 400 | } |
aoqi@0 | 401 | break; |
aoqi@0 | 402 | case INTERNAL_ERROR: |
aoqi@0 | 403 | default: |
aoqi@0 | 404 | break; |
aoqi@0 | 405 | } |
aoqi@0 | 406 | |
aoqi@0 | 407 | STEP(20, "(printing exception/signal name)") |
aoqi@0 | 408 | |
aoqi@0 | 409 | st->print_cr("#"); |
aoqi@0 | 410 | st->print("# "); |
aoqi@0 | 411 | // Is it an OS exception/signal? |
aoqi@0 | 412 | if (os::exception_name(_id, buf, sizeof(buf))) { |
aoqi@0 | 413 | st->print("%s", buf); |
aoqi@0 | 414 | st->print(" (0x%x)", _id); // signal number |
aoqi@0 | 415 | st->print(" at pc=" PTR_FORMAT, _pc); |
aoqi@0 | 416 | } else { |
aoqi@0 | 417 | if (should_report_bug(_id)) { |
aoqi@0 | 418 | st->print("Internal Error"); |
aoqi@0 | 419 | } else { |
aoqi@0 | 420 | st->print("Out of Memory Error"); |
aoqi@0 | 421 | } |
aoqi@0 | 422 | if (_filename != NULL && _lineno > 0) { |
aoqi@0 | 423 | #ifdef PRODUCT |
aoqi@0 | 424 | // In product mode chop off pathname? |
aoqi@0 | 425 | char separator = os::file_separator()[0]; |
aoqi@0 | 426 | const char *p = strrchr(_filename, separator); |
aoqi@0 | 427 | const char *file = p ? p+1 : _filename; |
aoqi@0 | 428 | #else |
aoqi@0 | 429 | const char *file = _filename; |
aoqi@0 | 430 | #endif |
aoqi@0 | 431 | size_t len = strlen(file); |
aoqi@0 | 432 | size_t buflen = sizeof(buf); |
aoqi@0 | 433 | |
aoqi@0 | 434 | strncpy(buf, file, buflen); |
aoqi@0 | 435 | if (len + 10 < buflen) { |
aoqi@0 | 436 | sprintf(buf + len, ":%d", _lineno); |
aoqi@0 | 437 | } |
aoqi@0 | 438 | st->print(" (%s)", buf); |
aoqi@0 | 439 | } else { |
aoqi@0 | 440 | st->print(" (0x%x)", _id); |
aoqi@0 | 441 | } |
aoqi@0 | 442 | } |
aoqi@0 | 443 | |
aoqi@0 | 444 | STEP(30, "(printing current thread and pid)") |
aoqi@0 | 445 | |
aoqi@0 | 446 | // process id, thread id |
aoqi@0 | 447 | st->print(", pid=%d", os::current_process_id()); |
dbuck@8186 | 448 | st->print(", tid=" INTPTR_FORMAT, os::current_thread_id()); |
aoqi@0 | 449 | st->cr(); |
aoqi@0 | 450 | |
aoqi@0 | 451 | STEP(40, "(printing error message)") |
aoqi@0 | 452 | |
aoqi@0 | 453 | if (should_report_bug(_id)) { // already printed the message. |
aoqi@0 | 454 | // error message |
aoqi@0 | 455 | if (_detail_msg) { |
aoqi@0 | 456 | st->print_cr("# %s: %s", _message ? _message : "Error", _detail_msg); |
aoqi@0 | 457 | } else if (_message) { |
aoqi@0 | 458 | st->print_cr("# Error: %s", _message); |
aoqi@0 | 459 | } |
aoqi@0 | 460 | } |
aoqi@0 | 461 | |
aoqi@0 | 462 | STEP(50, "(printing Java version string)") |
aoqi@0 | 463 | |
aoqi@0 | 464 | // VM version |
aoqi@0 | 465 | st->print_cr("#"); |
aoqi@0 | 466 | JDK_Version::current().to_string(buf, sizeof(buf)); |
aoqi@0 | 467 | const char* runtime_name = JDK_Version::runtime_name() != NULL ? |
aoqi@0 | 468 | JDK_Version::runtime_name() : ""; |
aoqi@0 | 469 | const char* runtime_version = JDK_Version::runtime_version() != NULL ? |
aoqi@0 | 470 | JDK_Version::runtime_version() : ""; |
aoqi@9137 | 471 | #ifdef LOONGSON_RUNTIME_NAME |
aoqi@9137 | 472 | const char* loongson_runtime_name_and_version = LOONGSON_RUNTIME_NAME; |
aoqi@9137 | 473 | #else |
aoqi@9137 | 474 | const char* loongson_runtime_name_and_version = ""; |
aoqi@9137 | 475 | #endif |
aoqi@9137 | 476 | st->print_cr("# JRE version: %s (%s) (build %s) (%s)", runtime_name, buf, runtime_version, loongson_runtime_name_and_version); |
aoqi@0 | 477 | st->print_cr("# Java VM: %s (%s %s %s %s)", |
aoqi@0 | 478 | Abstract_VM_Version::vm_name(), |
aoqi@0 | 479 | Abstract_VM_Version::vm_release(), |
aoqi@0 | 480 | Abstract_VM_Version::vm_info_string(), |
aoqi@0 | 481 | Abstract_VM_Version::vm_platform_string(), |
aoqi@0 | 482 | UseCompressedOops ? "compressed oops" : "" |
aoqi@0 | 483 | ); |
aoqi@0 | 484 | |
aoqi@0 | 485 | STEP(60, "(printing problematic frame)") |
aoqi@0 | 486 | |
aoqi@0 | 487 | // Print current frame if we have a context (i.e. it's a crash) |
aoqi@0 | 488 | if (_context) { |
aoqi@0 | 489 | st->print_cr("# Problematic frame:"); |
aoqi@0 | 490 | st->print("# "); |
aoqi@0 | 491 | frame fr = os::fetch_frame_from_context(_context); |
aoqi@0 | 492 | fr.print_on_error(st, buf, sizeof(buf)); |
aoqi@0 | 493 | st->cr(); |
aoqi@0 | 494 | st->print_cr("#"); |
aoqi@0 | 495 | } |
aoqi@0 | 496 | STEP(63, "(printing core file information)") |
aoqi@0 | 497 | st->print("# "); |
aoqi@0 | 498 | if (coredump_status) { |
aoqi@0 | 499 | st->print("Core dump written. Default location: %s", coredump_message); |
aoqi@0 | 500 | } else { |
aoqi@0 | 501 | st->print("Failed to write core dump. %s", coredump_message); |
aoqi@0 | 502 | } |
aoqi@0 | 503 | st->cr(); |
aoqi@0 | 504 | st->print_cr("#"); |
aoqi@0 | 505 | |
aoqi@0 | 506 | STEP(65, "(printing bug submit message)") |
aoqi@0 | 507 | |
aoqi@0 | 508 | if (should_report_bug(_id) && _verbose) { |
aoqi@0 | 509 | print_bug_submit_message(st, _thread); |
aoqi@0 | 510 | } |
aoqi@0 | 511 | |
aoqi@0 | 512 | STEP(70, "(printing thread)" ) |
aoqi@0 | 513 | |
aoqi@0 | 514 | if (_verbose) { |
aoqi@0 | 515 | st->cr(); |
aoqi@0 | 516 | st->print_cr("--------------- T H R E A D ---------------"); |
aoqi@0 | 517 | st->cr(); |
aoqi@0 | 518 | } |
aoqi@0 | 519 | |
aoqi@0 | 520 | STEP(80, "(printing current thread)" ) |
aoqi@0 | 521 | |
aoqi@0 | 522 | // current thread |
aoqi@0 | 523 | if (_verbose) { |
aoqi@0 | 524 | if (_thread) { |
aoqi@0 | 525 | st->print("Current thread (" PTR_FORMAT "): ", _thread); |
aoqi@0 | 526 | _thread->print_on_error(st, buf, sizeof(buf)); |
aoqi@0 | 527 | st->cr(); |
aoqi@0 | 528 | } else { |
aoqi@0 | 529 | st->print_cr("Current thread is native thread"); |
aoqi@0 | 530 | } |
aoqi@0 | 531 | st->cr(); |
aoqi@0 | 532 | } |
aoqi@0 | 533 | |
aoqi@0 | 534 | STEP(90, "(printing siginfo)" ) |
aoqi@0 | 535 | |
aoqi@0 | 536 | // signal no, signal code, address that caused the fault |
aoqi@0 | 537 | if (_verbose && _siginfo) { |
aoqi@0 | 538 | os::print_siginfo(st, _siginfo); |
aoqi@0 | 539 | st->cr(); |
aoqi@0 | 540 | } |
aoqi@0 | 541 | |
aoqi@0 | 542 | STEP(100, "(printing registers, top of stack, instructions near pc)") |
aoqi@0 | 543 | |
aoqi@0 | 544 | // registers, top of stack, instructions near pc |
aoqi@0 | 545 | if (_verbose && _context) { |
aoqi@0 | 546 | os::print_context(st, _context); |
aoqi@0 | 547 | st->cr(); |
aoqi@0 | 548 | } |
aoqi@0 | 549 | |
aoqi@0 | 550 | STEP(105, "(printing register info)") |
aoqi@0 | 551 | |
aoqi@0 | 552 | // decode register contents if possible |
aoqi@0 | 553 | if (_verbose && _context && Universe::is_fully_initialized()) { |
aoqi@0 | 554 | os::print_register_info(st, _context); |
aoqi@0 | 555 | st->cr(); |
aoqi@0 | 556 | } |
aoqi@0 | 557 | |
aoqi@0 | 558 | STEP(110, "(printing stack bounds)" ) |
aoqi@0 | 559 | |
aoqi@0 | 560 | if (_verbose) { |
aoqi@0 | 561 | st->print("Stack: "); |
aoqi@0 | 562 | |
aoqi@0 | 563 | address stack_top; |
aoqi@0 | 564 | size_t stack_size; |
aoqi@0 | 565 | |
aoqi@0 | 566 | if (_thread) { |
aoqi@0 | 567 | stack_top = _thread->stack_base(); |
aoqi@0 | 568 | stack_size = _thread->stack_size(); |
aoqi@0 | 569 | } else { |
aoqi@0 | 570 | stack_top = os::current_stack_base(); |
aoqi@0 | 571 | stack_size = os::current_stack_size(); |
aoqi@0 | 572 | } |
aoqi@0 | 573 | |
aoqi@0 | 574 | address stack_bottom = stack_top - stack_size; |
aoqi@0 | 575 | st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top); |
aoqi@0 | 576 | |
aoqi@0 | 577 | frame fr = _context ? os::fetch_frame_from_context(_context) |
aoqi@0 | 578 | : os::current_frame(); |
aoqi@0 | 579 | |
aoqi@0 | 580 | if (fr.sp()) { |
aoqi@0 | 581 | st->print(", sp=" PTR_FORMAT, fr.sp()); |
aoqi@0 | 582 | size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024); |
aoqi@0 | 583 | st->print(", free space=" SIZE_FORMAT "k", free_stack_size); |
aoqi@0 | 584 | } |
aoqi@0 | 585 | |
aoqi@0 | 586 | st->cr(); |
aoqi@0 | 587 | } |
aoqi@0 | 588 | |
aoqi@0 | 589 | STEP(120, "(printing native stack)" ) |
aoqi@0 | 590 | |
simonis@7553 | 591 | if (_verbose) { |
aoqi@0 | 592 | if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) { |
aoqi@0 | 593 | // We have printed the native stack in platform-specific code |
aoqi@0 | 594 | // Windows/x64 needs special handling. |
aoqi@0 | 595 | } else { |
aoqi@0 | 596 | frame fr = _context ? os::fetch_frame_from_context(_context) |
aoqi@0 | 597 | : os::current_frame(); |
aoqi@0 | 598 | |
simonis@7553 | 599 | print_native_stack(st, fr, _thread, buf, sizeof(buf)); |
aoqi@0 | 600 | } |
aoqi@0 | 601 | } |
aoqi@0 | 602 | |
aoqi@0 | 603 | STEP(130, "(printing Java stack)" ) |
aoqi@0 | 604 | |
aoqi@0 | 605 | if (_verbose && _thread && _thread->is_Java_thread()) { |
aoqi@0 | 606 | print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf)); |
aoqi@0 | 607 | } |
aoqi@0 | 608 | |
aoqi@0 | 609 | STEP(135, "(printing target Java thread stack)" ) |
aoqi@0 | 610 | |
aoqi@0 | 611 | // printing Java thread stack trace if it is involved in GC crash |
aoqi@0 | 612 | if (_verbose && _thread && (_thread->is_Named_thread())) { |
aoqi@0 | 613 | JavaThread* jt = ((NamedThread *)_thread)->processed_thread(); |
aoqi@0 | 614 | if (jt != NULL) { |
aoqi@0 | 615 | st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id()); |
aoqi@0 | 616 | print_stack_trace(st, jt, buf, sizeof(buf), true); |
aoqi@0 | 617 | } |
aoqi@0 | 618 | } |
aoqi@0 | 619 | |
aoqi@0 | 620 | STEP(140, "(printing VM operation)" ) |
aoqi@0 | 621 | |
aoqi@0 | 622 | if (_verbose && _thread && _thread->is_VM_thread()) { |
aoqi@0 | 623 | VMThread* t = (VMThread*)_thread; |
aoqi@0 | 624 | VM_Operation* op = t->vm_operation(); |
aoqi@0 | 625 | if (op) { |
aoqi@0 | 626 | op->print_on_error(st); |
aoqi@0 | 627 | st->cr(); |
aoqi@0 | 628 | st->cr(); |
aoqi@0 | 629 | } |
aoqi@0 | 630 | } |
aoqi@0 | 631 | |
aoqi@0 | 632 | STEP(150, "(printing current compile task)" ) |
aoqi@0 | 633 | |
aoqi@0 | 634 | if (_verbose && _thread && _thread->is_Compiler_thread()) { |
aoqi@0 | 635 | CompilerThread* t = (CompilerThread*)_thread; |
aoqi@0 | 636 | if (t->task()) { |
aoqi@0 | 637 | st->cr(); |
aoqi@0 | 638 | st->print_cr("Current CompileTask:"); |
aoqi@0 | 639 | t->task()->print_line_on_error(st, buf, sizeof(buf)); |
aoqi@0 | 640 | st->cr(); |
aoqi@0 | 641 | } |
aoqi@0 | 642 | } |
aoqi@0 | 643 | |
aoqi@0 | 644 | STEP(160, "(printing process)" ) |
aoqi@0 | 645 | |
aoqi@0 | 646 | if (_verbose) { |
aoqi@0 | 647 | st->cr(); |
aoqi@0 | 648 | st->print_cr("--------------- P R O C E S S ---------------"); |
aoqi@0 | 649 | st->cr(); |
aoqi@0 | 650 | } |
aoqi@0 | 651 | |
aoqi@0 | 652 | STEP(170, "(printing all threads)" ) |
aoqi@0 | 653 | |
aoqi@0 | 654 | // all threads |
aoqi@0 | 655 | if (_verbose && _thread) { |
aoqi@0 | 656 | Threads::print_on_error(st, _thread, buf, sizeof(buf)); |
aoqi@0 | 657 | st->cr(); |
aoqi@0 | 658 | } |
aoqi@0 | 659 | |
aoqi@0 | 660 | STEP(175, "(printing VM state)" ) |
aoqi@0 | 661 | |
aoqi@0 | 662 | if (_verbose) { |
aoqi@0 | 663 | // Safepoint state |
aoqi@0 | 664 | st->print("VM state:"); |
aoqi@0 | 665 | |
aoqi@0 | 666 | if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing"); |
aoqi@0 | 667 | else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint"); |
aoqi@0 | 668 | else st->print("not at safepoint"); |
aoqi@0 | 669 | |
aoqi@0 | 670 | // Also see if error occurred during initialization or shutdown |
aoqi@0 | 671 | if (!Universe::is_fully_initialized()) { |
aoqi@0 | 672 | st->print(" (not fully initialized)"); |
aoqi@0 | 673 | } else if (VM_Exit::vm_exited()) { |
aoqi@0 | 674 | st->print(" (shutting down)"); |
aoqi@0 | 675 | } else { |
aoqi@0 | 676 | st->print(" (normal execution)"); |
aoqi@0 | 677 | } |
aoqi@0 | 678 | st->cr(); |
aoqi@0 | 679 | st->cr(); |
aoqi@0 | 680 | } |
aoqi@0 | 681 | |
aoqi@0 | 682 | STEP(180, "(printing owned locks on error)" ) |
aoqi@0 | 683 | |
aoqi@0 | 684 | // mutexes/monitors that currently have an owner |
aoqi@0 | 685 | if (_verbose) { |
aoqi@0 | 686 | print_owned_locks_on_error(st); |
aoqi@0 | 687 | st->cr(); |
aoqi@0 | 688 | } |
aoqi@0 | 689 | |
aoqi@0 | 690 | STEP(190, "(printing heap information)" ) |
aoqi@0 | 691 | |
aoqi@0 | 692 | if (_verbose && Universe::is_fully_initialized()) { |
aoqi@0 | 693 | Universe::heap()->print_on_error(st); |
aoqi@0 | 694 | st->cr(); |
aoqi@0 | 695 | |
aoqi@0 | 696 | st->print_cr("Polling page: " INTPTR_FORMAT, os::get_polling_page()); |
aoqi@0 | 697 | st->cr(); |
aoqi@0 | 698 | } |
aoqi@0 | 699 | |
aoqi@0 | 700 | STEP(195, "(printing code cache information)" ) |
aoqi@0 | 701 | |
aoqi@0 | 702 | if (_verbose && Universe::is_fully_initialized()) { |
aoqi@0 | 703 | // print code cache information before vm abort |
aoqi@0 | 704 | CodeCache::print_summary(st); |
aoqi@0 | 705 | st->cr(); |
aoqi@0 | 706 | } |
aoqi@0 | 707 | |
aoqi@0 | 708 | STEP(200, "(printing ring buffers)" ) |
aoqi@0 | 709 | |
aoqi@0 | 710 | if (_verbose) { |
aoqi@0 | 711 | Events::print_all(st); |
aoqi@0 | 712 | st->cr(); |
aoqi@0 | 713 | } |
aoqi@0 | 714 | |
aoqi@0 | 715 | STEP(205, "(printing dynamic libraries)" ) |
aoqi@0 | 716 | |
aoqi@0 | 717 | if (_verbose) { |
aoqi@0 | 718 | // dynamic libraries, or memory map |
aoqi@0 | 719 | os::print_dll_info(st); |
aoqi@0 | 720 | st->cr(); |
aoqi@0 | 721 | } |
aoqi@0 | 722 | |
aoqi@0 | 723 | STEP(210, "(printing VM options)" ) |
aoqi@0 | 724 | |
aoqi@0 | 725 | if (_verbose) { |
aoqi@0 | 726 | // VM options |
aoqi@0 | 727 | Arguments::print_on(st); |
aoqi@0 | 728 | st->cr(); |
aoqi@0 | 729 | } |
aoqi@0 | 730 | |
aoqi@0 | 731 | STEP(215, "(printing warning if internal testing API used)" ) |
aoqi@0 | 732 | |
aoqi@0 | 733 | if (WhiteBox::used()) { |
aoqi@0 | 734 | st->print_cr("Unsupported internal testing APIs have been used."); |
aoqi@0 | 735 | st->cr(); |
aoqi@0 | 736 | } |
aoqi@0 | 737 | |
aoqi@0 | 738 | STEP(220, "(printing environment variables)" ) |
aoqi@0 | 739 | |
aoqi@0 | 740 | if (_verbose) { |
aoqi@0 | 741 | os::print_environment_variables(st, env_list, buf, sizeof(buf)); |
aoqi@0 | 742 | st->cr(); |
aoqi@0 | 743 | } |
aoqi@0 | 744 | |
aoqi@0 | 745 | STEP(225, "(printing signal handlers)" ) |
aoqi@0 | 746 | |
aoqi@0 | 747 | if (_verbose) { |
aoqi@0 | 748 | os::print_signal_handlers(st, buf, sizeof(buf)); |
aoqi@0 | 749 | st->cr(); |
aoqi@0 | 750 | } |
aoqi@0 | 751 | |
zgu@7074 | 752 | STEP(228, "(Native Memory Tracking)" ) |
zgu@7074 | 753 | if (_verbose) { |
coleenp@7267 | 754 | MemTracker::error_report(st); |
zgu@7074 | 755 | } |
zgu@7074 | 756 | |
aoqi@0 | 757 | STEP(230, "" ) |
aoqi@0 | 758 | |
aoqi@0 | 759 | if (_verbose) { |
aoqi@0 | 760 | st->cr(); |
aoqi@0 | 761 | st->print_cr("--------------- S Y S T E M ---------------"); |
aoqi@0 | 762 | st->cr(); |
aoqi@0 | 763 | } |
aoqi@0 | 764 | |
aoqi@0 | 765 | STEP(240, "(printing OS information)" ) |
aoqi@0 | 766 | |
aoqi@0 | 767 | if (_verbose) { |
aoqi@0 | 768 | os::print_os_info(st); |
aoqi@0 | 769 | st->cr(); |
aoqi@0 | 770 | } |
aoqi@0 | 771 | |
aoqi@0 | 772 | STEP(250, "(printing CPU info)" ) |
aoqi@0 | 773 | if (_verbose) { |
aoqi@0 | 774 | os::print_cpu_info(st); |
aoqi@0 | 775 | st->cr(); |
aoqi@0 | 776 | } |
aoqi@0 | 777 | |
aoqi@0 | 778 | STEP(260, "(printing memory info)" ) |
aoqi@0 | 779 | |
aoqi@0 | 780 | if (_verbose) { |
aoqi@0 | 781 | os::print_memory_info(st); |
aoqi@0 | 782 | st->cr(); |
aoqi@0 | 783 | } |
aoqi@0 | 784 | |
aoqi@0 | 785 | STEP(270, "(printing internal vm info)" ) |
aoqi@0 | 786 | |
aoqi@0 | 787 | if (_verbose) { |
aoqi@0 | 788 | st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string()); |
aoqi@0 | 789 | st->cr(); |
aoqi@0 | 790 | } |
aoqi@0 | 791 | |
aoqi@0 | 792 | STEP(280, "(printing date and time)" ) |
aoqi@0 | 793 | |
aoqi@0 | 794 | if (_verbose) { |
aoqi@0 | 795 | os::print_date_and_time(st); |
aoqi@0 | 796 | st->cr(); |
aoqi@0 | 797 | } |
aoqi@0 | 798 | |
aoqi@0 | 799 | END |
aoqi@0 | 800 | |
aoqi@0 | 801 | # undef BEGIN |
aoqi@0 | 802 | # undef STEP |
aoqi@0 | 803 | # undef END |
aoqi@0 | 804 | } |
aoqi@0 | 805 | |
aoqi@0 | 806 | VMError* volatile VMError::first_error = NULL; |
aoqi@0 | 807 | volatile jlong VMError::first_error_tid = -1; |
aoqi@0 | 808 | |
aoqi@0 | 809 | // An error could happen before tty is initialized or after it has been |
aoqi@0 | 810 | // destroyed. Here we use a very simple unbuffered fdStream for printing. |
aoqi@0 | 811 | // Only out.print_raw() and out.print_raw_cr() should be used, as other |
aoqi@0 | 812 | // printing methods need to allocate large buffer on stack. To format a |
aoqi@0 | 813 | // string, use jio_snprintf() with a static buffer or use staticBufferStream. |
aoqi@0 | 814 | fdStream VMError::out(defaultStream::output_fd()); |
aoqi@0 | 815 | fdStream VMError::log; // error log used by VMError::report_and_die() |
aoqi@0 | 816 | |
aoqi@0 | 817 | /** Expand a pattern into a buffer starting at pos and open a file using constructed path */ |
aoqi@0 | 818 | static int expand_and_open(const char* pattern, char* buf, size_t buflen, size_t pos) { |
aoqi@0 | 819 | int fd = -1; |
aoqi@0 | 820 | if (Arguments::copy_expand_pid(pattern, strlen(pattern), &buf[pos], buflen - pos)) { |
gthornbr@7493 | 821 | // the O_EXCL flag will cause the open to fail if the file exists |
gthornbr@7493 | 822 | fd = open(buf, O_RDWR | O_CREAT | O_EXCL, 0666); |
aoqi@0 | 823 | } |
aoqi@0 | 824 | return fd; |
aoqi@0 | 825 | } |
aoqi@0 | 826 | |
aoqi@0 | 827 | /** |
aoqi@0 | 828 | * Construct file name for a log file and return it's file descriptor. |
aoqi@0 | 829 | * Name and location depends on pattern, default_pattern params and access |
aoqi@0 | 830 | * permissions. |
aoqi@0 | 831 | */ |
aoqi@0 | 832 | static int prepare_log_file(const char* pattern, const char* default_pattern, char* buf, size_t buflen) { |
aoqi@0 | 833 | int fd = -1; |
aoqi@0 | 834 | |
aoqi@0 | 835 | // If possible, use specified pattern to construct log file name |
aoqi@0 | 836 | if (pattern != NULL) { |
aoqi@0 | 837 | fd = expand_and_open(pattern, buf, buflen, 0); |
aoqi@0 | 838 | } |
aoqi@0 | 839 | |
aoqi@0 | 840 | // Either user didn't specify, or the user's location failed, |
aoqi@0 | 841 | // so use the default name in the current directory |
aoqi@0 | 842 | if (fd == -1) { |
aoqi@0 | 843 | const char* cwd = os::get_current_directory(buf, buflen); |
aoqi@0 | 844 | if (cwd != NULL) { |
aoqi@0 | 845 | size_t pos = strlen(cwd); |
aoqi@0 | 846 | int fsep_len = jio_snprintf(&buf[pos], buflen-pos, "%s", os::file_separator()); |
aoqi@0 | 847 | pos += fsep_len; |
aoqi@0 | 848 | if (fsep_len > 0) { |
aoqi@0 | 849 | fd = expand_and_open(default_pattern, buf, buflen, pos); |
aoqi@0 | 850 | } |
aoqi@0 | 851 | } |
aoqi@0 | 852 | } |
aoqi@0 | 853 | |
aoqi@0 | 854 | // try temp directory if it exists. |
aoqi@0 | 855 | if (fd == -1) { |
aoqi@0 | 856 | const char* tmpdir = os::get_temp_directory(); |
aoqi@0 | 857 | if (tmpdir != NULL && strlen(tmpdir) > 0) { |
aoqi@0 | 858 | int pos = jio_snprintf(buf, buflen, "%s%s", tmpdir, os::file_separator()); |
aoqi@0 | 859 | if (pos > 0) { |
aoqi@0 | 860 | fd = expand_and_open(default_pattern, buf, buflen, pos); |
aoqi@0 | 861 | } |
aoqi@0 | 862 | } |
aoqi@0 | 863 | } |
aoqi@0 | 864 | |
aoqi@0 | 865 | return fd; |
aoqi@0 | 866 | } |
aoqi@0 | 867 | |
aoqi@0 | 868 | void VMError::report_and_die() { |
aoqi@0 | 869 | // Don't allocate large buffer on stack |
aoqi@0 | 870 | static char buffer[O_BUFLEN]; |
aoqi@0 | 871 | |
aoqi@0 | 872 | // How many errors occurred in error handler when reporting first_error. |
aoqi@0 | 873 | static int recursive_error_count; |
aoqi@0 | 874 | |
aoqi@0 | 875 | // We will first print a brief message to standard out (verbose = false), |
aoqi@0 | 876 | // then save detailed information in log file (verbose = true). |
aoqi@0 | 877 | static bool out_done = false; // done printing to standard out |
aoqi@0 | 878 | static bool log_done = false; // done saving error log |
aoqi@0 | 879 | static bool transmit_report_done = false; // done error reporting |
aoqi@0 | 880 | |
aoqi@0 | 881 | if (SuppressFatalErrorMessage) { |
aoqi@0 | 882 | os::abort(); |
aoqi@0 | 883 | } |
aoqi@0 | 884 | jlong mytid = os::current_thread_id(); |
aoqi@0 | 885 | if (first_error == NULL && |
aoqi@0 | 886 | Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) { |
aoqi@0 | 887 | |
aoqi@0 | 888 | // first time |
aoqi@0 | 889 | first_error_tid = mytid; |
aoqi@0 | 890 | set_error_reported(); |
aoqi@0 | 891 | |
aoqi@0 | 892 | if (ShowMessageBoxOnError || PauseAtExit) { |
aoqi@0 | 893 | show_message_box(buffer, sizeof(buffer)); |
aoqi@0 | 894 | |
aoqi@0 | 895 | // User has asked JVM to abort. Reset ShowMessageBoxOnError so the |
aoqi@0 | 896 | // WatcherThread can kill JVM if the error handler hangs. |
aoqi@0 | 897 | ShowMessageBoxOnError = false; |
aoqi@0 | 898 | } |
aoqi@0 | 899 | |
aoqi@0 | 900 | // Write a minidump on Windows, check core dump limits on Linux/Solaris |
aoqi@0 | 901 | os::check_or_create_dump(_siginfo, _context, buffer, sizeof(buffer)); |
aoqi@0 | 902 | |
aoqi@0 | 903 | // reset signal handlers or exception filter; make sure recursive crashes |
aoqi@0 | 904 | // are handled properly. |
aoqi@0 | 905 | reset_signal_handlers(); |
aoqi@0 | 906 | |
aoqi@0 | 907 | } else { |
aoqi@0 | 908 | // If UseOsErrorReporting we call this for each level of the call stack |
aoqi@0 | 909 | // while searching for the exception handler. Only the first level needs |
aoqi@0 | 910 | // to be reported. |
aoqi@0 | 911 | if (UseOSErrorReporting && log_done) return; |
aoqi@0 | 912 | |
aoqi@0 | 913 | // This is not the first error, see if it happened in a different thread |
aoqi@0 | 914 | // or in the same thread during error reporting. |
aoqi@0 | 915 | if (first_error_tid != mytid) { |
aoqi@0 | 916 | char msgbuf[64]; |
aoqi@0 | 917 | jio_snprintf(msgbuf, sizeof(msgbuf), |
aoqi@0 | 918 | "[thread " INT64_FORMAT " also had an error]", |
aoqi@0 | 919 | mytid); |
aoqi@0 | 920 | out.print_raw_cr(msgbuf); |
aoqi@0 | 921 | |
aoqi@0 | 922 | // error reporting is not MT-safe, block current thread |
aoqi@0 | 923 | os::infinite_sleep(); |
aoqi@0 | 924 | |
aoqi@0 | 925 | } else { |
aoqi@0 | 926 | if (recursive_error_count++ > 30) { |
aoqi@0 | 927 | out.print_raw_cr("[Too many errors, abort]"); |
aoqi@0 | 928 | os::die(); |
aoqi@0 | 929 | } |
aoqi@0 | 930 | |
aoqi@0 | 931 | jio_snprintf(buffer, sizeof(buffer), |
aoqi@0 | 932 | "[error occurred during error reporting %s, id 0x%x]", |
aoqi@0 | 933 | first_error ? first_error->_current_step_info : "", |
aoqi@0 | 934 | _id); |
aoqi@0 | 935 | if (log.is_open()) { |
aoqi@0 | 936 | log.cr(); |
aoqi@0 | 937 | log.print_raw_cr(buffer); |
aoqi@0 | 938 | log.cr(); |
aoqi@0 | 939 | } else { |
aoqi@0 | 940 | out.cr(); |
aoqi@0 | 941 | out.print_raw_cr(buffer); |
aoqi@0 | 942 | out.cr(); |
aoqi@0 | 943 | } |
aoqi@0 | 944 | } |
aoqi@0 | 945 | } |
aoqi@0 | 946 | |
aoqi@0 | 947 | // print to screen |
aoqi@0 | 948 | if (!out_done) { |
aoqi@0 | 949 | first_error->_verbose = false; |
aoqi@0 | 950 | |
aoqi@0 | 951 | staticBufferStream sbs(buffer, sizeof(buffer), &out); |
aoqi@0 | 952 | first_error->report(&sbs); |
aoqi@0 | 953 | |
aoqi@0 | 954 | out_done = true; |
aoqi@0 | 955 | |
aoqi@0 | 956 | first_error->_current_step = 0; // reset current_step |
aoqi@0 | 957 | first_error->_current_step_info = ""; // reset current_step string |
aoqi@0 | 958 | } |
aoqi@0 | 959 | |
aoqi@0 | 960 | // print to error log file |
aoqi@0 | 961 | if (!log_done) { |
aoqi@0 | 962 | first_error->_verbose = true; |
aoqi@0 | 963 | |
aoqi@0 | 964 | // see if log file is already open |
aoqi@0 | 965 | if (!log.is_open()) { |
aoqi@0 | 966 | // open log file |
aoqi@0 | 967 | int fd = prepare_log_file(ErrorFile, "hs_err_pid%p.log", buffer, sizeof(buffer)); |
aoqi@0 | 968 | if (fd != -1) { |
aoqi@0 | 969 | out.print_raw("# An error report file with more information is saved as:\n# "); |
aoqi@0 | 970 | out.print_raw_cr(buffer); |
aoqi@0 | 971 | |
aoqi@0 | 972 | log.set_fd(fd); |
aoqi@0 | 973 | } else { |
aoqi@0 | 974 | out.print_raw_cr("# Can not save log file, dump to screen.."); |
aoqi@0 | 975 | log.set_fd(defaultStream::output_fd()); |
aoqi@0 | 976 | /* Error reporting currently needs dumpfile. |
aoqi@0 | 977 | * Maybe implement direct streaming in the future.*/ |
aoqi@0 | 978 | transmit_report_done = true; |
aoqi@0 | 979 | } |
aoqi@0 | 980 | } |
aoqi@0 | 981 | |
aoqi@0 | 982 | staticBufferStream sbs(buffer, O_BUFLEN, &log); |
aoqi@0 | 983 | first_error->report(&sbs); |
aoqi@0 | 984 | first_error->_current_step = 0; // reset current_step |
aoqi@0 | 985 | first_error->_current_step_info = ""; // reset current_step string |
aoqi@0 | 986 | |
aoqi@0 | 987 | // Run error reporting to determine whether or not to report the crash. |
aoqi@0 | 988 | if (!transmit_report_done && should_report_bug(first_error->_id)) { |
aoqi@0 | 989 | transmit_report_done = true; |
aoqi@0 | 990 | FILE* hs_err = os::open(log.fd(), "r"); |
aoqi@0 | 991 | if (NULL != hs_err) { |
aoqi@0 | 992 | ErrorReporter er; |
aoqi@0 | 993 | er.call(hs_err, buffer, O_BUFLEN); |
aoqi@0 | 994 | } |
aoqi@0 | 995 | } |
aoqi@0 | 996 | |
aoqi@0 | 997 | if (log.fd() != defaultStream::output_fd()) { |
aoqi@0 | 998 | close(log.fd()); |
aoqi@0 | 999 | } |
aoqi@0 | 1000 | |
aoqi@0 | 1001 | log.set_fd(-1); |
aoqi@0 | 1002 | log_done = true; |
aoqi@0 | 1003 | } |
aoqi@0 | 1004 | |
aoqi@0 | 1005 | |
aoqi@0 | 1006 | static bool skip_OnError = false; |
aoqi@0 | 1007 | if (!skip_OnError && OnError && OnError[0]) { |
aoqi@0 | 1008 | skip_OnError = true; |
aoqi@0 | 1009 | |
aoqi@0 | 1010 | out.print_raw_cr("#"); |
aoqi@0 | 1011 | out.print_raw ("# -XX:OnError=\""); |
aoqi@0 | 1012 | out.print_raw (OnError); |
aoqi@0 | 1013 | out.print_raw_cr("\""); |
aoqi@0 | 1014 | |
aoqi@0 | 1015 | char* cmd; |
aoqi@0 | 1016 | const char* ptr = OnError; |
aoqi@0 | 1017 | while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ |
aoqi@0 | 1018 | out.print_raw ("# Executing "); |
aoqi@0 | 1019 | #if defined(LINUX) || defined(_ALLBSD_SOURCE) |
aoqi@0 | 1020 | out.print_raw ("/bin/sh -c "); |
aoqi@0 | 1021 | #elif defined(SOLARIS) |
aoqi@0 | 1022 | out.print_raw ("/usr/bin/sh -c "); |
aoqi@0 | 1023 | #endif |
aoqi@0 | 1024 | out.print_raw ("\""); |
aoqi@0 | 1025 | out.print_raw (cmd); |
aoqi@0 | 1026 | out.print_raw_cr("\" ..."); |
aoqi@0 | 1027 | |
dholmes@7793 | 1028 | if (os::fork_and_exec(cmd) < 0) { |
dholmes@7793 | 1029 | out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); |
dholmes@7793 | 1030 | } |
aoqi@0 | 1031 | } |
aoqi@0 | 1032 | |
aoqi@0 | 1033 | // done with OnError |
aoqi@0 | 1034 | OnError = NULL; |
aoqi@0 | 1035 | } |
aoqi@0 | 1036 | |
aoqi@0 | 1037 | static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay |
aoqi@0 | 1038 | if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) { |
aoqi@0 | 1039 | skip_replay = true; |
aoqi@0 | 1040 | ciEnv* env = ciEnv::current(); |
aoqi@0 | 1041 | if (env != NULL) { |
aoqi@0 | 1042 | int fd = prepare_log_file(ReplayDataFile, "replay_pid%p.log", buffer, sizeof(buffer)); |
aoqi@0 | 1043 | if (fd != -1) { |
aoqi@0 | 1044 | FILE* replay_data_file = os::open(fd, "w"); |
aoqi@0 | 1045 | if (replay_data_file != NULL) { |
aoqi@0 | 1046 | fileStream replay_data_stream(replay_data_file, /*need_close=*/true); |
aoqi@0 | 1047 | env->dump_replay_data_unsafe(&replay_data_stream); |
aoqi@0 | 1048 | out.print_raw("#\n# Compiler replay data is saved as:\n# "); |
aoqi@0 | 1049 | out.print_raw_cr(buffer); |
aoqi@0 | 1050 | } else { |
aoqi@0 | 1051 | out.print_raw("#\n# Can't open file to dump replay data. Error: "); |
aoqi@0 | 1052 | out.print_raw_cr(strerror(os::get_last_error())); |
aoqi@0 | 1053 | } |
aoqi@0 | 1054 | } |
aoqi@0 | 1055 | } |
aoqi@0 | 1056 | } |
aoqi@0 | 1057 | |
aoqi@0 | 1058 | static bool skip_bug_url = !should_report_bug(first_error->_id); |
aoqi@0 | 1059 | if (!skip_bug_url) { |
aoqi@0 | 1060 | skip_bug_url = true; |
aoqi@0 | 1061 | |
aoqi@0 | 1062 | out.print_raw_cr("#"); |
aoqi@0 | 1063 | print_bug_submit_message(&out, _thread); |
aoqi@0 | 1064 | } |
aoqi@0 | 1065 | |
aoqi@0 | 1066 | if (!UseOSErrorReporting) { |
aoqi@0 | 1067 | // os::abort() will call abort hooks, try it first. |
aoqi@0 | 1068 | static bool skip_os_abort = false; |
aoqi@0 | 1069 | if (!skip_os_abort) { |
aoqi@0 | 1070 | skip_os_abort = true; |
aoqi@0 | 1071 | bool dump_core = should_report_bug(first_error->_id); |
aoqi@0 | 1072 | os::abort(dump_core); |
aoqi@0 | 1073 | } |
aoqi@0 | 1074 | |
aoqi@0 | 1075 | // if os::abort() doesn't abort, try os::die(); |
aoqi@0 | 1076 | os::die(); |
aoqi@0 | 1077 | } |
aoqi@0 | 1078 | } |
aoqi@0 | 1079 | |
aoqi@0 | 1080 | /* |
aoqi@0 | 1081 | * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this |
aoqi@0 | 1082 | * ensures utilities such as jmap can observe the process is a consistent state. |
aoqi@0 | 1083 | */ |
aoqi@0 | 1084 | class VM_ReportJavaOutOfMemory : public VM_Operation { |
aoqi@0 | 1085 | private: |
aoqi@0 | 1086 | VMError *_err; |
aoqi@0 | 1087 | public: |
aoqi@0 | 1088 | VM_ReportJavaOutOfMemory(VMError *err) { _err = err; } |
aoqi@0 | 1089 | VMOp_Type type() const { return VMOp_ReportJavaOutOfMemory; } |
aoqi@0 | 1090 | void doit(); |
aoqi@0 | 1091 | }; |
aoqi@0 | 1092 | |
aoqi@0 | 1093 | void VM_ReportJavaOutOfMemory::doit() { |
aoqi@0 | 1094 | // Don't allocate large buffer on stack |
aoqi@0 | 1095 | static char buffer[O_BUFLEN]; |
aoqi@0 | 1096 | |
aoqi@0 | 1097 | tty->print_cr("#"); |
aoqi@0 | 1098 | tty->print_cr("# java.lang.OutOfMemoryError: %s", _err->message()); |
aoqi@0 | 1099 | tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError); |
aoqi@0 | 1100 | |
aoqi@0 | 1101 | // make heap parsability |
aoqi@0 | 1102 | Universe::heap()->ensure_parsability(false); // no need to retire TLABs |
aoqi@0 | 1103 | |
aoqi@0 | 1104 | char* cmd; |
aoqi@0 | 1105 | const char* ptr = OnOutOfMemoryError; |
aoqi@0 | 1106 | while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ |
aoqi@0 | 1107 | tty->print("# Executing "); |
aoqi@0 | 1108 | #if defined(LINUX) |
aoqi@0 | 1109 | tty->print ("/bin/sh -c "); |
aoqi@0 | 1110 | #elif defined(SOLARIS) |
aoqi@0 | 1111 | tty->print ("/usr/bin/sh -c "); |
aoqi@0 | 1112 | #endif |
aoqi@0 | 1113 | tty->print_cr("\"%s\"...", cmd); |
aoqi@0 | 1114 | |
dholmes@7793 | 1115 | if (os::fork_and_exec(cmd) < 0) { |
dholmes@7793 | 1116 | tty->print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); |
dholmes@7793 | 1117 | } |
aoqi@0 | 1118 | } |
aoqi@0 | 1119 | } |
aoqi@0 | 1120 | |
aoqi@0 | 1121 | void VMError::report_java_out_of_memory() { |
aoqi@0 | 1122 | if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { |
aoqi@0 | 1123 | MutexLocker ml(Heap_lock); |
aoqi@0 | 1124 | VM_ReportJavaOutOfMemory op(this); |
aoqi@0 | 1125 | VMThread::execute(&op); |
aoqi@0 | 1126 | } |
aoqi@0 | 1127 | } |