1 /*
2 * Copyright (c) 1997, 2014, 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 *
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
|
1 /*
2 * Copyright (c) 1997, 2015, 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 *
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 // 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); \
225 #define STATIC_ASSERT(cond)
226 #endif
227
228 // out of shared space reporting
229 enum SharedSpaceType {
230 SharedReadOnly,
231 SharedReadWrite,
232 SharedMiscData,
233 SharedMiscCode
234 };
235
236 void report_out_of_shared_space(SharedSpaceType space_type);
237
238 // out of memory reporting
239 void report_java_out_of_memory(const char* message);
240
241 // Support for self-destruct
242 bool is_error_reported();
243 void set_error_reported();
244
245 /* Test vmassert(), fatal(), guarantee(), etc. */
246 NOT_PRODUCT(void test_error_handler();)
247
248 void pd_ps(frame f);
249 void pd_obfuscate_location(char *buf, size_t buflen);
250
251 class outputStream;
252 void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size);
253
254 #endif // SHARE_VM_UTILITIES_DEBUG_HPP
|