annotate src/share/vm/utilities/vmError.cpp @ 423:a1980da045cc

6462850: generate biased locking code in C2 ideal graph Summary: Inline biased locking code in C2 ideal graph during macro nodes expansion Reviewed-by: never
author kvn
date Fri, 07 Nov 2008 09:29:38 -0800
parents d1605aabd0a1
children 2159823957e1 3ad2b8576c4a
rev   line source
duke@0 1 /*
xdono@196 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_vmError.cpp.incl"
duke@0 27
duke@0 28 // List of environment variables that should be reported in error log file.
duke@0 29 const char *env_list[] = {
duke@0 30 // All platforms
duke@0 31 "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
duke@0 32 "JAVA_COMPILER", "PATH", "USERNAME",
duke@0 33
duke@0 34 // Env variables that are defined on Solaris/Linux
duke@0 35 "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
duke@0 36 "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
duke@0 37
duke@0 38 // defined on Linux
duke@0 39 "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
duke@0 40
duke@0 41 // defined on Windows
duke@0 42 "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
duke@0 43
duke@0 44 (const char *)0
duke@0 45 };
duke@0 46
duke@0 47 // Fatal error handler for internal errors and crashes.
duke@0 48 //
duke@0 49 // The default behavior of fatal error handler is to print a brief message
duke@0 50 // to standard out (defaultStream::output_fd()), then save detailed information
duke@0 51 // into an error report file (hs_err_pid<pid>.log) and abort VM. If multiple
duke@0 52 // threads are having troubles at the same time, only one error is reported.
duke@0 53 // The thread that is reporting error will abort VM when it is done, all other
duke@0 54 // threads are blocked forever inside report_and_die().
duke@0 55
duke@0 56 // Constructor for crashes
duke@0 57 VMError::VMError(Thread* thread, int sig, address pc, void* siginfo, void* context) {
duke@0 58 _thread = thread;
duke@0 59 _id = sig;
duke@0 60 _pc = pc;
duke@0 61 _siginfo = siginfo;
duke@0 62 _context = context;
duke@0 63
duke@0 64 _verbose = false;
duke@0 65 _current_step = 0;
duke@0 66 _current_step_info = NULL;
duke@0 67
duke@0 68 _message = "";
duke@0 69 _filename = NULL;
duke@0 70 _lineno = 0;
duke@0 71
duke@0 72 _size = 0;
duke@0 73 }
duke@0 74
duke@0 75 // Constructor for internal errors
duke@0 76 VMError::VMError(Thread* thread, const char* message, const char* filename, int lineno) {
duke@0 77 _thread = thread;
duke@0 78 _id = internal_error; // set it to a value that's not an OS exception/signal
duke@0 79 _filename = filename;
duke@0 80 _lineno = lineno;
duke@0 81 _message = message;
duke@0 82
duke@0 83 _verbose = false;
duke@0 84 _current_step = 0;
duke@0 85 _current_step_info = NULL;
duke@0 86
duke@0 87 _pc = NULL;
duke@0 88 _siginfo = NULL;
duke@0 89 _context = NULL;
duke@0 90
duke@0 91 _size = 0;
duke@0 92 }
duke@0 93
duke@0 94 // Constructor for OOM errors
duke@0 95 VMError::VMError(Thread* thread, size_t size, const char* message, const char* filename, int lineno) {
duke@0 96 _thread = thread;
duke@0 97 _id = oom_error; // set it to a value that's not an OS exception/signal
duke@0 98 _filename = filename;
duke@0 99 _lineno = lineno;
duke@0 100 _message = message;
duke@0 101
duke@0 102 _verbose = false;
duke@0 103 _current_step = 0;
duke@0 104 _current_step_info = NULL;
duke@0 105
duke@0 106 _pc = NULL;
duke@0 107 _siginfo = NULL;
duke@0 108 _context = NULL;
duke@0 109
duke@0 110 _size = size;
duke@0 111 }
duke@0 112
duke@0 113
duke@0 114 // Constructor for non-fatal errors
duke@0 115 VMError::VMError(const char* message) {
duke@0 116 _thread = NULL;
duke@0 117 _id = internal_error; // set it to a value that's not an OS exception/signal
duke@0 118 _filename = NULL;
duke@0 119 _lineno = 0;
duke@0 120 _message = message;
duke@0 121
duke@0 122 _verbose = false;
duke@0 123 _current_step = 0;
duke@0 124 _current_step_info = NULL;
duke@0 125
duke@0 126 _pc = NULL;
duke@0 127 _siginfo = NULL;
duke@0 128 _context = NULL;
duke@0 129
duke@0 130 _size = 0;
duke@0 131 }
duke@0 132
duke@0 133 // -XX:OnError=<string>, where <string> can be a list of commands, separated
duke@0 134 // by ';'. "%p" is replaced by current process id (pid); "%%" is replaced by
duke@0 135 // a single "%". Some examples:
duke@0 136 //
duke@0 137 // -XX:OnError="pmap %p" // show memory map
duke@0 138 // -XX:OnError="gcore %p; dbx - %p" // dump core and launch debugger
duke@0 139 // -XX:OnError="cat hs_err_pid%p.log | mail my_email@sun.com"
duke@0 140 // -XX:OnError="kill -9 %p" // ?#!@#
duke@0 141
duke@0 142 // A simple parser for -XX:OnError, usage:
duke@0 143 // ptr = OnError;
duke@0 144 // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL)
duke@0 145 // ... ...
duke@0 146 static char* next_OnError_command(char* buf, int buflen, const char** ptr) {
duke@0 147 if (ptr == NULL || *ptr == NULL) return NULL;
duke@0 148
duke@0 149 const char* cmd = *ptr;
duke@0 150
duke@0 151 // skip leading blanks or ';'
duke@0 152 while (*cmd == ' ' || *cmd == ';') cmd++;
duke@0 153
duke@0 154 if (*cmd == '\0') return NULL;
duke@0 155
duke@0 156 const char * cmdend = cmd;
duke@0 157 while (*cmdend != '\0' && *cmdend != ';') cmdend++;
duke@0 158
duke@0 159 Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen);
duke@0 160
duke@0 161 *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1);
duke@0 162 return buf;
duke@0 163 }
duke@0 164
duke@0 165
duke@0 166 static void print_bug_submit_message(outputStream *out, Thread *thread) {
duke@0 167 if (out == NULL) return;
duke@0 168 out->print_raw_cr("# If you would like to submit a bug report, please visit:");
duke@0 169 out->print_raw ("# ");
duke@0 170 out->print_raw_cr(Arguments::java_vendor_url_bug());
duke@0 171 // If the crash is in native code, encourage user to submit a bug to the
duke@0 172 // provider of that code.
coleenp@56 173 if (thread && thread->is_Java_thread() &&
coleenp@56 174 !thread->is_hidden_from_external_view()) {
duke@0 175 JavaThread* jt = (JavaThread*)thread;
duke@0 176 if (jt->thread_state() == _thread_in_native) {
duke@0 177 out->print_cr("# The crash happened outside the Java Virtual Machine in native code.\n# See problematic frame for where to report the bug.");
duke@0 178 }
duke@0 179 }
duke@0 180 out->print_raw_cr("#");
duke@0 181 }
duke@0 182
duke@0 183
duke@0 184 // Return a string to describe the error
duke@0 185 char* VMError::error_string(char* buf, int buflen) {
duke@0 186 char signame_buf[64];
duke@0 187 const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf));
duke@0 188
duke@0 189 if (signame) {
duke@0 190 jio_snprintf(buf, buflen,
duke@0 191 "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" UINTX_FORMAT,
duke@0 192 signame, _id, _pc,
duke@0 193 os::current_process_id(), os::current_thread_id());
duke@0 194 } else {
duke@0 195 if (_filename != NULL && _lineno > 0) {
duke@0 196 // skip directory names
duke@0 197 char separator = os::file_separator()[0];
duke@0 198 const char *p = strrchr(_filename, separator);
duke@0 199
duke@0 200 jio_snprintf(buf, buflen,
duke@0 201 "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT " \nError: %s",
duke@0 202 p ? p + 1 : _filename, _lineno,
duke@0 203 os::current_process_id(), os::current_thread_id(),
duke@0 204 _message ? _message : "");
duke@0 205 } else {
duke@0 206 jio_snprintf(buf, buflen,
duke@0 207 "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT,
duke@0 208 _id, os::current_process_id(), os::current_thread_id());
duke@0 209 }
duke@0 210 }
duke@0 211
duke@0 212 return buf;
duke@0 213 }
duke@0 214
duke@0 215
duke@0 216 // This is the main function to report a fatal error. Only one thread can
duke@0 217 // call this function, so we don't need to worry about MT-safety. But it's
duke@0 218 // possible that the error handler itself may crash or die on an internal
duke@0 219 // error, for example, when the stack/heap is badly damaged. We must be
duke@0 220 // able to handle recursive errors that happen inside error handler.
duke@0 221 //
duke@0 222 // Error reporting is done in several steps. If a crash or internal error
duke@0 223 // occurred when reporting an error, the nested signal/exception handler
duke@0 224 // can skip steps that are already (or partially) done. Error reporting will
duke@0 225 // continue from the next step. This allows us to retrieve and print
duke@0 226 // information that may be unsafe to get after a fatal error. If it happens,
duke@0 227 // you may find nested report_and_die() frames when you look at the stack
duke@0 228 // in a debugger.
duke@0 229 //
duke@0 230 // In general, a hang in error handler is much worse than a crash or internal
duke@0 231 // error, as it's harder to recover from a hang. Deadlock can happen if we
duke@0 232 // try to grab a lock that is already owned by current thread, or if the
duke@0 233 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
duke@0 234 // error handler and all the functions it called should avoid grabbing any
duke@0 235 // lock. An important thing to notice is that memory allocation needs a lock.
duke@0 236 //
duke@0 237 // We should avoid using large stack allocated buffers. Many errors happen
duke@0 238 // when stack space is already low. Making things even worse is that there
duke@0 239 // could be nested report_and_die() calls on stack (see above). Only one
duke@0 240 // thread can report error, so large buffers are statically allocated in data
duke@0 241 // segment.
duke@0 242
duke@0 243 void VMError::report(outputStream* st) {
duke@0 244 # define BEGIN if (_current_step == 0) { _current_step = 1;
duke@0 245 # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s;
duke@0 246 # define END }
duke@0 247
duke@0 248 // don't allocate large buffer on stack
duke@0 249 static char buf[O_BUFLEN];
duke@0 250
duke@0 251 BEGIN
duke@0 252
coleenp@56 253 STEP(10, "(printing fatal error message)")
duke@0 254
duke@0 255 st->print_cr("#");
coleenp@56 256 st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
duke@0 257
duke@0 258 STEP(15, "(printing type of error)")
duke@0 259
duke@0 260 switch(_id) {
duke@0 261 case oom_error:
duke@0 262 st->print_cr("#");
duke@0 263 st->print("# java.lang.OutOfMemoryError: ");
duke@0 264 if (_size) {
duke@0 265 st->print("requested ");
kvn@423 266 sprintf(buf,SIZE_FORMAT,_size);
duke@0 267 st->print(buf);
duke@0 268 st->print(" bytes");
duke@0 269 if (_message != NULL) {
duke@0 270 st->print(" for ");
duke@0 271 st->print(_message);
duke@0 272 }
duke@0 273 st->print_cr(". Out of swap space?");
duke@0 274 } else {
duke@0 275 if (_message != NULL)
duke@0 276 st->print_cr(_message);
duke@0 277 }
duke@0 278 break;
duke@0 279 case internal_error:
duke@0 280 default:
duke@0 281 break;
duke@0 282 }
duke@0 283
duke@0 284 STEP(20, "(printing exception/signal name)")
duke@0 285
duke@0 286 st->print_cr("#");
duke@0 287 st->print("# ");
duke@0 288 // Is it an OS exception/signal?
duke@0 289 if (os::exception_name(_id, buf, sizeof(buf))) {
duke@0 290 st->print("%s", buf);
duke@0 291 st->print(" (0x%x)", _id); // signal number
duke@0 292 st->print(" at pc=" PTR_FORMAT, _pc);
duke@0 293 } else {
duke@0 294 st->print("Internal Error");
duke@0 295 if (_filename != NULL && _lineno > 0) {
duke@0 296 #ifdef PRODUCT
duke@0 297 // In product mode chop off pathname?
duke@0 298 char separator = os::file_separator()[0];
duke@0 299 const char *p = strrchr(_filename, separator);
duke@0 300 const char *file = p ? p+1 : _filename;
duke@0 301 #else
duke@0 302 const char *file = _filename;
duke@0 303 #endif
duke@0 304 size_t len = strlen(file);
duke@0 305 size_t buflen = sizeof(buf);
duke@0 306
duke@0 307 strncpy(buf, file, buflen);
duke@0 308 if (len + 10 < buflen) {
duke@0 309 sprintf(buf + len, ":" SIZE_FORMAT, _lineno);
duke@0 310 }
duke@0 311 st->print(" (%s)", buf);
duke@0 312 } else {
duke@0 313 st->print(" (0x%x)", _id);
duke@0 314 }
duke@0 315 }
duke@0 316
duke@0 317 STEP(30, "(printing current thread and pid)")
duke@0 318
duke@0 319 // process id, thread id
duke@0 320 st->print(", pid=%d", os::current_process_id());
duke@0 321 st->print(", tid=" UINTX_FORMAT, os::current_thread_id());
duke@0 322 st->cr();
duke@0 323
duke@0 324 STEP(40, "(printing error message)")
duke@0 325
duke@0 326 // error message
duke@0 327 if (_message && _message[0] != '\0') {
duke@0 328 st->print_cr("# Error: %s", _message);
duke@0 329 }
duke@0 330
duke@0 331 STEP(50, "(printing Java version string)")
duke@0 332
duke@0 333 // VM version
duke@0 334 st->print_cr("#");
coleenp@113 335 st->print_cr("# Java VM: %s (%s %s %s %s)",
duke@0 336 Abstract_VM_Version::vm_name(),
duke@0 337 Abstract_VM_Version::vm_release(),
duke@0 338 Abstract_VM_Version::vm_info_string(),
coleenp@113 339 Abstract_VM_Version::vm_platform_string(),
coleenp@113 340 UseCompressedOops ? "compressed oops" : ""
duke@0 341 );
duke@0 342
duke@0 343 STEP(60, "(printing problematic frame)")
duke@0 344
duke@0 345 // Print current frame if we have a context (i.e. it's a crash)
duke@0 346 if (_context) {
duke@0 347 st->print_cr("# Problematic frame:");
duke@0 348 st->print("# ");
duke@0 349 frame fr = os::fetch_frame_from_context(_context);
duke@0 350 fr.print_on_error(st, buf, sizeof(buf));
duke@0 351 st->cr();
duke@0 352 st->print_cr("#");
duke@0 353 }
duke@0 354
duke@0 355 STEP(65, "(printing bug submit message)")
duke@0 356
duke@0 357 if (_verbose) print_bug_submit_message(st, _thread);
duke@0 358
duke@0 359 STEP(70, "(printing thread)" )
duke@0 360
duke@0 361 if (_verbose) {
duke@0 362 st->cr();
duke@0 363 st->print_cr("--------------- T H R E A D ---------------");
duke@0 364 st->cr();
duke@0 365 }
duke@0 366
duke@0 367 STEP(80, "(printing current thread)" )
duke@0 368
duke@0 369 // current thread
duke@0 370 if (_verbose) {
duke@0 371 if (_thread) {
duke@0 372 st->print("Current thread (" PTR_FORMAT "): ", _thread);
duke@0 373 _thread->print_on_error(st, buf, sizeof(buf));
duke@0 374 st->cr();
duke@0 375 } else {
duke@0 376 st->print_cr("Current thread is native thread");
duke@0 377 }
duke@0 378 st->cr();
duke@0 379 }
duke@0 380
duke@0 381 STEP(90, "(printing siginfo)" )
duke@0 382
duke@0 383 // signal no, signal code, address that caused the fault
duke@0 384 if (_verbose && _siginfo) {
duke@0 385 os::print_siginfo(st, _siginfo);
duke@0 386 st->cr();
duke@0 387 }
duke@0 388
duke@0 389 STEP(100, "(printing registers, top of stack, instructions near pc)")
duke@0 390
duke@0 391 // registers, top of stack, instructions near pc
duke@0 392 if (_verbose && _context) {
duke@0 393 os::print_context(st, _context);
duke@0 394 st->cr();
duke@0 395 }
duke@0 396
duke@0 397 STEP(110, "(printing stack bounds)" )
duke@0 398
duke@0 399 if (_verbose) {
duke@0 400 st->print("Stack: ");
duke@0 401
duke@0 402 address stack_top;
duke@0 403 size_t stack_size;
duke@0 404
duke@0 405 if (_thread) {
duke@0 406 stack_top = _thread->stack_base();
duke@0 407 stack_size = _thread->stack_size();
duke@0 408 } else {
duke@0 409 stack_top = os::current_stack_base();
duke@0 410 stack_size = os::current_stack_size();
duke@0 411 }
duke@0 412
duke@0 413 address stack_bottom = stack_top - stack_size;
duke@0 414 st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top);
duke@0 415
duke@0 416 frame fr = _context ? os::fetch_frame_from_context(_context)
duke@0 417 : os::current_frame();
duke@0 418
duke@0 419 if (fr.sp()) {
duke@0 420 st->print(", sp=" PTR_FORMAT, fr.sp());
duke@0 421 st->print(", free space=%dk",
duke@0 422 ((intptr_t)fr.sp() - (intptr_t)stack_bottom) >> 10);
duke@0 423 }
duke@0 424
duke@0 425 st->cr();
duke@0 426 }
duke@0 427
duke@0 428 STEP(120, "(printing native stack)" )
duke@0 429
duke@0 430 if (_verbose) {
duke@0 431 frame fr = _context ? os::fetch_frame_from_context(_context)
duke@0 432 : os::current_frame();
duke@0 433
duke@0 434 // see if it's a valid frame
duke@0 435 if (fr.pc()) {
duke@0 436 st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)");
duke@0 437
duke@0 438 int count = 0;
duke@0 439
duke@0 440 while (count++ < StackPrintLimit) {
duke@0 441 fr.print_on_error(st, buf, sizeof(buf));
duke@0 442 st->cr();
duke@0 443 if (os::is_first_C_frame(&fr)) break;
duke@0 444 fr = os::get_sender_for_C_frame(&fr);
duke@0 445 }
duke@0 446
duke@0 447 if (count > StackPrintLimit) {
duke@0 448 st->print_cr("...<more frames>...");
duke@0 449 }
duke@0 450
duke@0 451 st->cr();
duke@0 452 }
duke@0 453 }
duke@0 454
duke@0 455 STEP(130, "(printing Java stack)" )
duke@0 456
duke@0 457 if (_verbose && _thread && _thread->is_Java_thread()) {
duke@0 458 JavaThread* jt = (JavaThread*)_thread;
duke@0 459 if (jt->has_last_Java_frame()) {
duke@0 460 st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
duke@0 461 for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
duke@0 462 sfs.current()->print_on_error(st, buf, sizeof(buf));
duke@0 463 st->cr();
duke@0 464 }
duke@0 465 }
duke@0 466 }
duke@0 467
duke@0 468 STEP(140, "(printing VM operation)" )
duke@0 469
duke@0 470 if (_verbose && _thread && _thread->is_VM_thread()) {
duke@0 471 VMThread* t = (VMThread*)_thread;
duke@0 472 VM_Operation* op = t->vm_operation();
duke@0 473 if (op) {
duke@0 474 op->print_on_error(st);
duke@0 475 st->cr();
duke@0 476 st->cr();
duke@0 477 }
duke@0 478 }
duke@0 479
duke@0 480 STEP(150, "(printing current compile task)" )
duke@0 481
duke@0 482 if (_verbose && _thread && _thread->is_Compiler_thread()) {
duke@0 483 CompilerThread* t = (CompilerThread*)_thread;
duke@0 484 if (t->task()) {
duke@0 485 st->cr();
duke@0 486 st->print_cr("Current CompileTask:");
duke@0 487 t->task()->print_line_on_error(st, buf, sizeof(buf));
duke@0 488 st->cr();
duke@0 489 }
duke@0 490 }
duke@0 491
duke@0 492 STEP(160, "(printing process)" )
duke@0 493
duke@0 494 if (_verbose) {
duke@0 495 st->cr();
duke@0 496 st->print_cr("--------------- P R O C E S S ---------------");
duke@0 497 st->cr();
duke@0 498 }
duke@0 499
duke@0 500 STEP(170, "(printing all threads)" )
duke@0 501
duke@0 502 // all threads
duke@0 503 if (_verbose && _thread) {
duke@0 504 Threads::print_on_error(st, _thread, buf, sizeof(buf));
duke@0 505 st->cr();
duke@0 506 }
duke@0 507
duke@0 508 STEP(175, "(printing VM state)" )
duke@0 509
duke@0 510 if (_verbose) {
duke@0 511 // Safepoint state
duke@0 512 st->print("VM state:");
duke@0 513
duke@0 514 if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing");
duke@0 515 else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint");
duke@0 516 else st->print("not at safepoint");
duke@0 517
duke@0 518 // Also see if error occurred during initialization or shutdown
duke@0 519 if (!Universe::is_fully_initialized()) {
duke@0 520 st->print(" (not fully initialized)");
duke@0 521 } else if (VM_Exit::vm_exited()) {
duke@0 522 st->print(" (shutting down)");
duke@0 523 } else {
duke@0 524 st->print(" (normal execution)");
duke@0 525 }
duke@0 526 st->cr();
duke@0 527 st->cr();
duke@0 528 }
duke@0 529
duke@0 530 STEP(180, "(printing owned locks on error)" )
duke@0 531
duke@0 532 // mutexes/monitors that currently have an owner
duke@0 533 if (_verbose) {
duke@0 534 print_owned_locks_on_error(st);
duke@0 535 st->cr();
duke@0 536 }
duke@0 537
duke@0 538 STEP(190, "(printing heap information)" )
duke@0 539
duke@0 540 if (_verbose && Universe::is_fully_initialized()) {
duke@0 541 // print heap information before vm abort
duke@0 542 Universe::print_on(st);
duke@0 543 st->cr();
duke@0 544 }
duke@0 545
duke@0 546 STEP(200, "(printing dynamic libraries)" )
duke@0 547
duke@0 548 if (_verbose) {
duke@0 549 // dynamic libraries, or memory map
duke@0 550 os::print_dll_info(st);
duke@0 551 st->cr();
duke@0 552 }
duke@0 553
duke@0 554 STEP(210, "(printing VM options)" )
duke@0 555
duke@0 556 if (_verbose) {
duke@0 557 // VM options
duke@0 558 Arguments::print_on(st);
duke@0 559 st->cr();
duke@0 560 }
duke@0 561
duke@0 562 STEP(220, "(printing environment variables)" )
duke@0 563
duke@0 564 if (_verbose) {
duke@0 565 os::print_environment_variables(st, env_list, buf, sizeof(buf));
duke@0 566 st->cr();
duke@0 567 }
duke@0 568
duke@0 569 STEP(225, "(printing signal handlers)" )
duke@0 570
duke@0 571 if (_verbose) {
duke@0 572 os::print_signal_handlers(st, buf, sizeof(buf));
duke@0 573 st->cr();
duke@0 574 }
duke@0 575
duke@0 576 STEP(230, "" )
duke@0 577
duke@0 578 if (_verbose) {
duke@0 579 st->cr();
duke@0 580 st->print_cr("--------------- S Y S T E M ---------------");
duke@0 581 st->cr();
duke@0 582 }
duke@0 583
duke@0 584 STEP(240, "(printing OS information)" )
duke@0 585
duke@0 586 if (_verbose) {
duke@0 587 os::print_os_info(st);
duke@0 588 st->cr();
duke@0 589 }
duke@0 590
duke@0 591 STEP(250, "(printing CPU info)" )
duke@0 592 if (_verbose) {
duke@0 593 os::print_cpu_info(st);
duke@0 594 st->cr();
duke@0 595 }
duke@0 596
duke@0 597 STEP(260, "(printing memory info)" )
duke@0 598
duke@0 599 if (_verbose) {
duke@0 600 os::print_memory_info(st);
duke@0 601 st->cr();
duke@0 602 }
duke@0 603
duke@0 604 STEP(270, "(printing internal vm info)" )
duke@0 605
duke@0 606 if (_verbose) {
duke@0 607 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
duke@0 608 st->cr();
duke@0 609 }
duke@0 610
duke@0 611 STEP(280, "(printing date and time)" )
duke@0 612
duke@0 613 if (_verbose) {
duke@0 614 os::print_date_and_time(st);
duke@0 615 st->cr();
duke@0 616 }
duke@0 617
duke@0 618 END
duke@0 619
duke@0 620 # undef BEGIN
duke@0 621 # undef STEP
duke@0 622 # undef END
duke@0 623 }
duke@0 624
duke@0 625
duke@0 626 void VMError::report_and_die() {
duke@0 627 // Don't allocate large buffer on stack
duke@0 628 static char buffer[O_BUFLEN];
duke@0 629
duke@0 630 // First error, and its thread id. We must be able to handle native thread,
duke@0 631 // so use thread id instead of Thread* to identify thread.
duke@0 632 static VMError* first_error;
duke@0 633 static jlong first_error_tid;
duke@0 634
duke@0 635 // An error could happen before tty is initialized or after it has been
duke@0 636 // destroyed. Here we use a very simple unbuffered fdStream for printing.
duke@0 637 // Only out.print_raw() and out.print_raw_cr() should be used, as other
duke@0 638 // printing methods need to allocate large buffer on stack. To format a
duke@0 639 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
duke@0 640 static fdStream out(defaultStream::output_fd());
duke@0 641
duke@0 642 // How many errors occurred in error handler when reporting first_error.
duke@0 643 static int recursive_error_count;
duke@0 644
duke@0 645 // We will first print a brief message to standard out (verbose = false),
duke@0 646 // then save detailed information in log file (verbose = true).
duke@0 647 static bool out_done = false; // done printing to standard out
duke@0 648 static bool log_done = false; // done saving error log
duke@0 649 static fdStream log; // error log
duke@0 650
duke@0 651 if (SuppressFatalErrorMessage) {
duke@0 652 os::abort();
duke@0 653 }
duke@0 654 jlong mytid = os::current_thread_id();
duke@0 655 if (first_error == NULL &&
duke@0 656 Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) {
duke@0 657
duke@0 658 // first time
duke@0 659 first_error_tid = mytid;
duke@0 660 set_error_reported();
duke@0 661
duke@0 662 if (ShowMessageBoxOnError) {
duke@0 663 show_message_box(buffer, sizeof(buffer));
duke@0 664
duke@0 665 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
duke@0 666 // WatcherThread can kill JVM if the error handler hangs.
duke@0 667 ShowMessageBoxOnError = false;
duke@0 668 }
duke@0 669
duke@0 670 // reset signal handlers or exception filter; make sure recursive crashes
duke@0 671 // are handled properly.
duke@0 672 reset_signal_handlers();
duke@0 673
duke@0 674 } else {
duke@0 675 // This is not the first error, see if it happened in a different thread
duke@0 676 // or in the same thread during error reporting.
duke@0 677 if (first_error_tid != mytid) {
duke@0 678 jio_snprintf(buffer, sizeof(buffer),
duke@0 679 "[thread " INT64_FORMAT " also had an error]",
duke@0 680 mytid);
duke@0 681 out.print_raw_cr(buffer);
duke@0 682
duke@0 683 // error reporting is not MT-safe, block current thread
duke@0 684 os::infinite_sleep();
duke@0 685
duke@0 686 } else {
duke@0 687 if (recursive_error_count++ > 30) {
duke@0 688 out.print_raw_cr("[Too many errors, abort]");
duke@0 689 os::die();
duke@0 690 }
duke@0 691
duke@0 692 jio_snprintf(buffer, sizeof(buffer),
duke@0 693 "[error occurred during error reporting %s, id 0x%x]",
duke@0 694 first_error ? first_error->_current_step_info : "",
duke@0 695 _id);
duke@0 696 if (log.is_open()) {
duke@0 697 log.cr();
duke@0 698 log.print_raw_cr(buffer);
duke@0 699 log.cr();
duke@0 700 } else {
duke@0 701 out.cr();
duke@0 702 out.print_raw_cr(buffer);
duke@0 703 out.cr();
duke@0 704 }
duke@0 705 }
duke@0 706 }
duke@0 707
duke@0 708 // print to screen
duke@0 709 if (!out_done) {
duke@0 710 first_error->_verbose = false;
duke@0 711
duke@0 712 staticBufferStream sbs(buffer, sizeof(buffer), &out);
duke@0 713 first_error->report(&sbs);
duke@0 714
duke@0 715 out_done = true;
duke@0 716
duke@0 717 first_error->_current_step = 0; // reset current_step
duke@0 718 first_error->_current_step_info = ""; // reset current_step string
duke@0 719 }
duke@0 720
duke@0 721 // print to error log file
duke@0 722 if (!log_done) {
duke@0 723 first_error->_verbose = true;
duke@0 724
duke@0 725 // see if log file is already open
duke@0 726 if (!log.is_open()) {
duke@0 727 // open log file
duke@0 728 int fd = -1;
duke@0 729
duke@0 730 if (ErrorFile != NULL) {
duke@0 731 bool copy_ok =
duke@0 732 Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer));
duke@0 733 if (copy_ok) {
duke@0 734 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
duke@0 735 }
duke@0 736 }
duke@0 737
duke@0 738 if (fd == -1) {
duke@0 739 const char *cwd = os::get_current_directory(buffer, sizeof(buffer));
duke@0 740 size_t len = strlen(cwd);
duke@0 741 // either user didn't specify, or the user's location failed,
duke@0 742 // so use the default name in the current directory
duke@0 743 jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log",
duke@0 744 os::file_separator(), os::current_process_id());
duke@0 745 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
duke@0 746 }
duke@0 747
duke@0 748 if (fd == -1) {
duke@0 749 // try temp directory
duke@0 750 const char * tmpdir = os::get_temp_directory();
duke@0 751 jio_snprintf(buffer, sizeof(buffer), "%shs_err_pid%u.log",
duke@0 752 (tmpdir ? tmpdir : ""), os::current_process_id());
duke@0 753 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
duke@0 754 }
duke@0 755
duke@0 756 if (fd != -1) {
duke@0 757 out.print_raw("# An error report file with more information is saved as:\n# ");
duke@0 758 out.print_raw_cr(buffer);
duke@0 759 os::set_error_file(buffer);
duke@0 760
duke@0 761 log.set_fd(fd);
duke@0 762 } else {
duke@0 763 out.print_raw_cr("# Can not save log file, dump to screen..");
duke@0 764 log.set_fd(defaultStream::output_fd());
duke@0 765 }
duke@0 766 }
duke@0 767
duke@0 768 staticBufferStream sbs(buffer, O_BUFLEN, &log);
duke@0 769 first_error->report(&sbs);
duke@0 770 first_error->_current_step = 0; // reset current_step
duke@0 771 first_error->_current_step_info = ""; // reset current_step string
duke@0 772
duke@0 773 if (log.fd() != defaultStream::output_fd()) {
duke@0 774 close(log.fd());
duke@0 775 }
duke@0 776
duke@0 777 log.set_fd(-1);
duke@0 778 log_done = true;
duke@0 779 }
duke@0 780
duke@0 781
duke@0 782 static bool skip_OnError = false;
duke@0 783 if (!skip_OnError && OnError && OnError[0]) {
duke@0 784 skip_OnError = true;
duke@0 785
duke@0 786 out.print_raw_cr("#");
duke@0 787 out.print_raw ("# -XX:OnError=\"");
duke@0 788 out.print_raw (OnError);
duke@0 789 out.print_raw_cr("\"");
duke@0 790
duke@0 791 char* cmd;
duke@0 792 const char* ptr = OnError;
duke@0 793 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
duke@0 794 out.print_raw ("# Executing ");
duke@0 795 #if defined(LINUX)
duke@0 796 out.print_raw ("/bin/sh -c ");
duke@0 797 #elif defined(SOLARIS)
duke@0 798 out.print_raw ("/usr/bin/sh -c ");
duke@0 799 #endif
duke@0 800 out.print_raw ("\"");
duke@0 801 out.print_raw (cmd);
duke@0 802 out.print_raw_cr("\" ...");
duke@0 803
duke@0 804 os::fork_and_exec(cmd);
duke@0 805 }
duke@0 806
duke@0 807 // done with OnError
duke@0 808 OnError = NULL;
duke@0 809 }
duke@0 810
duke@0 811 static bool skip_bug_url = false;
duke@0 812 if (!skip_bug_url) {
duke@0 813 skip_bug_url = true;
duke@0 814
duke@0 815 out.print_raw_cr("#");
duke@0 816 print_bug_submit_message(&out, _thread);
duke@0 817 }
duke@0 818
duke@0 819 if (!UseOSErrorReporting) {
duke@0 820 // os::abort() will call abort hooks, try it first.
duke@0 821 static bool skip_os_abort = false;
duke@0 822 if (!skip_os_abort) {
duke@0 823 skip_os_abort = true;
duke@0 824 os::abort();
duke@0 825 }
duke@0 826
duke@0 827 // if os::abort() doesn't abort, try os::die();
duke@0 828 os::die();
duke@0 829 }
duke@0 830 }
duke@0 831
duke@0 832 /*
duke@0 833 * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this
duke@0 834 * ensures utilities such as jmap can observe the process is a consistent state.
duke@0 835 */
duke@0 836 class VM_ReportJavaOutOfMemory : public VM_Operation {
duke@0 837 private:
duke@0 838 VMError *_err;
duke@0 839 public:
duke@0 840 VM_ReportJavaOutOfMemory(VMError *err) { _err = err; }
duke@0 841 VMOp_Type type() const { return VMOp_ReportJavaOutOfMemory; }
duke@0 842 void doit();
duke@0 843 };
duke@0 844
duke@0 845 void VM_ReportJavaOutOfMemory::doit() {
duke@0 846 // Don't allocate large buffer on stack
duke@0 847 static char buffer[O_BUFLEN];
duke@0 848
duke@0 849 tty->print_cr("#");
duke@0 850 tty->print_cr("# java.lang.OutOfMemoryError: %s", _err->message());
duke@0 851 tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError);
duke@0 852
duke@0 853 // make heap parsability
duke@0 854 Universe::heap()->ensure_parsability(false); // no need to retire TLABs
duke@0 855
duke@0 856 char* cmd;
duke@0 857 const char* ptr = OnOutOfMemoryError;
duke@0 858 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
duke@0 859 tty->print("# Executing ");
duke@0 860 #if defined(LINUX)
duke@0 861 tty->print ("/bin/sh -c ");
duke@0 862 #elif defined(SOLARIS)
duke@0 863 tty->print ("/usr/bin/sh -c ");
duke@0 864 #endif
duke@0 865 tty->print_cr("\"%s\"...", cmd);
duke@0 866
duke@0 867 os::fork_and_exec(cmd);
duke@0 868 }
duke@0 869 }
duke@0 870
duke@0 871 void VMError::report_java_out_of_memory() {
duke@0 872 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
duke@0 873 MutexLocker ml(Heap_lock);
duke@0 874 VM_ReportJavaOutOfMemory op(this);
duke@0 875 VMThread::execute(&op);
duke@0 876 }
duke@0 877 }