32 #include "prims/jvm.h"
33 #include "prims/whitebox.hpp"
34 #include "runtime/arguments.hpp"
35 #include "runtime/atomic.hpp"
36 #include "runtime/frame.inline.hpp"
37 #include "runtime/init.hpp"
38 #include "runtime/os.hpp"
39 #include "runtime/thread.inline.hpp"
40 #include "runtime/vmThread.hpp"
41 #include "runtime/vm_operations.hpp"
42 #include "runtime/vm_version.hpp"
43 #include "services/memTracker.hpp"
44 #include "trace/traceMacros.hpp"
45 #include "utilities/debug.hpp"
46 #include "utilities/decoder.hpp"
47 #include "utilities/defaultStream.hpp"
48 #include "utilities/errorReporter.hpp"
49 #include "utilities/events.hpp"
50 #include "utilities/vmError.hpp"
51
52 // List of environment variables that should be reported in error log file.
53 const char *env_list[] = {
54 // All platforms
55 "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
56 "JAVA_COMPILER", "PATH", "USERNAME",
57
58 // Env variables that are defined on Solaris/Linux/BSD
59 "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
60 "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
61
62 // defined on Linux
63 "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
64
65 // defined on Darwin
66 "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
67 "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
68 "DYLD_INSERT_LIBRARIES",
69
70 // defined on Windows
71 "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
1242 intptr_t mytid = os::current_thread_id();
1243 if (first_error_tid == -1 &&
1244 Atomic::cmpxchg_ptr(mytid, &first_error_tid, -1) == -1) {
1245
1246 // Initialize time stamps to use the same base.
1247 out.time_stamp().update_to(1);
1248 log.time_stamp().update_to(1);
1249
1250 _id = id;
1251 _message = message;
1252 _thread = thread;
1253 _pc = pc;
1254 _siginfo = siginfo;
1255 _context = context;
1256 _filename = filename;
1257 _lineno = lineno;
1258 _size = size;
1259 jio_vsnprintf(_detail_msg, sizeof(_detail_msg), detail_fmt, detail_args);
1260
1261 // first time
1262 set_error_reported();
1263
1264 reporting_started();
1265 record_reporting_start_time();
1266
1267 if (ShowMessageBoxOnError || PauseAtExit) {
1268 show_message_box(buffer, sizeof(buffer));
1269
1270 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
1271 // WatcherThread can kill JVM if the error handler hangs.
1272 ShowMessageBoxOnError = false;
1273 }
1274
1275 os::check_dump_limit(buffer, sizeof(buffer));
1276
1277 // reset signal handlers or exception filter; make sure recursive crashes
1278 // are handled properly.
1279 reset_signal_handlers();
1280
1281 TRACE_VM_ERROR();
1282
1556 return true; // global timeout
1557 }
1558 }
1559
1560 const jlong step_start_time_l = get_step_start_time();
1561 if (step_start_time_l > 0) {
1562 // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
1563 // hang for some reason, so this simple rule allows for three hanging step and still
1564 // hopefully leaves time enough for the rest of the steps to finish.
1565 const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
1566 if (end <= now) {
1567 _step_did_timeout = true;
1568 interrupt_reporting_thread();
1569 return false; // (Not a global timeout)
1570 }
1571 }
1572
1573 return false;
1574
1575 }
1576
|
32 #include "prims/jvm.h"
33 #include "prims/whitebox.hpp"
34 #include "runtime/arguments.hpp"
35 #include "runtime/atomic.hpp"
36 #include "runtime/frame.inline.hpp"
37 #include "runtime/init.hpp"
38 #include "runtime/os.hpp"
39 #include "runtime/thread.inline.hpp"
40 #include "runtime/vmThread.hpp"
41 #include "runtime/vm_operations.hpp"
42 #include "runtime/vm_version.hpp"
43 #include "services/memTracker.hpp"
44 #include "trace/traceMacros.hpp"
45 #include "utilities/debug.hpp"
46 #include "utilities/decoder.hpp"
47 #include "utilities/defaultStream.hpp"
48 #include "utilities/errorReporter.hpp"
49 #include "utilities/events.hpp"
50 #include "utilities/vmError.hpp"
51
52 bool VMError::_error_reported = false;
53
54 // call this when the VM is dying--it might loosen some asserts
55 bool VMError::is_error_reported() { return _error_reported; }
56
57 // returns an address which is guaranteed to generate a SIGSEGV on read,
58 // for test purposes, which is not NULL and contains bits in every word
59 void* VMError::get_segfault_address() {
60 return (void*)
61 #ifdef _LP64
62 0xABC0000000000ABCULL;
63 #else
64 0x00000ABC;
65 #endif
66 }
67
68 NOT_PRODUCT(void controlled_crash(int how);)
69
70 // List of environment variables that should be reported in error log file.
71 const char *env_list[] = {
72 // All platforms
73 "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
74 "JAVA_COMPILER", "PATH", "USERNAME",
75
76 // Env variables that are defined on Solaris/Linux/BSD
77 "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
78 "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
79
80 // defined on Linux
81 "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
82
83 // defined on Darwin
84 "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
85 "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
86 "DYLD_INSERT_LIBRARIES",
87
88 // defined on Windows
89 "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
1260 intptr_t mytid = os::current_thread_id();
1261 if (first_error_tid == -1 &&
1262 Atomic::cmpxchg_ptr(mytid, &first_error_tid, -1) == -1) {
1263
1264 // Initialize time stamps to use the same base.
1265 out.time_stamp().update_to(1);
1266 log.time_stamp().update_to(1);
1267
1268 _id = id;
1269 _message = message;
1270 _thread = thread;
1271 _pc = pc;
1272 _siginfo = siginfo;
1273 _context = context;
1274 _filename = filename;
1275 _lineno = lineno;
1276 _size = size;
1277 jio_vsnprintf(_detail_msg, sizeof(_detail_msg), detail_fmt, detail_args);
1278
1279 // first time
1280 _error_reported = true;
1281
1282 reporting_started();
1283 record_reporting_start_time();
1284
1285 if (ShowMessageBoxOnError || PauseAtExit) {
1286 show_message_box(buffer, sizeof(buffer));
1287
1288 // User has asked JVM to abort. Reset ShowMessageBoxOnError so the
1289 // WatcherThread can kill JVM if the error handler hangs.
1290 ShowMessageBoxOnError = false;
1291 }
1292
1293 os::check_dump_limit(buffer, sizeof(buffer));
1294
1295 // reset signal handlers or exception filter; make sure recursive crashes
1296 // are handled properly.
1297 reset_signal_handlers();
1298
1299 TRACE_VM_ERROR();
1300
1574 return true; // global timeout
1575 }
1576 }
1577
1578 const jlong step_start_time_l = get_step_start_time();
1579 if (step_start_time_l > 0) {
1580 // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
1581 // hang for some reason, so this simple rule allows for three hanging step and still
1582 // hopefully leaves time enough for the rest of the steps to finish.
1583 const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
1584 if (end <= now) {
1585 _step_did_timeout = true;
1586 interrupt_reporting_thread();
1587 return false; // (Not a global timeout)
1588 }
1589 }
1590
1591 return false;
1592
1593 }
1594
1595 #ifndef PRODUCT
1596 #include <signal.h>
1597
1598 typedef void (*voidfun_t)();
1599 // Crash with an authentic sigfpe
1600 static void crash_with_sigfpe() {
1601 // generate a native synchronous SIGFPE where possible;
1602 // if that did not cause a signal (e.g. on ppc), just
1603 // raise the signal.
1604 volatile int x = 0;
1605 volatile int y = 1/x;
1606 #ifndef _WIN32
1607 // OSX implements raise(sig) incorrectly so we need to
1608 // explicitly target the current thread
1609 pthread_kill(pthread_self(), SIGFPE);
1610 #endif
1611 } // end: crash_with_sigfpe
1612
1613 // crash with sigsegv at non-null address.
1614 static void crash_with_segfault() {
1615
1616 char* const crash_addr = (char*) VMError::get_segfault_address();
1617 *crash_addr = 'X';
1618
1619 } // end: crash_with_segfault
1620
1621 void VMError::test_error_handler() {
1622 controlled_crash(ErrorHandlerTest);
1623 }
1624
1625 // crash in a controlled way:
1626 // how can be one of:
1627 // 1,2 - asserts
1628 // 3,4 - guarantee
1629 // 5-7 - fatal
1630 // 8 - vm_exit_out_of_memory
1631 // 9 - ShouldNotCallThis
1632 // 10 - ShouldNotReachHere
1633 // 11 - Unimplemented
1634 // 12,13 - (not guaranteed) crashes
1635 // 14 - SIGSEGV
1636 // 15 - SIGFPE
1637 void controlled_crash(int how) {
1638 if (how == 0) return;
1639
1640 // If asserts are disabled, use the corresponding guarantee instead.
1641 NOT_DEBUG(if (how <= 2) how += 2);
1642
1643 const char* const str = "hello";
1644 const size_t num = (size_t)os::vm_page_size();
1645
1646 const char* const eol = os::line_separator();
1647 const char* const msg = "this message should be truncated during formatting";
1648 char * const dataPtr = NULL; // bad data pointer
1649 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer
1650
1651 // Keep this in sync with test/runtime/ErrorHandling/ErrorHandler.java
1652 switch (how) {
1653 case 1: vmassert(str == NULL, "expected null");
1654 case 2: vmassert(num == 1023 && *str == 'X',
1655 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
1656 case 3: guarantee(str == NULL, "expected null");
1657 case 4: guarantee(num == 1023 && *str == 'X',
1658 "num=" SIZE_FORMAT " str=\"%s\"", num, str);
1659 case 5: fatal("expected null");
1660 case 6: fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
1661 case 7: fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
1662 "%s%s# %s%s# %s%s# %s%s# %s%s# "
1663 "%s%s# %s%s# %s%s# %s%s# %s",
1664 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
1665 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
1666 msg, eol, msg, eol, msg, eol, msg, eol, msg);
1667 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
1668 case 9: ShouldNotCallThis();
1669 case 10: ShouldNotReachHere();
1670 case 11: Unimplemented();
1671 // There's no guarantee the bad data pointer will crash us
1672 // so "break" out to the ShouldNotReachHere().
1673 case 12: *dataPtr = '\0'; break;
1674 // There's no guarantee the bad function pointer will crash us
1675 // so "break" out to the ShouldNotReachHere().
1676 case 13: (*funcPtr)(); break;
1677 case 14: crash_with_segfault(); break;
1678 case 15: crash_with_sigfpe(); break;
1679
1680 default: tty->print_cr("ERROR: %d: unexpected test_num value.", how);
1681 }
1682 ShouldNotReachHere();
1683 }
1684 #endif // !PRODUCT
1685
|