src/share/vm/utilities/vmError.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6782
f73af4455d7d
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial