src/share/vm/utilities/debug.hpp

Tue, 05 Apr 2011 14:12:31 -0700

author
trims
date
Tue, 05 Apr 2011 14:12:31 -0700
changeset 2708
1d1603768966
parent 2643
1216415d8e35
child 3499
aa3d708d67c4
permissions
-rw-r--r--

7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
Summary: Update the copyright to be 2010 on all changed files in OpenJDK
Reviewed-by: ohair

     1 /*
     2  * Copyright (c) 1997, 2011, 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   operator const char *() const { return _buf; }
    41 private:
    42   FormatBuffer(const FormatBuffer &); // prevent copies
    44 private:
    45   char _buf[bufsz];
    46 };
    48 template <size_t bufsz>
    49 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) {
    50   va_list argp;
    51   va_start(argp, format);
    52   jio_vsnprintf(_buf, bufsz, format, argp);
    53   va_end(argp);
    54 }
    56 template <size_t bufsz>
    57 void FormatBuffer<bufsz>::append(const char* format, ...) {
    58   // Given that the constructor does a vsnprintf we can assume that
    59   // _buf is already initialized.
    60   size_t len = strlen(_buf);
    61   char* buf_end = _buf + len;
    63   va_list argp;
    64   va_start(argp, format);
    65   jio_vsnprintf(buf_end, bufsz - len, format, argp);
    66   va_end(argp);
    67 }
    69 // Used to format messages for assert(), guarantee(), fatal(), etc.
    70 typedef FormatBuffer<> err_msg;
    72 // assertions
    73 #ifdef ASSERT
    74 #ifndef USE_REPEATED_ASSERTS
    75 #define assert(p, msg)                                                       \
    76 do {                                                                         \
    77   if (!(p)) {                                                                \
    78     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);       \
    79     BREAKPOINT;                                                              \
    80   }                                                                          \
    81 } while (0)
    82 #else // #ifndef USE_REPEATED_ASSERTS
    83 #define assert(p, msg)
    84 do {                                                                         \
    85   for (int __i = 0; __i < AssertRepeat; __i++) {                             \
    86     if (!(p)) {                                                              \
    87       report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);     \
    88       BREAKPOINT;                                                            \
    89     }                                                                        \
    90   }                                                                          \
    91 } while (0)
    92 #endif // #ifndef USE_REPEATED_ASSERTS
    94 // This version of assert is for use with checking return status from
    95 // library calls that return actual error values eg. EINVAL,
    96 // ENOMEM etc, rather than returning -1 and setting errno.
    97 // When the status is not what is expected it is very useful to know
    98 // what status was actually returned, so we pass the status variable as
    99 // an extra arg and use strerror to convert it to a meaningful string
   100 // like "Invalid argument", "out of memory" etc
   101 #define assert_status(p, status, msg)                                        \
   102 do {                                                                         \
   103   if (!(p)) {                                                                \
   104     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed",             \
   105                     err_msg("error %s(%d) %s", strerror(status),             \
   106                             status, msg));                                   \
   107     BREAKPOINT;                                                              \
   108   }                                                                          \
   109 } while (0)
   111 // Do not assert this condition if there's already another error reported.
   112 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
   113 #else // #ifdef ASSERT
   114   #define assert(p,msg)
   115   #define assert_status(p,status,msg)
   116   #define assert_if_no_error(cond,msg)
   117 #endif // #ifdef ASSERT
   119 // guarantee is like assert except it's always executed -- use it for
   120 // cheap tests that catch errors that would otherwise be hard to find.
   121 // guarantee is also used for Verify options.
   122 #define guarantee(p, msg)                                                    \
   123 do {                                                                         \
   124   if (!(p)) {                                                                \
   125     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg);    \
   126     BREAKPOINT;                                                              \
   127   }                                                                          \
   128 } while (0)
   130 #define fatal(msg)                                                           \
   131 do {                                                                         \
   132   report_fatal(__FILE__, __LINE__, msg);                                     \
   133   BREAKPOINT;                                                                \
   134 } while (0)
   136 // out of memory
   137 #define vm_exit_out_of_memory(size, msg)                                     \
   138 do {                                                                         \
   139   report_vm_out_of_memory(__FILE__, __LINE__, size, msg);                    \
   140   BREAKPOINT;                                                                \
   141 } while (0)
   143 #define ShouldNotCallThis()                                                  \
   144 do {                                                                         \
   145   report_should_not_call(__FILE__, __LINE__);                                \
   146   BREAKPOINT;                                                                \
   147 } while (0)
   149 #define ShouldNotReachHere()                                                 \
   150 do {                                                                         \
   151   report_should_not_reach_here(__FILE__, __LINE__);                          \
   152   BREAKPOINT;                                                                \
   153 } while (0)
   155 #define Unimplemented()                                                      \
   156 do {                                                                         \
   157   report_unimplemented(__FILE__, __LINE__);                                  \
   158   BREAKPOINT;                                                                \
   159 } while (0)
   161 #define Untested(msg)                                                        \
   162 do {                                                                         \
   163   report_untested(__FILE__, __LINE__, msg);                                  \
   164   BREAKPOINT;                                                                \
   165 } while (0);
   167 // error reporting helper functions
   168 void report_vm_error(const char* file, int line, const char* error_msg,
   169                      const char* detail_msg = NULL);
   170 void report_fatal(const char* file, int line, const char* message);
   171 void report_vm_out_of_memory(const char* file, int line, size_t size,
   172                              const char* message);
   173 void report_should_not_call(const char* file, int line);
   174 void report_should_not_reach_here(const char* file, int line);
   175 void report_unimplemented(const char* file, int line);
   176 void report_untested(const char* file, int line, const char* message);
   178 void warning(const char* format, ...);
   180 // out of shared space reporting
   181 enum SharedSpaceType {
   182   SharedPermGen,
   183   SharedReadOnly,
   184   SharedReadWrite,
   185   SharedMiscData
   186 };
   188 void report_out_of_shared_space(SharedSpaceType space_type);
   190 // out of memory reporting
   191 void report_java_out_of_memory(const char* message);
   193 // Support for self-destruct
   194 bool is_error_reported();
   195 void set_error_reported();
   197 /* Test assert(), fatal(), guarantee(), etc. */
   198 NOT_PRODUCT(void test_error_handler(size_t test_num);)
   200 void pd_ps(frame f);
   201 void pd_obfuscate_location(char *buf, size_t buflen);
   203 #endif // SHARE_VM_UTILITIES_DEBUG_HPP

mercurial