< prev index next >

src/share/vm/utilities/debug.hpp

Print this page




 102   va_list argp;
 103   va_start(argp, format);
 104   jio_vsnprintf(buf_end, bufsz - len, format, argp);
 105   va_end(argp);
 106 }
 107 
 108 // Used to format messages for vmassert(), guarantee(), fatal(), etc.
 109 typedef FormatBuffer<> err_msg;
 110 typedef FormatBufferResource err_msg_res;
 111 
 112 // assertions
 113 #ifndef ASSERT
 114 #define vmassert(p, msg)
 115 #else
 116 // Note: message says "assert" rather than "vmassert" for backward
 117 // compatibility with tools that parse/match the message text.
 118 #define vmassert(p, msg)                                                     \
 119 do {                                                                         \
 120   if (!(p)) {                                                                \
 121     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);       \
 122     BREAKPOINT;                                                              \
 123   }                                                                          \
 124 } while (0)
 125 #endif
 126 
 127 // For backward compatibility.
 128 #define assert(p, msg) vmassert(p, msg)
 129 
 130 // This version of vmassert is for use with checking return status from
 131 // library calls that return actual error values eg. EINVAL,
 132 // ENOMEM etc, rather than returning -1 and setting errno.
 133 // When the status is not what is expected it is very useful to know
 134 // what status was actually returned, so we pass the status variable as
 135 // an extra arg and use strerror to convert it to a meaningful string
 136 // like "Invalid argument", "out of memory" etc
 137 #define vmassert_status(p, status, msg) \
 138   vmassert(p, err_msg("error %s(%d), %s", strerror(status), status, msg))
 139 
 140 // For backward compatibility.
 141 #define assert_status(p, status, msg) vmassert_status(p, status, msg)
 142 
 143 // guarantee is like vmassert except it's always executed -- use it for
 144 // cheap tests that catch errors that would otherwise be hard to find.
 145 // guarantee is also used for Verify options.
 146 #define guarantee(p, msg)                                                    \
 147 do {                                                                         \
 148   if (!(p)) {                                                                \
 149     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg);    \
 150     BREAKPOINT;                                                              \
 151   }                                                                          \
 152 } while (0)
 153 
 154 #define fatal(msg)                                                           \
 155 do {                                                                         \
 156   report_fatal(__FILE__, __LINE__, msg);                                     \
 157   BREAKPOINT;                                                                \
 158 } while (0)
 159 
 160 // out of memory
 161 #define vm_exit_out_of_memory(size, vm_err_type, msg)                        \
 162 do {                                                                         \
 163   report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg);       \
 164   BREAKPOINT;                                                                \
 165 } while (0)
 166 
 167 #define ShouldNotCallThis()                                                  \
 168 do {                                                                         \
 169   report_should_not_call(__FILE__, __LINE__);                                \
 170   BREAKPOINT;                                                                \
 171 } while (0)
 172 
 173 #define ShouldNotReachHere()                                                 \
 174 do {                                                                         \
 175   report_should_not_reach_here(__FILE__, __LINE__);                          \
 176   BREAKPOINT;                                                                \
 177 } while (0)
 178 
 179 #define Unimplemented()                                                      \
 180 do {                                                                         \
 181   report_unimplemented(__FILE__, __LINE__);                                  \
 182   BREAKPOINT;                                                                \
 183 } while (0)
 184 
 185 #define Untested(msg)                                                        \
 186 do {                                                                         \
 187   report_untested(__FILE__, __LINE__, msg);                                  \
 188   BREAKPOINT;                                                                \
 189 } while (0);
 190 
 191 
 192 // types of VM error - originally in vmError.hpp
 193 enum VMErrorType {
 194   INTERNAL_ERROR   = 0xe0000000,
 195   OOM_MALLOC_ERROR = 0xe0000001,
 196   OOM_MMAP_ERROR   = 0xe0000002
 197 };
 198 
 199 // error reporting helper functions
 200 void report_vm_error(const char* file, int line, const char* error_msg,
 201                      const char* detail_msg = NULL);
 202 void report_fatal(const char* file, int line, const char* message);
 203 void report_vm_out_of_memory(const char* file, int line, size_t size,
 204                              VMErrorType vm_err_type, const char* message);
 205 void report_should_not_call(const char* file, int line);
 206 void report_should_not_reach_here(const char* file, int line);
 207 void report_unimplemented(const char* file, int line);
 208 void report_untested(const char* file, int line, const char* message);









 209 
 210 void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
 211 
 212 // Compile-time asserts.  Cond must be a compile-time constant expression that
 213 // is convertible to bool.  STATIC_ASSERT() can be used anywhere a declaration
 214 // may appear.
 215 //
 216 // Implementation Note: STATIC_ASSERT_FAILURE<true> provides a value member
 217 // rather than type member that could be used directly in the typedef, because
 218 // a type member would require conditional use of "typename", depending on
 219 // whether Cond is dependent or not.  The use of a value member leads to the
 220 // use of an array type.
 221 
 222 template<bool x> struct STATIC_ASSERT_FAILURE;
 223 template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
 224 
 225 #define STATIC_ASSERT(Cond) \
 226   typedef char STATIC_ASSERT_DUMMY_TYPE[ STATIC_ASSERT_FAILURE< (Cond) >::value ]
 227 
 228 // out of shared space reporting




 102   va_list argp;
 103   va_start(argp, format);
 104   jio_vsnprintf(buf_end, bufsz - len, format, argp);
 105   va_end(argp);
 106 }
 107 
 108 // Used to format messages for vmassert(), guarantee(), fatal(), etc.
 109 typedef FormatBuffer<> err_msg;
 110 typedef FormatBufferResource err_msg_res;
 111 
 112 // assertions
 113 #ifndef ASSERT
 114 #define vmassert(p, msg)
 115 #else
 116 // Note: message says "assert" rather than "vmassert" for backward
 117 // compatibility with tools that parse/match the message text.
 118 #define vmassert(p, msg)                                                     \
 119 do {                                                                         \
 120   if (!(p)) {                                                                \
 121     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg);       \

 122   }                                                                          \
 123 } while (0)
 124 #endif
 125 
 126 // For backward compatibility.
 127 #define assert(p, msg) vmassert(p, msg)
 128 
 129 // This version of vmassert is for use with checking return status from
 130 // library calls that return actual error values eg. EINVAL,
 131 // ENOMEM etc, rather than returning -1 and setting errno.
 132 // When the status is not what is expected it is very useful to know
 133 // what status was actually returned, so we pass the status variable as
 134 // an extra arg and use strerror to convert it to a meaningful string
 135 // like "Invalid argument", "out of memory" etc
 136 #define vmassert_status(p, status, msg) \
 137   vmassert(p, err_msg("error %s(%d), %s", strerror(status), status, msg))
 138 
 139 // For backward compatibility.
 140 #define assert_status(p, status, msg) vmassert_status(p, status, msg)
 141 
 142 // guarantee is like vmassert except it's always executed -- use it for
 143 // cheap tests that catch errors that would otherwise be hard to find.
 144 // guarantee is also used for Verify options.
 145 #define guarantee(p, msg)                                                    \
 146 do {                                                                         \
 147   if (!(p)) {                                                                \
 148     report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg);    \

 149   }                                                                          \
 150 } while (0)
 151 






 152 // out of memory
 153 #define vm_exit_out_of_memory(size, vm_err_type, msg) \
 154   report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg)



 155 
 156 #define fatal(msg)           report_fatal(__FILE__, __LINE__, msg)
 157 #define ShouldNotCallThis()  report_should_not_call(__FILE__, __LINE__)
 158 #define ShouldNotReachHere() report_should_not_reach_here(__FILE__, __LINE__)
 159 #define Unimplemented()      report_unimplemented(__FILE__, __LINE__)
 160 #define Untested(msg)        report_untested(__FILE__, __LINE__, msg)


















 161 
 162 
 163 // types of VM error - originally in vmError.hpp
 164 enum VMErrorType {
 165   INTERNAL_ERROR   = 0xe0000000,
 166   OOM_MALLOC_ERROR = 0xe0000001,
 167   OOM_MMAP_ERROR   = 0xe0000002
 168 };
 169 
 170 // error reporting helper functions
 171 void report_vm_error(const char* file, int line, const char* error_msg,
 172                      const char* detail_msg = NULL);
 173 




 174 void report_unimplemented(const char* file, int line);
 175 void report_untested(const char* file, int line, const char* message);
 176 
 177 NORETURN_ATTRIBUTE(void report_vm_error_noreturn(const char* file, int line,
 178                                        const char* error_msg,
 179                                        const char* detail_msg = NULL));
 180 NORETURN_ATTRIBUTE(void report_vm_out_of_memory(const char* file, int line, size_t size,
 181                                       VMErrorType vm_err_type, const char* message));
 182 NORETURN_ATTRIBUTE(void report_fatal(const char* file, int line, const char* message));
 183 NORETURN_ATTRIBUTE(void report_should_not_call(const char* file, int line));
 184 NORETURN_ATTRIBUTE(void report_should_not_reach_here(const char* file, int line));
 185 
 186 void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
 187 
 188 // Compile-time asserts.  Cond must be a compile-time constant expression that
 189 // is convertible to bool.  STATIC_ASSERT() can be used anywhere a declaration
 190 // may appear.
 191 //
 192 // Implementation Note: STATIC_ASSERT_FAILURE<true> provides a value member
 193 // rather than type member that could be used directly in the typedef, because
 194 // a type member would require conditional use of "typename", depending on
 195 // whether Cond is dependent or not.  The use of a value member leads to the
 196 // use of an array type.
 197 
 198 template<bool x> struct STATIC_ASSERT_FAILURE;
 199 template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
 200 
 201 #define STATIC_ASSERT(Cond) \
 202   typedef char STATIC_ASSERT_DUMMY_TYPE[ STATIC_ASSERT_FAILURE< (Cond) >::value ]
 203 
 204 // out of shared space reporting


< prev index next >