src/share/vm/utilities/vmError.cpp

Wed, 26 Nov 2014 08:57:40 -0800

author
asaha
date
Wed, 26 Nov 2014 08:57:40 -0800
changeset 7495
42f27b59c550
parent 7267
417e3b8d04c5
parent 7493
d7b6bdd51abe
child 7535
7ae4e26cb1e0
child 7557
9989538b7507
child 7715
f3ffb37f88a6
permissions
-rw-r--r--

Merge

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

mercurial