src/share/vm/utilities/debug.hpp

Wed, 01 Feb 2012 07:59:01 -0800

author
never
date
Wed, 01 Feb 2012 07:59:01 -0800
changeset 3499
aa3d708d67c4
parent 2708
1d1603768966
child 3971
6c5b7a6becc8
permissions
-rw-r--r--

7141200: log some interesting information in ring buffers for crashes
Reviewed-by: kvn, jrose, kevinw, brutisso, twisti, jmasa

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_UTILITIES_DEBUG_HPP
    26 #define SHARE_VM_UTILITIES_DEBUG_HPP
    28 #include "prims/jvm.h"
    29 #include "utilities/globalDefinitions.hpp"
    31 #include <stdarg.h>
    33 // Simple class to format the ctor arguments into a fixed-sized buffer.
    34 template <size_t bufsz = 256>
    35 class FormatBuffer {
    36  public:
    37   inline FormatBuffer(const char * format, ...);
    38   inline void append(const char* format, ...);
    39   inline void print(const char* format, ...);
    40   inline void printv(const char* format, va_list ap);
    41   operator const char *() const { return _buf; }
    43   char* buffer() { return _buf; }
    44   int size() { return bufsz; }
    46  private:
    47   FormatBuffer(const FormatBuffer &); // prevent copies
    49  protected:
    50   char _buf[bufsz];
    52   inline FormatBuffer();
    53 };
    55 template <size_t bufsz>
    56 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) {
    57   va_list argp;
    58   va_start(argp, format);
    59   jio_vsnprintf(_buf, bufsz, format, argp);
    60   va_end(argp);
    61 }
    63 template <size_t bufsz>
    64 FormatBuffer<bufsz>::FormatBuffer() {
    65   _buf[0] = '\0';
    66 }
    68 template <size_t bufsz>
    69 void FormatBuffer<bufsz>::print(const char * format, ...) {
    70   va_list argp;
    71   va_start(argp, format);
    72   jio_vsnprintf(_buf, bufsz, format, argp);
    73   va_end(argp);
    74 }
    76 template <size_t bufsz>
    77 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
    78   jio_vsnprintf(_buf, bufsz, format, argp);
    79 }
    81 template <size_t bufsz>
    82 void FormatBuffer<bufsz>::append(const char* format, ...) {
    83   // Given that the constructor does a vsnprintf we can assume that
    84   // _buf is already initialized.
    85   size_t len = strlen(_buf);
    86   char* buf_end = _buf + len;
    88   va_list argp;
    89   va_start(argp, format);
    90   jio_vsnprintf(buf_end, bufsz - len, format, argp);
    91   va_end(argp);
    92 }
    94 // Used to format messages for assert(), guarantee(), fatal(), etc.
    95 typedef FormatBuffer<> err_msg;
    97 // assertions
    98 #ifdef ASSERT
    99 #ifndef USE_REPEATED_ASSERTS
   100 #define assert(p, msg)                                                       \
   101 do {                                                                         \
   102   if (!(p)) {                                                                \
   103     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);       \
   104     BREAKPOINT;                                                              \
   105   }                                                                          \
   106 } while (0)
   107 #else // #ifndef USE_REPEATED_ASSERTS
   108 #define assert(p, msg)
   109 do {                                                                         \
   110   for (int __i = 0; __i < AssertRepeat; __i++) {                             \
   111     if (!(p)) {                                                              \
   112       report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);     \
   113       BREAKPOINT;                                                            \
   114     }                                                                        \
   115   }                                                                          \
   116 } while (0)
   117 #endif // #ifndef USE_REPEATED_ASSERTS
   119 // This version of assert is for use with checking return status from
   120 // library calls that return actual error values eg. EINVAL,
   121 // ENOMEM etc, rather than returning -1 and setting errno.
   122 // When the status is not what is expected it is very useful to know
   123 // what status was actually returned, so we pass the status variable as
   124 // an extra arg and use strerror to convert it to a meaningful string
   125 // like "Invalid argument", "out of memory" etc
   126 #define assert_status(p, status, msg)                                        \
   127 do {                                                                         \
   128   if (!(p)) {                                                                \
   129     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed",             \
   130                     err_msg("error %s(%d) %s", strerror(status),             \
   131                             status, msg));                                   \
   132     BREAKPOINT;                                                              \
   133   }                                                                          \
   134 } while (0)
   136 // Do not assert this condition if there's already another error reported.
   137 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
   138 #else // #ifdef ASSERT
   139   #define assert(p,msg)
   140   #define assert_status(p,status,msg)
   141   #define assert_if_no_error(cond,msg)
   142 #endif // #ifdef ASSERT
   144 // guarantee is like assert except it's always executed -- use it for
   145 // cheap tests that catch errors that would otherwise be hard to find.
   146 // guarantee is also used for Verify options.
   147 #define guarantee(p, msg)                                                    \
   148 do {                                                                         \
   149   if (!(p)) {                                                                \
   150     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg);    \
   151     BREAKPOINT;                                                              \
   152   }                                                                          \
   153 } while (0)
   155 #define fatal(msg)                                                           \
   156 do {                                                                         \
   157   report_fatal(__FILE__, __LINE__, msg);                                     \
   158   BREAKPOINT;                                                                \
   159 } while (0)
   161 // out of memory
   162 #define vm_exit_out_of_memory(size, msg)                                     \
   163 do {                                                                         \
   164   report_vm_out_of_memory(__FILE__, __LINE__, size, msg);                    \
   165   BREAKPOINT;                                                                \
   166 } while (0)
   168 #define ShouldNotCallThis()                                                  \
   169 do {                                                                         \
   170   report_should_not_call(__FILE__, __LINE__);                                \
   171   BREAKPOINT;                                                                \
   172 } while (0)
   174 #define ShouldNotReachHere()                                                 \
   175 do {                                                                         \
   176   report_should_not_reach_here(__FILE__, __LINE__);                          \
   177   BREAKPOINT;                                                                \
   178 } while (0)
   180 #define Unimplemented()                                                      \
   181 do {                                                                         \
   182   report_unimplemented(__FILE__, __LINE__);                                  \
   183   BREAKPOINT;                                                                \
   184 } while (0)
   186 #define Untested(msg)                                                        \
   187 do {                                                                         \
   188   report_untested(__FILE__, __LINE__, msg);                                  \
   189   BREAKPOINT;                                                                \
   190 } while (0);
   192 // error reporting helper functions
   193 void report_vm_error(const char* file, int line, const char* error_msg,
   194                      const char* detail_msg = NULL);
   195 void report_fatal(const char* file, int line, const char* message);
   196 void report_vm_out_of_memory(const char* file, int line, size_t size,
   197                              const char* message);
   198 void report_should_not_call(const char* file, int line);
   199 void report_should_not_reach_here(const char* file, int line);
   200 void report_unimplemented(const char* file, int line);
   201 void report_untested(const char* file, int line, const char* message);
   203 void warning(const char* format, ...);
   205 // out of shared space reporting
   206 enum SharedSpaceType {
   207   SharedPermGen,
   208   SharedReadOnly,
   209   SharedReadWrite,
   210   SharedMiscData
   211 };
   213 void report_out_of_shared_space(SharedSpaceType space_type);
   215 // out of memory reporting
   216 void report_java_out_of_memory(const char* message);
   218 // Support for self-destruct
   219 bool is_error_reported();
   220 void set_error_reported();
   222 /* Test assert(), fatal(), guarantee(), etc. */
   223 NOT_PRODUCT(void test_error_handler(size_t test_num);)
   225 void pd_ps(frame f);
   226 void pd_obfuscate_location(char *buf, size_t buflen);
   228 #endif // SHARE_VM_UTILITIES_DEBUG_HPP

mercurial