< prev index next >

src/hotspot/share/utilities/vmError.cpp

Print this page
rev 59383 : [mq]: final


  65 // call this when the VM is dying--it might loosen some asserts
  66 bool VMError::is_error_reported() { return _error_reported; }
  67 
  68 // returns an address which is guaranteed to generate a SIGSEGV on read,
  69 // for test purposes, which is not NULL and contains bits in every word
  70 void* VMError::get_segfault_address() {
  71   return (void*)
  72 #ifdef _LP64
  73     0xABC0000000000ABCULL;
  74 #else
  75     0x00000ABC;
  76 #endif
  77 }
  78 
  79 // List of environment variables that should be reported in error log file.
  80 const char *env_list[] = {
  81   // All platforms
  82   "JAVA_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
  83   "PATH", "USERNAME",
  84 
  85   // Env variables that are defined on Solaris/Linux/BSD
  86   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
  87   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
  88   "LANG", "LC_ALL", "LC_CTYPE", "TZ",
  89 
  90   // defined on AIX
  91   "LIBPATH", "LDR_PRELOAD", "LDR_PRELOAD64",
  92 
  93   // defined on Linux/AIX/BSD
  94   "_JAVA_SR_SIGNUM",
  95 
  96   // defined on Darwin
  97   "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
  98   "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
  99   "DYLD_INSERT_LIBRARIES",
 100 
 101   // defined on Windows
 102   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
 103 
 104   (const char *)0
 105 };


1572   }
1573 
1574   static bool skip_OnError = false;
1575   if (!skip_OnError && OnError && OnError[0]) {
1576     skip_OnError = true;
1577 
1578     // Flush output and finish logs before running OnError commands.
1579     ostream_abort();
1580 
1581     out.print_raw_cr("#");
1582     out.print_raw   ("# -XX:OnError=\"");
1583     out.print_raw   (OnError);
1584     out.print_raw_cr("\"");
1585 
1586     char* cmd;
1587     const char* ptr = OnError;
1588     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1589       out.print_raw   ("#   Executing ");
1590 #if defined(LINUX) || defined(_ALLBSD_SOURCE)
1591       out.print_raw   ("/bin/sh -c ");
1592 #elif defined(SOLARIS)
1593       out.print_raw   ("/usr/bin/sh -c ");
1594 #elif defined(_WINDOWS)
1595       out.print_raw   ("cmd /C ");
1596 #endif
1597       out.print_raw   ("\"");
1598       out.print_raw   (cmd);
1599       out.print_raw_cr("\" ...");
1600 
1601       if (os::fork_and_exec(cmd) < 0) {
1602         out.print_cr("os::fork_and_exec failed: %s (%s=%d)",
1603                      os::strerror(errno), os::errno_name(errno), errno);
1604       }
1605     }
1606 
1607     // done with OnError
1608     OnError = NULL;
1609   }
1610 
1611   if (!UseOSErrorReporting) {
1612     // os::abort() will call abort hooks, try it first.
1613     static bool skip_os_abort = false;


1635   void doit();
1636 };
1637 
1638 void VM_ReportJavaOutOfMemory::doit() {
1639   // Don't allocate large buffer on stack
1640   static char buffer[O_BUFLEN];
1641 
1642   tty->print_cr("#");
1643   tty->print_cr("# java.lang.OutOfMemoryError: %s", _message);
1644   tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError);
1645 
1646   // make heap parsability
1647   Universe::heap()->ensure_parsability(false);  // no need to retire TLABs
1648 
1649   char* cmd;
1650   const char* ptr = OnOutOfMemoryError;
1651   while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1652     tty->print("#   Executing ");
1653 #if defined(LINUX)
1654     tty->print  ("/bin/sh -c ");
1655 #elif defined(SOLARIS)
1656     tty->print  ("/usr/bin/sh -c ");
1657 #endif
1658     tty->print_cr("\"%s\"...", cmd);
1659 
1660     if (os::fork_and_exec(cmd, true) < 0) {
1661       tty->print_cr("os::fork_and_exec failed: %s (%s=%d)",
1662                      os::strerror(errno), os::errno_name(errno), errno);
1663     }
1664   }
1665 }
1666 
1667 void VMError::report_java_out_of_memory(const char* message) {
1668   if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
1669     MutexLocker ml(Heap_lock);
1670     VM_ReportJavaOutOfMemory op(message);
1671     VMThread::execute(&op);
1672   }
1673 }
1674 
1675 void VMError::show_message_box(char *buf, int buflen) {
1676   bool yes;


1714   const jlong step_start_time_l = get_step_start_time();
1715   if (step_start_time_l > 0) {
1716     // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
1717     // hang for some reason, so this simple rule allows for three hanging step and still
1718     // hopefully leaves time enough for the rest of the steps to finish.
1719     const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
1720     if (end <= now && !_step_did_timeout) {
1721       // The step timed out and we haven't interrupted the reporting
1722       // thread yet.
1723       _step_did_timeout = true;
1724       interrupt_reporting_thread();
1725       return false; // (Not a global timeout)
1726     }
1727   }
1728 
1729   return false;
1730 
1731 }
1732 
1733 #ifndef PRODUCT
1734 #if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140
1735 #pragma error_messages(off, SEC_NULL_PTR_DEREF)
1736 #endif
1737 typedef void (*voidfun_t)();
1738 // Crash with an authentic sigfpe
1739 static void crash_with_sigfpe() {
1740   // generate a native synchronous SIGFPE where possible;
1741   // if that did not cause a signal (e.g. on ppc), just
1742   // raise the signal.
1743   volatile int x = 0;
1744   volatile int y = 1/x;
1745 #ifndef _WIN32
1746   // OSX implements raise(sig) incorrectly so we need to
1747   // explicitly target the current thread
1748   pthread_kill(pthread_self(), SIGFPE);
1749 #endif
1750 } // end: crash_with_sigfpe
1751 
1752 // crash with sigsegv at non-null address.
1753 static void crash_with_segfault() {
1754 
1755   char* const crash_addr = (char*) VMError::get_segfault_address();
1756   *crash_addr = 'X';




  65 // call this when the VM is dying--it might loosen some asserts
  66 bool VMError::is_error_reported() { return _error_reported; }
  67 
  68 // returns an address which is guaranteed to generate a SIGSEGV on read,
  69 // for test purposes, which is not NULL and contains bits in every word
  70 void* VMError::get_segfault_address() {
  71   return (void*)
  72 #ifdef _LP64
  73     0xABC0000000000ABCULL;
  74 #else
  75     0x00000ABC;
  76 #endif
  77 }
  78 
  79 // List of environment variables that should be reported in error log file.
  80 const char *env_list[] = {
  81   // All platforms
  82   "JAVA_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
  83   "PATH", "USERNAME",
  84 
  85   // Env variables that are defined on Linux/BSD
  86   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
  87   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
  88   "LANG", "LC_ALL", "LC_CTYPE", "TZ",
  89 
  90   // defined on AIX
  91   "LIBPATH", "LDR_PRELOAD", "LDR_PRELOAD64",
  92 
  93   // defined on Linux/AIX/BSD
  94   "_JAVA_SR_SIGNUM",
  95 
  96   // defined on Darwin
  97   "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
  98   "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
  99   "DYLD_INSERT_LIBRARIES",
 100 
 101   // defined on Windows
 102   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
 103 
 104   (const char *)0
 105 };


1572   }
1573 
1574   static bool skip_OnError = false;
1575   if (!skip_OnError && OnError && OnError[0]) {
1576     skip_OnError = true;
1577 
1578     // Flush output and finish logs before running OnError commands.
1579     ostream_abort();
1580 
1581     out.print_raw_cr("#");
1582     out.print_raw   ("# -XX:OnError=\"");
1583     out.print_raw   (OnError);
1584     out.print_raw_cr("\"");
1585 
1586     char* cmd;
1587     const char* ptr = OnError;
1588     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1589       out.print_raw   ("#   Executing ");
1590 #if defined(LINUX) || defined(_ALLBSD_SOURCE)
1591       out.print_raw   ("/bin/sh -c ");


1592 #elif defined(_WINDOWS)
1593       out.print_raw   ("cmd /C ");
1594 #endif
1595       out.print_raw   ("\"");
1596       out.print_raw   (cmd);
1597       out.print_raw_cr("\" ...");
1598 
1599       if (os::fork_and_exec(cmd) < 0) {
1600         out.print_cr("os::fork_and_exec failed: %s (%s=%d)",
1601                      os::strerror(errno), os::errno_name(errno), errno);
1602       }
1603     }
1604 
1605     // done with OnError
1606     OnError = NULL;
1607   }
1608 
1609   if (!UseOSErrorReporting) {
1610     // os::abort() will call abort hooks, try it first.
1611     static bool skip_os_abort = false;


1633   void doit();
1634 };
1635 
1636 void VM_ReportJavaOutOfMemory::doit() {
1637   // Don't allocate large buffer on stack
1638   static char buffer[O_BUFLEN];
1639 
1640   tty->print_cr("#");
1641   tty->print_cr("# java.lang.OutOfMemoryError: %s", _message);
1642   tty->print_cr("# -XX:OnOutOfMemoryError=\"%s\"", OnOutOfMemoryError);
1643 
1644   // make heap parsability
1645   Universe::heap()->ensure_parsability(false);  // no need to retire TLABs
1646 
1647   char* cmd;
1648   const char* ptr = OnOutOfMemoryError;
1649   while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
1650     tty->print("#   Executing ");
1651 #if defined(LINUX)
1652     tty->print  ("/bin/sh -c ");


1653 #endif
1654     tty->print_cr("\"%s\"...", cmd);
1655 
1656     if (os::fork_and_exec(cmd, true) < 0) {
1657       tty->print_cr("os::fork_and_exec failed: %s (%s=%d)",
1658                      os::strerror(errno), os::errno_name(errno), errno);
1659     }
1660   }
1661 }
1662 
1663 void VMError::report_java_out_of_memory(const char* message) {
1664   if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
1665     MutexLocker ml(Heap_lock);
1666     VM_ReportJavaOutOfMemory op(message);
1667     VMThread::execute(&op);
1668   }
1669 }
1670 
1671 void VMError::show_message_box(char *buf, int buflen) {
1672   bool yes;


1710   const jlong step_start_time_l = get_step_start_time();
1711   if (step_start_time_l > 0) {
1712     // A step times out after a quarter of the total timeout. Steps are mostly fast unless they
1713     // hang for some reason, so this simple rule allows for three hanging step and still
1714     // hopefully leaves time enough for the rest of the steps to finish.
1715     const jlong end = step_start_time_l + (jlong)ErrorLogTimeout * TIMESTAMP_TO_SECONDS_FACTOR / 4;
1716     if (end <= now && !_step_did_timeout) {
1717       // The step timed out and we haven't interrupted the reporting
1718       // thread yet.
1719       _step_did_timeout = true;
1720       interrupt_reporting_thread();
1721       return false; // (Not a global timeout)
1722     }
1723   }
1724 
1725   return false;
1726 
1727 }
1728 
1729 #ifndef PRODUCT



1730 typedef void (*voidfun_t)();
1731 // Crash with an authentic sigfpe
1732 static void crash_with_sigfpe() {
1733   // generate a native synchronous SIGFPE where possible;
1734   // if that did not cause a signal (e.g. on ppc), just
1735   // raise the signal.
1736   volatile int x = 0;
1737   volatile int y = 1/x;
1738 #ifndef _WIN32
1739   // OSX implements raise(sig) incorrectly so we need to
1740   // explicitly target the current thread
1741   pthread_kill(pthread_self(), SIGFPE);
1742 #endif
1743 } // end: crash_with_sigfpe
1744 
1745 // crash with sigsegv at non-null address.
1746 static void crash_with_segfault() {
1747 
1748   char* const crash_addr = (char*) VMError::get_segfault_address();
1749   *crash_addr = 'X';


< prev index next >