src/share/vm/utilities/vmError.cpp

Thu, 27 Dec 2018 11:43:33 +0800

author
aoqi
date
Thu, 27 Dec 2018 11:43:33 +0800
changeset 9448
73d689add964
parent 9304
44e44e1f0fd8
parent 9137
dc1769738300
child 9637
eef07cd490d4
permissions
-rw-r--r--

Merge

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

mercurial