annotate src/share/vm/utilities/vmError.cpp @ 1999:2c8e1acf0433

7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined Summary: Change get_temp_directory() back to /tmp and %TEMP% like it always was and where the tools expect it to be. Reviewed-by: phh, dcubed, kamg, alanb
author coleenp
date Wed, 12 Jan 2011 13:59:18 -0800
parents 2ecd0d1194d2
children a541ca8fa0e3
rev   line source
duke@0 1 /*
trims@1772 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. 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 *
trims@1772 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1772 20 * or visit www.oracle.com if you need additional information or have any
trims@1772 21 * 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
jcoomes@1700 68 _message = NULL;
jcoomes@1700 69 _detail_msg = NULL;
duke@0 70 _filename = NULL;
duke@0 71 _lineno = 0;
duke@0 72
duke@0 73 _size = 0;
duke@0 74 }
duke@0 75
duke@0 76 // Constructor for internal errors
jcoomes@1700 77 VMError::VMError(Thread* thread, const char* filename, int lineno,
jcoomes@1700 78 const char* message, const char * detail_msg)
jcoomes@1700 79 {
jcoomes@1700 80 _thread = thread;
jcoomes@1700 81 _id = internal_error; // Value that's not an OS exception/signal
jcoomes@1700 82 _filename = filename;
jcoomes@1700 83 _lineno = lineno;
jcoomes@1700 84 _message = message;
jcoomes@1700 85 _detail_msg = detail_msg;
jcoomes@1700 86
jcoomes@1700 87 _verbose = false;
jcoomes@1700 88 _current_step = 0;
jcoomes@1700 89 _current_step_info = NULL;
jcoomes@1700 90
jcoomes@1700 91 _pc = NULL;
jcoomes@1700 92 _siginfo = NULL;
jcoomes@1700 93 _context = NULL;
jcoomes@1700 94
jcoomes@1700 95 _size = 0;
jcoomes@1700 96 }
jcoomes@1700 97
jcoomes@1700 98 // Constructor for OOM errors
jcoomes@1700 99 VMError::VMError(Thread* thread, const char* filename, int lineno, size_t size,
jcoomes@1700 100 const char* message) {
duke@0 101 _thread = thread;
jcoomes@1700 102 _id = oom_error; // Value that's not an OS exception/signal
duke@0 103 _filename = filename;
duke@0 104 _lineno = lineno;
duke@0 105 _message = message;
jcoomes@1700 106 _detail_msg = NULL;
duke@0 107
duke@0 108 _verbose = false;
duke@0 109 _current_step = 0;
duke@0 110 _current_step_info = NULL;
duke@0 111
duke@0 112 _pc = NULL;
duke@0 113 _siginfo = NULL;
duke@0 114 _context = NULL;
duke@0 115
duke@0 116 _size = size;
duke@0 117 }
duke@0 118
duke@0 119
duke@0 120 // Constructor for non-fatal errors
duke@0 121 VMError::VMError(const char* message) {
duke@0 122 _thread = NULL;
jcoomes@1700 123 _id = internal_error; // Value that's not an OS exception/signal
duke@0 124 _filename = NULL;
duke@0 125 _lineno = 0;
duke@0 126 _message = message;
jcoomes@1700 127 _detail_msg = NULL;
duke@0 128
duke@0 129 _verbose = false;
duke@0 130 _current_step = 0;
duke@0 131 _current_step_info = NULL;
duke@0 132
duke@0 133 _pc = NULL;
duke@0 134 _siginfo = NULL;
duke@0 135 _context = NULL;
duke@0 136
duke@0 137 _size = 0;
duke@0 138 }
duke@0 139
duke@0 140 // -XX:OnError=<string>, where <string> can be a list of commands, separated
duke@0 141 // by ';'. "%p" is replaced by current process id (pid); "%%" is replaced by
duke@0 142 // a single "%". Some examples:
duke@0 143 //
duke@0 144 // -XX:OnError="pmap %p" // show memory map
duke@0 145 // -XX:OnError="gcore %p; dbx - %p" // dump core and launch debugger
duke@0 146 // -XX:OnError="cat hs_err_pid%p.log | mail my_email@sun.com"
duke@0 147 // -XX:OnError="kill -9 %p" // ?#!@#
duke@0 148
duke@0 149 // A simple parser for -XX:OnError, usage:
duke@0 150 // ptr = OnError;
duke@0 151 // while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr) != NULL)
duke@0 152 // ... ...
duke@0 153 static char* next_OnError_command(char* buf, int buflen, const char** ptr) {
duke@0 154 if (ptr == NULL || *ptr == NULL) return NULL;
duke@0 155
duke@0 156 const char* cmd = *ptr;
duke@0 157
duke@0 158 // skip leading blanks or ';'
duke@0 159 while (*cmd == ' ' || *cmd == ';') cmd++;
duke@0 160
duke@0 161 if (*cmd == '\0') return NULL;
duke@0 162
duke@0 163 const char * cmdend = cmd;
duke@0 164 while (*cmdend != '\0' && *cmdend != ';') cmdend++;
duke@0 165
duke@0 166 Arguments::copy_expand_pid(cmd, cmdend - cmd, buf, buflen);
duke@0 167
duke@0 168 *ptr = (*cmdend == '\0' ? cmdend : cmdend + 1);
duke@0 169 return buf;
duke@0 170 }
duke@0 171
duke@0 172
duke@0 173 static void print_bug_submit_message(outputStream *out, Thread *thread) {
duke@0 174 if (out == NULL) return;
duke@0 175 out->print_raw_cr("# If you would like to submit a bug report, please visit:");
duke@0 176 out->print_raw ("# ");
duke@0 177 out->print_raw_cr(Arguments::java_vendor_url_bug());
duke@0 178 // If the crash is in native code, encourage user to submit a bug to the
duke@0 179 // provider of that code.
coleenp@114 180 if (thread && thread->is_Java_thread() &&
coleenp@114 181 !thread->is_hidden_from_external_view()) {
duke@0 182 JavaThread* jt = (JavaThread*)thread;
duke@0 183 if (jt->thread_state() == _thread_in_native) {
duke@0 184 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 185 }
duke@0 186 }
duke@0 187 out->print_raw_cr("#");
duke@0 188 }
duke@0 189
duke@0 190
duke@0 191 // Return a string to describe the error
duke@0 192 char* VMError::error_string(char* buf, int buflen) {
duke@0 193 char signame_buf[64];
duke@0 194 const char *signame = os::exception_name(_id, signame_buf, sizeof(signame_buf));
duke@0 195
duke@0 196 if (signame) {
duke@0 197 jio_snprintf(buf, buflen,
duke@0 198 "%s (0x%x) at pc=" PTR_FORMAT ", pid=%d, tid=" UINTX_FORMAT,
duke@0 199 signame, _id, _pc,
duke@0 200 os::current_process_id(), os::current_thread_id());
jcoomes@1700 201 } else if (_filename != NULL && _lineno > 0) {
jcoomes@1700 202 // skip directory names
jcoomes@1700 203 char separator = os::file_separator()[0];
jcoomes@1700 204 const char *p = strrchr(_filename, separator);
jcoomes@1700 205 int n = jio_snprintf(buf, buflen,
jcoomes@1700 206 "Internal Error at %s:%d, pid=%d, tid=" UINTX_FORMAT,
jcoomes@1700 207 p ? p + 1 : _filename, _lineno,
jcoomes@1700 208 os::current_process_id(), os::current_thread_id());
jcoomes@1700 209 if (n >= 0 && n < buflen && _message) {
jcoomes@1700 210 if (_detail_msg) {
jcoomes@1700 211 jio_snprintf(buf + n, buflen - n, "%s%s: %s",
jcoomes@1700 212 os::line_separator(), _message, _detail_msg);
jcoomes@1700 213 } else {
jcoomes@1700 214 jio_snprintf(buf + n, buflen - n, "%sError: %s",
jcoomes@1700 215 os::line_separator(), _message);
jcoomes@1700 216 }
jcoomes@1700 217 }
duke@0 218 } else {
jcoomes@1700 219 jio_snprintf(buf, buflen,
jcoomes@1700 220 "Internal Error (0x%x), pid=%d, tid=" UINTX_FORMAT,
jcoomes@1700 221 _id, os::current_process_id(), os::current_thread_id());
duke@0 222 }
duke@0 223
duke@0 224 return buf;
duke@0 225 }
duke@0 226
twisti@1682 227 void VMError::print_stack_trace(outputStream* st, JavaThread* jt,
twisti@1682 228 char* buf, int buflen, bool verbose) {
twisti@1682 229 #ifdef ZERO
twisti@1682 230 if (jt->zero_stack()->sp() && jt->top_zero_frame()) {
twisti@1682 231 // StackFrameStream uses the frame anchor, which may not have
twisti@1682 232 // been set up. This can be done at any time in Zero, however,
twisti@1682 233 // so if it hasn't been set up then we just set it up now and
twisti@1682 234 // clear it again when we're done.
twisti@1682 235 bool has_last_Java_frame = jt->has_last_Java_frame();
twisti@1682 236 if (!has_last_Java_frame)
twisti@1682 237 jt->set_last_Java_frame();
twisti@1682 238 st->print("Java frames:");
twisti@1682 239
twisti@1682 240 // If the top frame is a Shark frame and the frame anchor isn't
twisti@1682 241 // set up then it's possible that the information in the frame
twisti@1682 242 // is garbage: it could be from a previous decache, or it could
twisti@1682 243 // simply have never been written. So we print a warning...
twisti@1682 244 StackFrameStream sfs(jt);
twisti@1682 245 if (!has_last_Java_frame && !sfs.is_done()) {
twisti@1682 246 if (sfs.current()->zeroframe()->is_shark_frame()) {
twisti@1682 247 st->print(" (TOP FRAME MAY BE JUNK)");
twisti@1682 248 }
twisti@1682 249 }
twisti@1682 250 st->cr();
twisti@1682 251
twisti@1682 252 // Print the frames
twisti@1682 253 for(int i = 0; !sfs.is_done(); sfs.next(), i++) {
twisti@1682 254 sfs.current()->zero_print_on_error(i, st, buf, buflen);
twisti@1682 255 st->cr();
twisti@1682 256 }
twisti@1682 257
twisti@1682 258 // Reset the frame anchor if necessary
twisti@1682 259 if (!has_last_Java_frame)
twisti@1682 260 jt->reset_last_Java_frame();
twisti@1682 261 }
twisti@1682 262 #else
twisti@1682 263 if (jt->has_last_Java_frame()) {
twisti@1682 264 st->print_cr("Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)");
twisti@1682 265 for(StackFrameStream sfs(jt); !sfs.is_done(); sfs.next()) {
twisti@1682 266 sfs.current()->print_on_error(st, buf, buflen, verbose);
twisti@1682 267 st->cr();
twisti@1682 268 }
twisti@1682 269 }
twisti@1682 270 #endif // ZERO
twisti@1682 271 }
duke@0 272
duke@0 273 // This is the main function to report a fatal error. Only one thread can
duke@0 274 // call this function, so we don't need to worry about MT-safety. But it's
duke@0 275 // possible that the error handler itself may crash or die on an internal
duke@0 276 // error, for example, when the stack/heap is badly damaged. We must be
duke@0 277 // able to handle recursive errors that happen inside error handler.
duke@0 278 //
duke@0 279 // Error reporting is done in several steps. If a crash or internal error
duke@0 280 // occurred when reporting an error, the nested signal/exception handler
duke@0 281 // can skip steps that are already (or partially) done. Error reporting will
duke@0 282 // continue from the next step. This allows us to retrieve and print
duke@0 283 // information that may be unsafe to get after a fatal error. If it happens,
duke@0 284 // you may find nested report_and_die() frames when you look at the stack
duke@0 285 // in a debugger.
duke@0 286 //
duke@0 287 // In general, a hang in error handler is much worse than a crash or internal
duke@0 288 // error, as it's harder to recover from a hang. Deadlock can happen if we
duke@0 289 // try to grab a lock that is already owned by current thread, or if the
duke@0 290 // owner is blocked forever (e.g. in os::infinite_sleep()). If possible, the
duke@0 291 // error handler and all the functions it called should avoid grabbing any
duke@0 292 // lock. An important thing to notice is that memory allocation needs a lock.
duke@0 293 //
duke@0 294 // We should avoid using large stack allocated buffers. Many errors happen
duke@0 295 // when stack space is already low. Making things even worse is that there
duke@0 296 // could be nested report_and_die() calls on stack (see above). Only one
duke@0 297 // thread can report error, so large buffers are statically allocated in data
duke@0 298 // segment.
duke@0 299
duke@0 300 void VMError::report(outputStream* st) {
duke@0 301 # define BEGIN if (_current_step == 0) { _current_step = 1;
duke@0 302 # define STEP(n, s) } if (_current_step < n) { _current_step = n; _current_step_info = s;
duke@0 303 # define END }
duke@0 304
duke@0 305 // don't allocate large buffer on stack
duke@0 306 static char buf[O_BUFLEN];
duke@0 307
duke@0 308 BEGIN
duke@0 309
coleenp@114 310 STEP(10, "(printing fatal error message)")
duke@0 311
duke@0 312 st->print_cr("#");
coleenp@114 313 st->print_cr("# A fatal error has been detected by the Java Runtime Environment:");
duke@0 314
duke@0 315 STEP(15, "(printing type of error)")
duke@0 316
duke@0 317 switch(_id) {
duke@0 318 case oom_error:
duke@0 319 st->print_cr("#");
duke@0 320 st->print("# java.lang.OutOfMemoryError: ");
duke@0 321 if (_size) {
duke@0 322 st->print("requested ");
kvn@478 323 sprintf(buf,SIZE_FORMAT,_size);
duke@0 324 st->print(buf);
duke@0 325 st->print(" bytes");
duke@0 326 if (_message != NULL) {
duke@0 327 st->print(" for ");
duke@0 328 st->print(_message);
duke@0 329 }
duke@0 330 st->print_cr(". Out of swap space?");
duke@0 331 } else {
duke@0 332 if (_message != NULL)
duke@0 333 st->print_cr(_message);
duke@0 334 }
duke@0 335 break;
duke@0 336 case internal_error:
duke@0 337 default:
duke@0 338 break;
duke@0 339 }
duke@0 340
duke@0 341 STEP(20, "(printing exception/signal name)")
duke@0 342
duke@0 343 st->print_cr("#");
duke@0 344 st->print("# ");
duke@0 345 // Is it an OS exception/signal?
duke@0 346 if (os::exception_name(_id, buf, sizeof(buf))) {
duke@0 347 st->print("%s", buf);
duke@0 348 st->print(" (0x%x)", _id); // signal number
duke@0 349 st->print(" at pc=" PTR_FORMAT, _pc);
duke@0 350 } else {
duke@0 351 st->print("Internal Error");
duke@0 352 if (_filename != NULL && _lineno > 0) {
duke@0 353 #ifdef PRODUCT
duke@0 354 // In product mode chop off pathname?
duke@0 355 char separator = os::file_separator()[0];
duke@0 356 const char *p = strrchr(_filename, separator);
duke@0 357 const char *file = p ? p+1 : _filename;
duke@0 358 #else
duke@0 359 const char *file = _filename;
duke@0 360 #endif
duke@0 361 size_t len = strlen(file);
duke@0 362 size_t buflen = sizeof(buf);
duke@0 363
duke@0 364 strncpy(buf, file, buflen);
duke@0 365 if (len + 10 < buflen) {
twisti@734 366 sprintf(buf + len, ":%d", _lineno);
duke@0 367 }
duke@0 368 st->print(" (%s)", buf);
duke@0 369 } else {
duke@0 370 st->print(" (0x%x)", _id);
duke@0 371 }
duke@0 372 }
duke@0 373
duke@0 374 STEP(30, "(printing current thread and pid)")
duke@0 375
duke@0 376 // process id, thread id
duke@0 377 st->print(", pid=%d", os::current_process_id());
duke@0 378 st->print(", tid=" UINTX_FORMAT, os::current_thread_id());
duke@0 379 st->cr();
duke@0 380
duke@0 381 STEP(40, "(printing error message)")
duke@0 382
duke@0 383 // error message
jcoomes@1700 384 if (_detail_msg) {
jcoomes@1700 385 st->print_cr("# %s: %s", _message ? _message : "Error", _detail_msg);
jcoomes@1700 386 } else if (_message) {
duke@0 387 st->print_cr("# Error: %s", _message);
duke@0 388 }
duke@0 389
duke@0 390 STEP(50, "(printing Java version string)")
duke@0 391
duke@0 392 // VM version
duke@0 393 st->print_cr("#");
coleenp@529 394 JDK_Version::current().to_string(buf, sizeof(buf));
coleenp@529 395 st->print_cr("# JRE version: %s", buf);
coleenp@170 396 st->print_cr("# Java VM: %s (%s %s %s %s)",
duke@0 397 Abstract_VM_Version::vm_name(),
duke@0 398 Abstract_VM_Version::vm_release(),
duke@0 399 Abstract_VM_Version::vm_info_string(),
coleenp@170 400 Abstract_VM_Version::vm_platform_string(),
coleenp@170 401 UseCompressedOops ? "compressed oops" : ""
duke@0 402 );
duke@0 403
duke@0 404 STEP(60, "(printing problematic frame)")
duke@0 405
duke@0 406 // Print current frame if we have a context (i.e. it's a crash)
duke@0 407 if (_context) {
duke@0 408 st->print_cr("# Problematic frame:");
duke@0 409 st->print("# ");
duke@0 410 frame fr = os::fetch_frame_from_context(_context);
duke@0 411 fr.print_on_error(st, buf, sizeof(buf));
duke@0 412 st->cr();
duke@0 413 st->print_cr("#");
duke@0 414 }
duke@0 415
duke@0 416 STEP(65, "(printing bug submit message)")
duke@0 417
duke@0 418 if (_verbose) print_bug_submit_message(st, _thread);
duke@0 419
duke@0 420 STEP(70, "(printing thread)" )
duke@0 421
duke@0 422 if (_verbose) {
duke@0 423 st->cr();
duke@0 424 st->print_cr("--------------- T H R E A D ---------------");
duke@0 425 st->cr();
duke@0 426 }
duke@0 427
duke@0 428 STEP(80, "(printing current thread)" )
duke@0 429
duke@0 430 // current thread
duke@0 431 if (_verbose) {
duke@0 432 if (_thread) {
duke@0 433 st->print("Current thread (" PTR_FORMAT "): ", _thread);
duke@0 434 _thread->print_on_error(st, buf, sizeof(buf));
duke@0 435 st->cr();
duke@0 436 } else {
duke@0 437 st->print_cr("Current thread is native thread");
duke@0 438 }
duke@0 439 st->cr();
duke@0 440 }
duke@0 441
duke@0 442 STEP(90, "(printing siginfo)" )
duke@0 443
duke@0 444 // signal no, signal code, address that caused the fault
duke@0 445 if (_verbose && _siginfo) {
duke@0 446 os::print_siginfo(st, _siginfo);
duke@0 447 st->cr();
duke@0 448 }
duke@0 449
duke@0 450 STEP(100, "(printing registers, top of stack, instructions near pc)")
duke@0 451
duke@0 452 // registers, top of stack, instructions near pc
duke@0 453 if (_verbose && _context) {
duke@0 454 os::print_context(st, _context);
duke@0 455 st->cr();
duke@0 456 }
duke@0 457
duke@0 458 STEP(110, "(printing stack bounds)" )
duke@0 459
duke@0 460 if (_verbose) {
duke@0 461 st->print("Stack: ");
duke@0 462
duke@0 463 address stack_top;
duke@0 464 size_t stack_size;
duke@0 465
duke@0 466 if (_thread) {
duke@0 467 stack_top = _thread->stack_base();
duke@0 468 stack_size = _thread->stack_size();
duke@0 469 } else {
duke@0 470 stack_top = os::current_stack_base();
duke@0 471 stack_size = os::current_stack_size();
duke@0 472 }
duke@0 473
duke@0 474 address stack_bottom = stack_top - stack_size;
duke@0 475 st->print("[" PTR_FORMAT "," PTR_FORMAT "]", stack_bottom, stack_top);
duke@0 476
duke@0 477 frame fr = _context ? os::fetch_frame_from_context(_context)
duke@0 478 : os::current_frame();
duke@0 479
duke@0 480 if (fr.sp()) {
duke@0 481 st->print(", sp=" PTR_FORMAT, fr.sp());
kvn@1895 482 size_t free_stack_size = pointer_delta(fr.sp(), stack_bottom, 1024);
kvn@1895 483 st->print(", free space=" SIZE_FORMAT "k", free_stack_size);
duke@0 484 }
duke@0 485
duke@0 486 st->cr();
duke@0 487 }
duke@0 488
duke@0 489 STEP(120, "(printing native stack)" )
duke@0 490
duke@0 491 if (_verbose) {
duke@0 492 frame fr = _context ? os::fetch_frame_from_context(_context)
duke@0 493 : os::current_frame();
duke@0 494
duke@0 495 // see if it's a valid frame
duke@0 496 if (fr.pc()) {
duke@0 497 st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)");
duke@0 498
duke@0 499 int count = 0;
duke@0 500
duke@0 501 while (count++ < StackPrintLimit) {
duke@0 502 fr.print_on_error(st, buf, sizeof(buf));
duke@0 503 st->cr();
duke@0 504 if (os::is_first_C_frame(&fr)) break;
duke@0 505 fr = os::get_sender_for_C_frame(&fr);
duke@0 506 }
duke@0 507
duke@0 508 if (count > StackPrintLimit) {
duke@0 509 st->print_cr("...<more frames>...");
duke@0 510 }
duke@0 511
duke@0 512 st->cr();
duke@0 513 }
duke@0 514 }
duke@0 515
duke@0 516 STEP(130, "(printing Java stack)" )
duke@0 517
duke@0 518 if (_verbose && _thread && _thread->is_Java_thread()) {
twisti@1682 519 print_stack_trace(st, (JavaThread*)_thread, buf, sizeof(buf));
duke@0 520 }
duke@0 521
minqi@1350 522 STEP(135, "(printing target Java thread stack)" )
minqi@1350 523
minqi@1350 524 // printing Java thread stack trace if it is involved in GC crash
minqi@1990 525 if (_verbose && _thread && (_thread->is_Named_thread())) {
minqi@1350 526 JavaThread* jt = ((NamedThread *)_thread)->processed_thread();
minqi@1350 527 if (jt != NULL) {
minqi@1350 528 st->print_cr("JavaThread " PTR_FORMAT " (nid = " UINTX_FORMAT ") was being processed", jt, jt->osthread()->thread_id());
twisti@1682 529 print_stack_trace(st, jt, buf, sizeof(buf), true);
minqi@1350 530 }
minqi@1350 531 }
minqi@1350 532
duke@0 533 STEP(140, "(printing VM operation)" )
duke@0 534
duke@0 535 if (_verbose && _thread && _thread->is_VM_thread()) {
duke@0 536 VMThread* t = (VMThread*)_thread;
duke@0 537 VM_Operation* op = t->vm_operation();
duke@0 538 if (op) {
duke@0 539 op->print_on_error(st);
duke@0 540 st->cr();
duke@0 541 st->cr();
duke@0 542 }
duke@0 543 }
duke@0 544
duke@0 545 STEP(150, "(printing current compile task)" )
duke@0 546
duke@0 547 if (_verbose && _thread && _thread->is_Compiler_thread()) {
duke@0 548 CompilerThread* t = (CompilerThread*)_thread;
duke@0 549 if (t->task()) {
duke@0 550 st->cr();
duke@0 551 st->print_cr("Current CompileTask:");
duke@0 552 t->task()->print_line_on_error(st, buf, sizeof(buf));
duke@0 553 st->cr();
duke@0 554 }
duke@0 555 }
duke@0 556
duke@0 557 STEP(160, "(printing process)" )
duke@0 558
duke@0 559 if (_verbose) {
duke@0 560 st->cr();
duke@0 561 st->print_cr("--------------- P R O C E S S ---------------");
duke@0 562 st->cr();
duke@0 563 }
duke@0 564
duke@0 565 STEP(170, "(printing all threads)" )
duke@0 566
duke@0 567 // all threads
duke@0 568 if (_verbose && _thread) {
duke@0 569 Threads::print_on_error(st, _thread, buf, sizeof(buf));
duke@0 570 st->cr();
duke@0 571 }
duke@0 572
duke@0 573 STEP(175, "(printing VM state)" )
duke@0 574
duke@0 575 if (_verbose) {
duke@0 576 // Safepoint state
duke@0 577 st->print("VM state:");
duke@0 578
duke@0 579 if (SafepointSynchronize::is_synchronizing()) st->print("synchronizing");
duke@0 580 else if (SafepointSynchronize::is_at_safepoint()) st->print("at safepoint");
duke@0 581 else st->print("not at safepoint");
duke@0 582
duke@0 583 // Also see if error occurred during initialization or shutdown
duke@0 584 if (!Universe::is_fully_initialized()) {
duke@0 585 st->print(" (not fully initialized)");
duke@0 586 } else if (VM_Exit::vm_exited()) {
duke@0 587 st->print(" (shutting down)");
duke@0 588 } else {
duke@0 589 st->print(" (normal execution)");
duke@0 590 }
duke@0 591 st->cr();
duke@0 592 st->cr();
duke@0 593 }
duke@0 594
duke@0 595 STEP(180, "(printing owned locks on error)" )
duke@0 596
duke@0 597 // mutexes/monitors that currently have an owner
duke@0 598 if (_verbose) {
duke@0 599 print_owned_locks_on_error(st);
duke@0 600 st->cr();
duke@0 601 }
duke@0 602
duke@0 603 STEP(190, "(printing heap information)" )
duke@0 604
duke@0 605 if (_verbose && Universe::is_fully_initialized()) {
duke@0 606 // print heap information before vm abort
duke@0 607 Universe::print_on(st);
duke@0 608 st->cr();
duke@0 609 }
duke@0 610
duke@0 611 STEP(200, "(printing dynamic libraries)" )
duke@0 612
duke@0 613 if (_verbose) {
duke@0 614 // dynamic libraries, or memory map
duke@0 615 os::print_dll_info(st);
duke@0 616 st->cr();
duke@0 617 }
duke@0 618
duke@0 619 STEP(210, "(printing VM options)" )
duke@0 620
duke@0 621 if (_verbose) {
duke@0 622 // VM options
duke@0 623 Arguments::print_on(st);
duke@0 624 st->cr();
duke@0 625 }
duke@0 626
duke@0 627 STEP(220, "(printing environment variables)" )
duke@0 628
duke@0 629 if (_verbose) {
duke@0 630 os::print_environment_variables(st, env_list, buf, sizeof(buf));
duke@0 631 st->cr();
duke@0 632 }
duke@0 633
duke@0 634 STEP(225, "(printing signal handlers)" )
duke@0 635
duke@0 636 if (_verbose) {
duke@0 637 os::print_signal_handlers(st, buf, sizeof(buf));
duke@0 638 st->cr();
duke@0 639 }
duke@0 640
duke@0 641 STEP(230, "" )
duke@0 642
duke@0 643 if (_verbose) {
duke@0 644 st->cr();
duke@0 645 st->print_cr("--------------- S Y S T E M ---------------");
duke@0 646 st->cr();
duke@0 647 }
duke@0 648
duke@0 649 STEP(240, "(printing OS information)" )
duke@0 650
duke@0 651 if (_verbose) {
duke@0 652 os::print_os_info(st);
duke@0 653 st->cr();
duke@0 654 }
duke@0 655
duke@0 656 STEP(250, "(printing CPU info)" )
duke@0 657 if (_verbose) {
duke@0 658 os::print_cpu_info(st);
duke@0 659 st->cr();
duke@0 660 }
duke@0 661
duke@0 662 STEP(260, "(printing memory info)" )
duke@0 663
duke@0 664 if (_verbose) {
duke@0 665 os::print_memory_info(st);
duke@0 666 st->cr();
duke@0 667 }
duke@0 668
duke@0 669 STEP(270, "(printing internal vm info)" )
duke@0 670
duke@0 671 if (_verbose) {
duke@0 672 st->print_cr("vm_info: %s", Abstract_VM_Version::internal_vm_info_string());
duke@0 673 st->cr();
duke@0 674 }
duke@0 675
duke@0 676 STEP(280, "(printing date and time)" )
duke@0 677
duke@0 678 if (_verbose) {
duke@0 679 os::print_date_and_time(st);
duke@0 680 st->cr();
duke@0 681 }
duke@0 682
duke@0 683 END
duke@0 684
duke@0 685 # undef BEGIN
duke@0 686 # undef STEP
duke@0 687 # undef END
duke@0 688 }
duke@0 689
bobv@1892 690 VMError* volatile VMError::first_error = NULL;
bobv@1892 691 volatile jlong VMError::first_error_tid = -1;
duke@0 692
duke@0 693 void VMError::report_and_die() {
duke@0 694 // Don't allocate large buffer on stack
duke@0 695 static char buffer[O_BUFLEN];
duke@0 696
duke@0 697 // An error could happen before tty is initialized or after it has been
duke@0 698 // destroyed. Here we use a very simple unbuffered fdStream for printing.
duke@0 699 // Only out.print_raw() and out.print_raw_cr() should be used, as other
duke@0 700 // printing methods need to allocate large buffer on stack. To format a
duke@0 701 // string, use jio_snprintf() with a static buffer or use staticBufferStream.
duke@0 702 static fdStream out(defaultStream::output_fd());
duke@0 703
duke@0 704 // How many errors occurred in error handler when reporting first_error.
duke@0 705 static int recursive_error_count;
duke@0 706
duke@0 707 // We will first print a brief message to standard out (verbose = false),
duke@0 708 // then save detailed information in log file (verbose = true).
duke@0 709 static bool out_done = false; // done printing to standard out
duke@0 710 static bool log_done = false; // done saving error log
duke@0 711 static fdStream log; // error log
duke@0 712
duke@0 713 if (SuppressFatalErrorMessage) {
duke@0 714 os::abort();
duke@0 715 }
duke@0 716 jlong mytid = os::current_thread_id();
duke@0 717 if (first_error == NULL &&
duke@0 718 Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) {
duke@0 719
duke@0 720 // first time
duke@0 721 first_error_tid = mytid;
duke@0 722 set_error_reported();
duke@0 723
duke@0 724 if (ShowMessageBoxOnError) {
duke@0 725 show_message_box(buffer, sizeof(buffer));
duke@0 726
duke@0 727 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
duke@0 728 // WatcherThread can kill JVM if the error handler hangs.
duke@0 729 ShowMessageBoxOnError = false;
duke@0 730 }
duke@0 731
duke@0 732 // reset signal handlers or exception filter; make sure recursive crashes
duke@0 733 // are handled properly.
duke@0 734 reset_signal_handlers();
duke@0 735
duke@0 736 } else {
coleenp@641 737 // If UseOsErrorReporting we call this for each level of the call stack
coleenp@641 738 // while searching for the exception handler. Only the first level needs
coleenp@641 739 // to be reported.
coleenp@641 740 if (UseOSErrorReporting && log_done) return;
coleenp@641 741
duke@0 742 // This is not the first error, see if it happened in a different thread
duke@0 743 // or in the same thread during error reporting.
duke@0 744 if (first_error_tid != mytid) {
duke@0 745 jio_snprintf(buffer, sizeof(buffer),
duke@0 746 "[thread " INT64_FORMAT " also had an error]",
duke@0 747 mytid);
duke@0 748 out.print_raw_cr(buffer);
duke@0 749
duke@0 750 // error reporting is not MT-safe, block current thread
duke@0 751 os::infinite_sleep();
duke@0 752
duke@0 753 } else {
duke@0 754 if (recursive_error_count++ > 30) {
duke@0 755 out.print_raw_cr("[Too many errors, abort]");
duke@0 756 os::die();
duke@0 757 }
duke@0 758
duke@0 759 jio_snprintf(buffer, sizeof(buffer),
duke@0 760 "[error occurred during error reporting %s, id 0x%x]",
duke@0 761 first_error ? first_error->_current_step_info : "",
duke@0 762 _id);
duke@0 763 if (log.is_open()) {
duke@0 764 log.cr();
duke@0 765 log.print_raw_cr(buffer);
duke@0 766 log.cr();
duke@0 767 } else {
duke@0 768 out.cr();
duke@0 769 out.print_raw_cr(buffer);
duke@0 770 out.cr();
duke@0 771 }
duke@0 772 }
duke@0 773 }
duke@0 774
duke@0 775 // print to screen
duke@0 776 if (!out_done) {
duke@0 777 first_error->_verbose = false;
duke@0 778
duke@0 779 staticBufferStream sbs(buffer, sizeof(buffer), &out);
duke@0 780 first_error->report(&sbs);
duke@0 781
duke@0 782 out_done = true;
duke@0 783
duke@0 784 first_error->_current_step = 0; // reset current_step
duke@0 785 first_error->_current_step_info = ""; // reset current_step string
duke@0 786 }
duke@0 787
duke@0 788 // print to error log file
duke@0 789 if (!log_done) {
duke@0 790 first_error->_verbose = true;
duke@0 791
duke@0 792 // see if log file is already open
duke@0 793 if (!log.is_open()) {
duke@0 794 // open log file
duke@0 795 int fd = -1;
duke@0 796
duke@0 797 if (ErrorFile != NULL) {
duke@0 798 bool copy_ok =
duke@0 799 Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer));
duke@0 800 if (copy_ok) {
duke@0 801 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
duke@0 802 }
duke@0 803 }
duke@0 804
duke@0 805 if (fd == -1) {
duke@0 806 const char *cwd = os::get_current_directory(buffer, sizeof(buffer));
duke@0 807 size_t len = strlen(cwd);
duke@0 808 // either user didn't specify, or the user's location failed,
duke@0 809 // so use the default name in the current directory
duke@0 810 jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log",
duke@0 811 os::file_separator(), os::current_process_id());
duke@0 812 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
duke@0 813 }
duke@0 814
duke@0 815 if (fd == -1) {
duke@0 816 const char * tmpdir = os::get_temp_directory();
coleenp@1999 817 // try temp directory if it exists.
coleenp@1999 818 if (tmpdir != NULL && tmpdir[0] != '\0') {
coleenp@1999 819 jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log",
coleenp@1999 820 tmpdir, os::file_separator(), os::current_process_id());
coleenp@1999 821 fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
coleenp@1999 822 }
duke@0 823 }
duke@0 824
duke@0 825 if (fd != -1) {
duke@0 826 out.print_raw("# An error report file with more information is saved as:\n# ");
duke@0 827 out.print_raw_cr(buffer);
duke@0 828 os::set_error_file(buffer);
duke@0 829
duke@0 830 log.set_fd(fd);
duke@0 831 } else {
duke@0 832 out.print_raw_cr("# Can not save log file, dump to screen..");
duke@0 833 log.set_fd(defaultStream::output_fd());
duke@0 834 }
duke@0 835 }
duke@0 836
duke@0 837 staticBufferStream sbs(buffer, O_BUFLEN, &log);
duke@0 838 first_error->report(&sbs);
duke@0 839 first_error->_current_step = 0; // reset current_step
duke@0 840 first_error->_current_step_info = ""; // reset current_step string
duke@0 841
duke@0 842 if (log.fd() != defaultStream::output_fd()) {
duke@0 843 close(log.fd());
duke@0 844 }
duke@0 845
duke@0 846 log.set_fd(-1);
duke@0 847 log_done = true;
duke@0 848 }
duke@0 849
duke@0 850
duke@0 851 static bool skip_OnError = false;
duke@0 852 if (!skip_OnError && OnError && OnError[0]) {
duke@0 853 skip_OnError = true;
duke@0 854
duke@0 855 out.print_raw_cr("#");
duke@0 856 out.print_raw ("# -XX:OnError=\"");
duke@0 857 out.print_raw (OnError);
duke@0 858 out.print_raw_cr("\"");
duke@0 859
duke@0 860 char* cmd;
duke@0 861 const char* ptr = OnError;
duke@0 862 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
duke@0 863 out.print_raw ("# Executing ");
duke@0 864 #if defined(LINUX)
duke@0 865 out.print_raw ("/bin/sh -c ");
duke@0 866 #elif defined(SOLARIS)
duke@0 867 out.print_raw ("/usr/bin/sh -c ");
duke@0 868 #endif
duke@0 869 out.print_raw ("\"");
duke@0 870 out.print_raw (cmd);
duke@0 871 out.print_raw_cr("\" ...");
duke@0 872
duke@0 873 os::fork_and_exec(cmd);
duke@0 874 }
duke@0 875
duke@0 876 // done with OnError
duke@0 877 OnError = NULL;
duke@0 878 }
duke@0 879
duke@0 880 static bool skip_bug_url = false;
duke@0 881 if (!skip_bug_url) {
duke@0 882 skip_bug_url = true;
duke@0 883
duke@0 884 out.print_raw_cr("#");
duke@0 885 print_bug_submit_message(&out, _thread);
duke@0 886 }
duke@0 887
duke@0 888 if (!UseOSErrorReporting) {
duke@0 889 // os::abort() will call abort hooks, try it first.
duke@0 890 static bool skip_os_abort = false;
duke@0 891 if (!skip_os_abort) {
duke@0 892 skip_os_abort = true;
duke@0 893 os::abort();
duke@0 894 }
duke@0 895
duke@0 896 // if os::abort() doesn't abort, try os::die();
duke@0 897 os::die();
duke@0 898 }
duke@0 899 }
duke@0 900
duke@0 901 /*
duke@0 902 * OnOutOfMemoryError scripts/commands executed while VM is a safepoint - this
duke@0 903 * ensures utilities such as jmap can observe the process is a consistent state.
duke@0 904 */
duke@0 905 class VM_ReportJavaOutOfMemory : public VM_Operation {
duke@0 906 private:
duke@0 907 VMError *_err;
duke@0 908 public:
duke@0 909 VM_ReportJavaOutOfMemory(VMError *err) { _err = err; }
duke@0 910 VMOp_Type type() const { return VMOp_ReportJavaOutOfMemory; }
duke@0 911 void doit();
duke@0 912 };
duke@0 913
duke@0 914 void VM_ReportJavaOutOfMemory::doit() {
duke@0 915 // Don't allocate large buffer on stack
duke@0 916 static char buffer[O_BUFLEN];
duke@0 917
duke@0 918 tty->print_cr("#");
duke@0 919 tty->print_cr("# java.lang.OutOfMemoryError: %s", _err->message());
duke@0 920 tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError);
duke@0 921
duke@0 922 // make heap parsability
duke@0 923 Universe::heap()->ensure_parsability(false); // no need to retire TLABs
duke@0 924
duke@0 925 char* cmd;
duke@0 926 const char* ptr = OnOutOfMemoryError;
duke@0 927 while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
duke@0 928 tty->print("# Executing ");
duke@0 929 #if defined(LINUX)
duke@0 930 tty->print ("/bin/sh -c ");
duke@0 931 #elif defined(SOLARIS)
duke@0 932 tty->print ("/usr/bin/sh -c ");
duke@0 933 #endif
duke@0 934 tty->print_cr("\"%s\"...", cmd);
duke@0 935
duke@0 936 os::fork_and_exec(cmd);
duke@0 937 }
duke@0 938 }
duke@0 939
duke@0 940 void VMError::report_java_out_of_memory() {
duke@0 941 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
duke@0 942 MutexLocker ml(Heap_lock);
duke@0 943 VM_ReportJavaOutOfMemory op(this);
duke@0 944 VMThread::execute(&op);
duke@0 945 }
duke@0 946 }