annotate src/share/vm/utilities/vmError.cpp @ 20779:d7b6bdd51abe

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