88 }
89
90 template <size_t bufsz>
91 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
92 jio_vsnprintf(_buf, bufsz, format, argp);
93 }
94
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;
101
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 assert(), guarantee(), fatal(), etc.
109 typedef FormatBuffer<> err_msg;
110 typedef FormatBufferResource err_msg_res;
111
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
133
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)
150
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
158
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)
169
170 #define fatal(msg) \
171 do { \
172 report_fatal(__FILE__, __LINE__, msg); \
173 BREAKPOINT; \
174 } while (0)
175
176 // out of memory
177 #define vm_exit_out_of_memory(size, vm_err_type, msg) \
178 do { \
179 report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg); \
241 #define STATIC_ASSERT(cond)
242 #endif
243
244 // out of shared space reporting
245 enum SharedSpaceType {
246 SharedReadOnly,
247 SharedReadWrite,
248 SharedMiscData,
249 SharedMiscCode
250 };
251
252 void report_out_of_shared_space(SharedSpaceType space_type);
253
254 // out of memory reporting
255 void report_java_out_of_memory(const char* message);
256
257 // Support for self-destruct
258 bool is_error_reported();
259 void set_error_reported();
260
261 /* Test assert(), fatal(), guarantee(), etc. */
262 NOT_PRODUCT(void test_error_handler();)
263
264 void pd_ps(frame f);
265 void pd_obfuscate_location(char *buf, size_t buflen);
266
267 class outputStream;
268 void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size);
269
270 #endif // SHARE_VM_UTILITIES_DEBUG_HPP
|
88 }
89
90 template <size_t bufsz>
91 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
92 jio_vsnprintf(_buf, bufsz, format, argp);
93 }
94
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;
101
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 #define vmassert(p, msg) \
117 do { \
118 if (!(p)) { \
119 report_vm_error(__FILE__, __LINE__, "vmassert(" #p ") failed", msg); \
120 BREAKPOINT; \
121 } \
122 } while (0)
123 #endif
124
125 // For backward compatibility.
126 #define assert(p, msg) vmassert(p, msg)
127
128 // This version of vmassert is for use with checking return status from
129 // library calls that return actual error values eg. EINVAL,
130 // ENOMEM etc, rather than returning -1 and setting errno.
131 // When the status is not what is expected it is very useful to know
132 // what status was actually returned, so we pass the status variable as
133 // an extra arg and use strerror to convert it to a meaningful string
134 // like "Invalid argument", "out of memory" etc
135 #define vmassert_status(p, status, msg) \
136 vmassert(p, err_msg("error %s(%d), %s", strerror(status), status, msg))
137
138 // For backward compatibility.
139 #define assert_status(p, status, msg) vmassert_status(p, status, msg)
140
141 // guarantee is like vmassert except it's always executed -- use it for
142 // cheap tests that catch errors that would otherwise be hard to find.
143 // guarantee is also used for Verify options.
144 #define guarantee(p, msg) \
145 do { \
146 if (!(p)) { \
147 report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \
148 BREAKPOINT; \
149 } \
150 } while (0)
151
152 #define fatal(msg) \
153 do { \
154 report_fatal(__FILE__, __LINE__, msg); \
155 BREAKPOINT; \
156 } while (0)
157
158 // out of memory
159 #define vm_exit_out_of_memory(size, vm_err_type, msg) \
160 do { \
161 report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg); \
223 #define STATIC_ASSERT(cond)
224 #endif
225
226 // out of shared space reporting
227 enum SharedSpaceType {
228 SharedReadOnly,
229 SharedReadWrite,
230 SharedMiscData,
231 SharedMiscCode
232 };
233
234 void report_out_of_shared_space(SharedSpaceType space_type);
235
236 // out of memory reporting
237 void report_java_out_of_memory(const char* message);
238
239 // Support for self-destruct
240 bool is_error_reported();
241 void set_error_reported();
242
243 /* Test vmassert(), fatal(), guarantee(), etc. */
244 NOT_PRODUCT(void test_error_handler();)
245
246 void pd_ps(frame f);
247 void pd_obfuscate_location(char *buf, size_t buflen);
248
249 class outputStream;
250 void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size);
251
252 #endif // SHARE_VM_UTILITIES_DEBUG_HPP
|