hotspot/src/share/vm/utilities/vmError.hpp
changeset 33105 294e48b4f704
parent 31963 641ed52732ec
child 33131 a8ad9de9e5a4
equal deleted inserted replaced
33104:a7c0f60a1294 33105:294e48b4f704
    28 #include "utilities/globalDefinitions.hpp"
    28 #include "utilities/globalDefinitions.hpp"
    29 
    29 
    30 class Decoder;
    30 class Decoder;
    31 class VM_ReportJavaOutOfMemory;
    31 class VM_ReportJavaOutOfMemory;
    32 
    32 
    33 class VMError : public StackObj {
    33 class VMError : public AllStatic {
    34   friend class VM_ReportJavaOutOfMemory;
    34   friend class VM_ReportJavaOutOfMemory;
    35   friend class Decoder;
    35   friend class Decoder;
    36 
    36 
    37   int          _id;          // Solaris/Linux signals: 0 - SIGRTMAX
    37   static int         _id;               // Solaris/Linux signals: 0 - SIGRTMAX
    38                              // Windows exceptions: 0xCxxxxxxx system errors
    38                                         // Windows exceptions: 0xCxxxxxxx system errors
    39                              //                     0x8xxxxxxx system warnings
    39                                         //                     0x8xxxxxxx system warnings
    40 
    40 
    41   const char * _message;
    41   static const char* _message;
    42   const char * _detail_msg;
    42   static char        _detail_msg[1024];
    43 
    43 
    44   Thread *     _thread;      // NULL if it's native thread
    44   static Thread*     _thread;           // NULL if it's native thread
    45 
       
    46 
    45 
    47   // additional info for crashes
    46   // additional info for crashes
    48   address      _pc;          // faulting PC
    47   static address     _pc;               // faulting PC
    49   void *       _siginfo;     // ExceptionRecord on Windows,
    48   static void*       _siginfo;          // ExceptionRecord on Windows,
    50                              // siginfo_t on Solaris/Linux
    49                                         // siginfo_t on Solaris/Linux
    51   void *       _context;     // ContextRecord on Windows,
    50   static void*       _context;          // ContextRecord on Windows,
    52                              // ucontext_t on Solaris/Linux
    51                                         // ucontext_t on Solaris/Linux
    53 
    52 
    54   // additional info for VM internal errors
    53   // additional info for VM internal errors
    55   const char * _filename;
    54   static const char* _filename;
    56   int          _lineno;
    55   static int         _lineno;
       
    56 
       
    57   // used by reporting about OOM
       
    58   static size_t      _size;
    57 
    59 
    58   // used by fatal error handler
    60   // used by fatal error handler
    59   int          _current_step;
    61   static int         _current_step;
    60   const char * _current_step_info;
    62   static const char* _current_step_info;
    61   int          _verbose;
    63 
    62   // First error, and its thread id. We must be able to handle native thread,
    64   // Thread id of the first error. We must be able to handle native thread,
    63   // so use thread id instead of Thread* to identify thread.
    65   // so use thread id instead of Thread* to identify thread.
    64   static VMError* volatile first_error;
       
    65   static volatile jlong    first_error_tid;
    66   static volatile jlong    first_error_tid;
    66 
    67 
    67   // Core dump status, false if we have been unable to write a core/minidump for some reason
    68   // Core dump status, false if we have been unable to write a core/minidump for some reason
    68   static bool coredump_status;
    69   static bool coredump_status;
    69 
    70 
    70   // When coredump_status is set to true this will contain the name/path to the core/minidump,
    71   // When coredump_status is set to true this will contain the name/path to the core/minidump,
    71   // if coredump_status if false, this will (hopefully) contain a useful error explaining why
    72   // if coredump_status if false, this will (hopefully) contain a useful error explaining why
    72   // no core/minidump has been written to disk
    73   // no core/minidump has been written to disk
    73   static char coredump_message[O_BUFLEN];
    74   static char coredump_message[O_BUFLEN];
    74 
    75 
    75   // used by reporting about OOM
       
    76   size_t       _size;
       
    77 
    76 
    78   // set signal handlers on Solaris/Linux or the default exception filter
    77   // set signal handlers on Solaris/Linux or the default exception filter
    79   // on Windows, to handle recursive crashes.
    78   // on Windows, to handle recursive crashes.
    80   void reset_signal_handlers();
    79   static void reset_signal_handlers();
    81 
    80 
    82   // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string
    81   // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string
    83   void show_message_box(char* buf, int buflen);
    82   static void show_message_box(char* buf, int buflen);
    84 
    83 
    85   // generate an error report
    84   // generate an error report
    86   void report(outputStream* st);
    85   static void report(outputStream* st, bool verbose);
    87 
    86 
    88   // generate a stack trace
    87   // generate a stack trace
    89   static void print_stack_trace(outputStream* st, JavaThread* jt,
    88   static void print_stack_trace(outputStream* st, JavaThread* jt,
    90                                 char* buf, int buflen, bool verbose = false);
    89                                 char* buf, int buflen, bool verbose = false);
    91 
    90 
    92   static const char* gc_mode();
    91   static const char* gc_mode();
    93   static void print_oom_reasons(outputStream* st);
    92   static void print_oom_reasons(outputStream* st);
    94 
    93 
    95   // accessor
    94   static bool should_report_bug(unsigned int id) {
    96   const char* message() const    { return _message; }
       
    97   const char* detail_msg() const { return _detail_msg; }
       
    98   bool should_report_bug(unsigned int id) {
       
    99     return (id != OOM_MALLOC_ERROR) && (id != OOM_MMAP_ERROR);
    95     return (id != OOM_MALLOC_ERROR) && (id != OOM_MMAP_ERROR);
   100   }
    96   }
       
    97 
       
    98   static void report_and_die(Thread* thread, unsigned int sig, address pc, void* siginfo,
       
    99                              void* context, const char* detail_fmt, ...) ATTRIBUTE_PRINTF(6, 7);
       
   100   static void report_and_die(const char* message, const char* detail_fmt, ...) ATTRIBUTE_PRINTF(2, 3);
   101 
   101 
   102   static fdStream out;
   102   static fdStream out;
   103   static fdStream log; // error log used by VMError::report_and_die()
   103   static fdStream log; // error log used by VMError::report_and_die()
   104 
   104 
   105 public:
   105 public:
   106 
   106 
   107   // Constructor for crashes
       
   108   VMError(Thread* thread, unsigned int sig, address pc, void* siginfo,
       
   109           void* context);
       
   110   // Constructor for VM internal errors
       
   111   VMError(Thread* thread, const char* filename, int lineno,
       
   112           const char* message, const char * detail_msg);
       
   113 
       
   114   // Constructor for VM OOM errors
       
   115   VMError(Thread* thread, const char* filename, int lineno, size_t size,
       
   116           VMErrorType vm_err_type, const char* message);
       
   117   // Constructor for non-fatal errors
       
   118   VMError(const char* message);
       
   119 
       
   120   // return a string to describe the error
   107   // return a string to describe the error
   121   char *error_string(char* buf, int buflen);
   108   static char* error_string(char* buf, int buflen);
   122 
   109 
   123   // Record status of core/minidump
   110   // Record status of core/minidump
   124   static void record_coredump_status(const char* message, bool status);
   111   static void record_coredump_status(const char* message, bool status);
   125 
   112 
   126   // main error reporting function
   113   // main error reporting function
   127   void report_and_die();
   114   static void report_and_die(int id, const char* message, const char* detail_fmt, va_list detail_args,
       
   115                              Thread* thread, address pc, void* siginfo, void* context,
       
   116                              const char* filename, int lineno, size_t size) ATTRIBUTE_PRINTF(3, 0);
       
   117 
       
   118   static void report_and_die(Thread* thread, unsigned int sig, address pc,
       
   119                              void* siginfo, void* context);
       
   120 
       
   121   static void report_and_die(Thread* thread,const char* filename, int lineno, const char* message,
       
   122                              const char* detail_fmt, va_list detail_args) ATTRIBUTE_PRINTF(5, 0);
       
   123 
       
   124   static void report_and_die(Thread* thread, const char* filename, int lineno, size_t size,
       
   125                              VMErrorType vm_err_type, const char* detail_fmt,
       
   126                              va_list detail_args) ATTRIBUTE_PRINTF(6, 0);
       
   127 
       
   128   static void report_and_die(const char* message);
   128 
   129 
   129   // reporting OutOfMemoryError
   130   // reporting OutOfMemoryError
   130   void report_java_out_of_memory();
   131   static void report_java_out_of_memory(const char* message);
   131 
   132 
   132   // returns original flags for signal, if it was resetted, or -1 if
   133   // returns original flags for signal, if it was resetted, or -1 if
   133   // signal was not changed by error reporter
   134   // signal was not changed by error reporter
   134   static int get_resetted_sigflags(int sig);
   135   static int get_resetted_sigflags(int sig);
   135 
   136 
   136   // returns original handler for signal, if it was resetted, or NULL if
   137   // returns original handler for signal, if it was resetted, or NULL if
   137   // signal was not changed by error reporter
   138   // signal was not changed by error reporter
   138   static address get_resetted_sighandler(int sig);
   139   static address get_resetted_sighandler(int sig);
   139 
   140 
   140   // check to see if fatal error reporting is in progress
   141   // check to see if fatal error reporting is in progress
   141   static bool fatal_error_in_progress() { return first_error != NULL; }
   142   static bool fatal_error_in_progress() { return first_error_tid != -1; }
   142 
   143 
   143   static jlong get_first_error_tid() {
   144   static jlong get_first_error_tid() {
   144     return first_error_tid;
   145     return first_error_tid;
   145   }
   146   }
   146 };
   147 };