author | tonyp |
Wed, 19 Jan 2011 19:30:42 -0500 | |
changeset 7923 | fc200fcd4e05 |
parent 7397 | 5b173b4ca846 |
child 8076 | 96d498ec7ae1 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_DEBUG_HPP |
26 |
#define SHARE_VM_UTILITIES_DEBUG_HPP |
|
27 |
||
28 |
#include "utilities/globalDefinitions.hpp" |
|
29 |
||
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
30 |
#include <stdarg.h> |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
31 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
32 |
// Simple class to format the ctor arguments into a fixed-sized buffer. |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
33 |
template <size_t bufsz = 256> |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
34 |
class FormatBuffer { |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
35 |
public: |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
36 |
inline FormatBuffer(const char * format, ...); |
7923 | 37 |
inline void append(const char* format, ...); |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
38 |
operator const char *() const { return _buf; } |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
39 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
40 |
private: |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
41 |
FormatBuffer(const FormatBuffer &); // prevent copies |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
42 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
43 |
private: |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
44 |
char _buf[bufsz]; |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
45 |
}; |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
46 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
47 |
template <size_t bufsz> |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
48 |
FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) { |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
49 |
va_list argp; |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
50 |
va_start(argp, format); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
51 |
vsnprintf(_buf, bufsz, format, argp); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
52 |
va_end(argp); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
53 |
} |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
54 |
|
7923 | 55 |
template <size_t bufsz> |
56 |
void FormatBuffer<bufsz>::append(const char* format, ...) { |
|
57 |
// Given that the constructor does a vsnprintf we can assume that |
|
58 |
// _buf is already initialized. |
|
59 |
size_t len = strlen(_buf); |
|
60 |
char* buf_end = _buf + len; |
|
61 |
||
62 |
va_list argp; |
|
63 |
va_start(argp, format); |
|
64 |
vsnprintf(buf_end, bufsz - len, format, argp); |
|
65 |
va_end(argp); |
|
66 |
} |
|
67 |
||
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
68 |
// Used to format messages for assert(), guarantee(), fatal(), etc. |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
69 |
typedef FormatBuffer<> err_msg; |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
70 |
|
1 | 71 |
// assertions |
72 |
#ifdef ASSERT |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
73 |
#ifndef USE_REPEATED_ASSERTS |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
74 |
#define assert(p, msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
75 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
76 |
if (!(p)) { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
77 |
report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
78 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
79 |
} \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
80 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
81 |
#else // #ifndef USE_REPEATED_ASSERTS |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
82 |
#define assert(p, msg) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
83 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
84 |
for (int __i = 0; __i < AssertRepeat; __i++) { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
85 |
if (!(p)) { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
86 |
report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
87 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
88 |
} \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
89 |
} \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
90 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
91 |
#endif // #ifndef USE_REPEATED_ASSERTS |
1 | 92 |
|
93 |
// This version of assert is for use with checking return status from |
|
94 |
// library calls that return actual error values eg. EINVAL, |
|
95 |
// ENOMEM etc, rather than returning -1 and setting errno. |
|
96 |
// When the status is not what is expected it is very useful to know |
|
97 |
// what status was actually returned, so we pass the status variable as |
|
98 |
// an extra arg and use strerror to convert it to a meaningful string |
|
99 |
// like "Invalid argument", "out of memory" etc |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
100 |
#define assert_status(p, status, msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
101 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
102 |
if (!(p)) { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
103 |
report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
104 |
err_msg("error %s(%d) %s", strerror(status), \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
105 |
status, msg)); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
106 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
107 |
} \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
108 |
} while (0) |
1 | 109 |
|
110 |
// Do not assert this condition if there's already another error reported. |
|
111 |
#define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg) |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
112 |
#else // #ifdef ASSERT |
1 | 113 |
#define assert(p,msg) |
114 |
#define assert_status(p,status,msg) |
|
115 |
#define assert_if_no_error(cond,msg) |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
116 |
#endif // #ifdef ASSERT |
1 | 117 |
|
118 |
// guarantee is like assert except it's always executed -- use it for |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
119 |
// cheap tests that catch errors that would otherwise be hard to find. |
1 | 120 |
// guarantee is also used for Verify options. |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
121 |
#define guarantee(p, msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
122 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
123 |
if (!(p)) { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
124 |
report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
125 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
126 |
} \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
127 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
128 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
129 |
#define fatal(msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
130 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
131 |
report_fatal(__FILE__, __LINE__, msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
132 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
133 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
134 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
135 |
// out of memory |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
136 |
#define vm_exit_out_of_memory(size, msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
137 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
138 |
report_vm_out_of_memory(__FILE__, __LINE__, size, msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
139 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
140 |
} while (0) |
1 | 141 |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
142 |
#define ShouldNotCallThis() \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
143 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
144 |
report_should_not_call(__FILE__, __LINE__); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
145 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
146 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
147 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
148 |
#define ShouldNotReachHere() \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
149 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
150 |
report_should_not_reach_here(__FILE__, __LINE__); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
151 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
152 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
153 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
154 |
#define Unimplemented() \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
155 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
156 |
report_unimplemented(__FILE__, __LINE__); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
157 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
158 |
} while (0) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
159 |
|
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
160 |
#define Untested(msg) \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
161 |
do { \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
162 |
report_untested(__FILE__, __LINE__, msg); \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
163 |
BREAKPOINT; \ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
164 |
} while (0); |
1 | 165 |
|
166 |
// error reporting helper functions |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
167 |
void report_vm_error(const char* file, int line, const char* error_msg, |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
168 |
const char* detail_msg = NULL); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
169 |
void report_fatal(const char* file, int line, const char* message); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
170 |
void report_vm_out_of_memory(const char* file, int line, size_t size, |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
171 |
const char* message); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
172 |
void report_should_not_call(const char* file, int line); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
173 |
void report_should_not_reach_here(const char* file, int line); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
174 |
void report_unimplemented(const char* file, int line); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
175 |
void report_untested(const char* file, int line, const char* message); |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
176 |
|
1 | 177 |
void warning(const char* format, ...); |
178 |
||
179 |
// out of memory reporting |
|
180 |
void report_java_out_of_memory(const char* message); |
|
181 |
||
182 |
// Support for self-destruct |
|
183 |
bool is_error_reported(); |
|
184 |
void set_error_reported(); |
|
185 |
||
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
186 |
/* Test assert(), fatal(), guarantee(), etc. */ |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
187 |
NOT_PRODUCT(void test_error_handler(size_t test_num);) |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
188 |
|
1 | 189 |
void pd_ps(frame f); |
190 |
void pd_obfuscate_location(char *buf, size_t buflen); |
|
7397 | 191 |
|
192 |
#endif // SHARE_VM_UTILITIES_DEBUG_HPP |