src/share/vm/utilities/debug.hpp

Tue, 12 Feb 2013 12:19:28 -0500

author
zgu
date
Tue, 12 Feb 2013 12:19:28 -0500
changeset 4573
5ee2b330eacd
parent 4037
da91efe96a93
child 4769
be4d5c6c1f79
permissions
-rw-r--r--

8007950: Undo hs_file permission change
Summary: Reverse hs_err file permission back to 0666, as early push was premature
Reviewed-by: dsamersoff, dcubed, acorn

     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 class FormatBufferBase {
    35  protected:
    36   char* _buf;
    37   inline FormatBufferBase(char* buf) : _buf(buf) {}
    38  public:
    39   operator const char *() const { return _buf; }
    40 };
    42 // Use resource area for buffer
    43 #define RES_BUFSZ 256
    44 class FormatBufferResource : public FormatBufferBase {
    45  public:
    46   FormatBufferResource(const char * format, ...);
    47 };
    49 // Use stack for buffer
    50 template <size_t bufsz = 256>
    51 class FormatBuffer : public FormatBufferBase {
    52  public:
    53   inline FormatBuffer(const char * format, ...);
    54   inline void append(const char* format, ...);
    55   inline void print(const char* format, ...);
    56   inline void printv(const char* format, va_list ap);
    58   char* buffer() { return _buf; }
    59   int size() { return bufsz; }
    61  private:
    62   FormatBuffer(const FormatBuffer &); // prevent copies
    63   char _buffer[bufsz];
    65  protected:
    66   inline FormatBuffer();
    67 };
    69 template <size_t bufsz>
    70 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) : FormatBufferBase(_buffer) {
    71   va_list argp;
    72   va_start(argp, format);
    73   jio_vsnprintf(_buf, bufsz, format, argp);
    74   va_end(argp);
    75 }
    77 template <size_t bufsz>
    78 FormatBuffer<bufsz>::FormatBuffer() : FormatBufferBase(_buffer) {
    79   _buf[0] = '\0';
    80 }
    82 template <size_t bufsz>
    83 void FormatBuffer<bufsz>::print(const char * format, ...) {
    84   va_list argp;
    85   va_start(argp, format);
    86   jio_vsnprintf(_buf, bufsz, format, argp);
    87   va_end(argp);
    88 }
    90 template <size_t bufsz>
    91 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
    92   jio_vsnprintf(_buf, bufsz, format, argp);
    93 }
    95 template <size_t bufsz>
    96 void FormatBuffer<bufsz>::append(const char* format, ...) {
    97   // Given that the constructor does a vsnprintf we can assume that
    98   // _buf is already initialized.
    99   size_t len = strlen(_buf);
   100   char* buf_end = _buf + len;
   102   va_list argp;
   103   va_start(argp, format);
   104   jio_vsnprintf(buf_end, bufsz - len, format, argp);
   105   va_end(argp);
   106 }
   108 // Used to format messages for assert(), guarantee(), fatal(), etc.
   109 typedef FormatBuffer<> err_msg;
   110 typedef FormatBufferResource err_msg_res;
   112 // assertions
   113 #ifdef ASSERT
   114 #ifndef USE_REPEATED_ASSERTS
   115 #define assert(p, msg)                                                       \
   116 do {                                                                         \
   117   if (!(p)) {                                                                \
   118     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);       \
   119     BREAKPOINT;                                                              \
   120   }                                                                          \
   121 } while (0)
   122 #else // #ifndef USE_REPEATED_ASSERTS
   123 #define assert(p, msg)
   124 do {                                                                         \
   125   for (int __i = 0; __i < AssertRepeat; __i++) {                             \
   126     if (!(p)) {                                                              \
   127       report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);     \
   128       BREAKPOINT;                                                            \
   129     }                                                                        \
   130   }                                                                          \
   131 } while (0)
   132 #endif // #ifndef USE_REPEATED_ASSERTS
   134 // This version of assert is for use with checking return status from
   135 // library calls that return actual error values eg. EINVAL,
   136 // ENOMEM etc, rather than returning -1 and setting errno.
   137 // When the status is not what is expected it is very useful to know
   138 // what status was actually returned, so we pass the status variable as
   139 // an extra arg and use strerror to convert it to a meaningful string
   140 // like "Invalid argument", "out of memory" etc
   141 #define assert_status(p, status, msg)                                        \
   142 do {                                                                         \
   143   if (!(p)) {                                                                \
   144     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed",             \
   145                     err_msg("error %s(%d) %s", strerror(status),             \
   146                             status, msg));                                   \
   147     BREAKPOINT;                                                              \
   148   }                                                                          \
   149 } while (0)
   151 // Do not assert this condition if there's already another error reported.
   152 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
   153 #else // #ifdef ASSERT
   154   #define assert(p,msg)
   155   #define assert_status(p,status,msg)
   156   #define assert_if_no_error(cond,msg)
   157 #endif // #ifdef ASSERT
   159 // guarantee is like assert except it's always executed -- use it for
   160 // cheap tests that catch errors that would otherwise be hard to find.
   161 // guarantee is also used for Verify options.
   162 #define guarantee(p, msg)                                                    \
   163 do {                                                                         \
   164   if (!(p)) {                                                                \
   165     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg);    \
   166     BREAKPOINT;                                                              \
   167   }                                                                          \
   168 } while (0)
   170 #define fatal(msg)                                                           \
   171 do {                                                                         \
   172   report_fatal(__FILE__, __LINE__, msg);                                     \
   173   BREAKPOINT;                                                                \
   174 } while (0)
   176 // out of memory
   177 #define vm_exit_out_of_memory(size, msg)                                     \
   178 do {                                                                         \
   179   report_vm_out_of_memory(__FILE__, __LINE__, size, msg);                    \
   180   BREAKPOINT;                                                                \
   181 } while (0)
   183 #define ShouldNotCallThis()                                                  \
   184 do {                                                                         \
   185   report_should_not_call(__FILE__, __LINE__);                                \
   186   BREAKPOINT;                                                                \
   187 } while (0)
   189 #define ShouldNotReachHere()                                                 \
   190 do {                                                                         \
   191   report_should_not_reach_here(__FILE__, __LINE__);                          \
   192   BREAKPOINT;                                                                \
   193 } while (0)
   195 #define ShouldNotReachHere2(message)                                         \
   196 do {                                                                         \
   197   report_should_not_reach_here2(__FILE__, __LINE__, message);                \
   198   BREAKPOINT;                                                                \
   199 } while (0)
   201 #define Unimplemented()                                                      \
   202 do {                                                                         \
   203   report_unimplemented(__FILE__, __LINE__);                                  \
   204   BREAKPOINT;                                                                \
   205 } while (0)
   207 #define Untested(msg)                                                        \
   208 do {                                                                         \
   209   report_untested(__FILE__, __LINE__, msg);                                  \
   210   BREAKPOINT;                                                                \
   211 } while (0);
   213 // error reporting helper functions
   214 void report_vm_error(const char* file, int line, const char* error_msg,
   215                      const char* detail_msg = NULL);
   216 void report_fatal(const char* file, int line, const char* message);
   217 void report_vm_out_of_memory(const char* file, int line, size_t size,
   218                              const char* message);
   219 void report_should_not_call(const char* file, int line);
   220 void report_should_not_reach_here(const char* file, int line);
   221 void report_should_not_reach_here2(const char* file, int line, const char* message);
   222 void report_unimplemented(const char* file, int line);
   223 void report_untested(const char* file, int line, const char* message);
   225 void warning(const char* format, ...);
   227 // out of shared space reporting
   228 enum SharedSpaceType {
   229   SharedPermGen,
   230   SharedReadOnly,
   231   SharedReadWrite,
   232   SharedMiscData
   233 };
   235 void report_out_of_shared_space(SharedSpaceType space_type);
   237 // out of memory reporting
   238 void report_java_out_of_memory(const char* message);
   240 // Support for self-destruct
   241 bool is_error_reported();
   242 void set_error_reported();
   244 /* Test assert(), fatal(), guarantee(), etc. */
   245 NOT_PRODUCT(void test_error_handler(size_t test_num);)
   247 void pd_ps(frame f);
   248 void pd_obfuscate_location(char *buf, size_t buflen);
   250 #endif // SHARE_VM_UTILITIES_DEBUG_HPP

mercurial