vmError.hpp 4.9 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29
#ifndef SHARE_VM_UTILITIES_VMERROR_HPP
#define SHARE_VM_UTILITIES_VMERROR_HPP

#include "utilities/globalDefinitions.hpp"

Z
zgu 已提交
30
class Decoder;
D
duke 已提交
31 32 33 34
class VM_ReportJavaOutOfMemory;

class VMError : public StackObj {
  friend class VM_ReportJavaOutOfMemory;
Z
zgu 已提交
35
  friend class Decoder;
D
duke 已提交
36 37 38 39 40 41 42 43 44 45

  enum ErrorType {
    internal_error = 0xe0000000,
    oom_error      = 0xe0000001
  };
  int          _id;          // Solaris/Linux signals: 0 - SIGRTMAX
                             // Windows exceptions: 0xCxxxxxxx system errors
                             //                     0x8xxxxxxx system warnings

  const char * _message;
46
  const char * _detail_msg;
D
duke 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59

  Thread *     _thread;      // NULL if it's native thread


  // additional info for crashes
  address      _pc;          // faulting PC
  void *       _siginfo;     // ExceptionRecord on Windows,
                             // siginfo_t on Solaris/Linux
  void *       _context;     // ContextRecord on Windows,
                             // ucontext_t on Solaris/Linux

  // additional info for VM internal errors
  const char * _filename;
60
  int          _lineno;
D
duke 已提交
61 62 63 64 65

  // used by fatal error handler
  int          _current_step;
  const char * _current_step_info;
  int          _verbose;
66 67 68 69
  // First error, and its thread id. We must be able to handle native thread,
  // so use thread id instead of Thread* to identify thread.
  static VMError* volatile first_error;
  static volatile jlong    first_error_tid;
D
duke 已提交
70

71 72 73 74 75 76 77 78
  // Core dump status, false if we have been unable to write a core/minidump for some reason
  static bool coredump_status;

  // When coredump_status is set to true this will contain the name/path to the core/minidump,
  // if coredump_status if false, this will (hopefully) contain a useful error explaining why
  // no core/minidump has been written to disk
  static char coredump_message[O_BUFLEN];

D
duke 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91
  // used by reporting about OOM
  size_t       _size;

  // set signal handlers on Solaris/Linux or the default exception filter
  // on Windows, to handle recursive crashes.
  void reset_signal_handlers();

  // handle -XX:+ShowMessageBoxOnError. buf is used to format the message string
  void show_message_box(char* buf, int buflen);

  // generate an error report
  void report(outputStream* st);

T
twisti 已提交
92 93 94 95
  // generate a stack trace
  static void print_stack_trace(outputStream* st, JavaThread* jt,
                                char* buf, int buflen, bool verbose = false);

D
duke 已提交
96
  // accessor
97 98
  const char* message() const    { return _message; }
  const char* detail_msg() const { return _detail_msg; }
99
  bool should_report_bug(unsigned int id) { return id != oom_error; }
D
duke 已提交
100 101 102

public:
  // Constructor for crashes
103 104
  VMError(Thread* thread, unsigned int sig, address pc, void* siginfo,
          void* context);
D
duke 已提交
105
  // Constructor for VM internal errors
106 107
  VMError(Thread* thread, const char* filename, int lineno,
          const char* message, const char * detail_msg);
D
duke 已提交
108

109 110 111
  // Constructor for VM OOM errors
  VMError(Thread* thread, const char* filename, int lineno, size_t size,
          const char* message);
D
duke 已提交
112 113 114 115 116 117
  // Constructor for non-fatal errors
  VMError(const char* message);

  // return a string to describe the error
  char *error_string(char* buf, int buflen);

118 119 120
  // Report status of core/minidump
  static void report_coredump_status(const char* message, bool status);

D
duke 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133
  // main error reporting function
  void report_and_die();

  // reporting OutOfMemoryError
  void report_java_out_of_memory();

  // returns original flags for signal, if it was resetted, or -1 if
  // signal was not changed by error reporter
  static int get_resetted_sigflags(int sig);

  // returns original handler for signal, if it was resetted, or NULL if
  // signal was not changed by error reporter
  static address get_resetted_sighandler(int sig);
134 135 136

  // check to see if fatal error reporting is in progress
  static bool fatal_error_in_progress() { return first_error != NULL; }
D
duke 已提交
137
};
138 139

#endif // SHARE_VM_UTILITIES_VMERROR_HPP