annotate src/share/vm/utilities/debug.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children f03d0a26bf83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // assertions
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // Turn this off by default:
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //#define USE_REPEATED_ASSERTS
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #ifdef USE_REPEATED_ASSERTS
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #define assert(p,msg) \
a61af66fc99e Initial load
duke
parents:
diff changeset
31 { for (int __i = 0; __i < AssertRepeat; __i++) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
32 if (!(p)) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
33 report_assertion_failure(__FILE__, __LINE__, \
a61af66fc99e Initial load
duke
parents:
diff changeset
34 "assert(" XSTR(p) ",\"" msg "\")");\
a61af66fc99e Initial load
duke
parents:
diff changeset
35 BREAKPOINT; \
a61af66fc99e Initial load
duke
parents:
diff changeset
36 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
37 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #define assert(p,msg) \
a61af66fc99e Initial load
duke
parents:
diff changeset
41 if (!(p)) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
42 report_assertion_failure(__FILE__, __LINE__, \
a61af66fc99e Initial load
duke
parents:
diff changeset
43 "assert(" XSTR(p) ",\"" msg "\")");\
a61af66fc99e Initial load
duke
parents:
diff changeset
44 BREAKPOINT; \
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // This version of assert is for use with checking return status from
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // library calls that return actual error values eg. EINVAL,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // ENOMEM etc, rather than returning -1 and setting errno.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // When the status is not what is expected it is very useful to know
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // what status was actually returned, so we pass the status variable as
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // an extra arg and use strerror to convert it to a meaningful string
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // like "Invalid argument", "out of memory" etc
a61af66fc99e Initial load
duke
parents:
diff changeset
55 #define assert_status(p, status, msg) \
a61af66fc99e Initial load
duke
parents:
diff changeset
56 do { \
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (!(p)) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
58 char buf[128]; \
a61af66fc99e Initial load
duke
parents:
diff changeset
59 snprintf(buf, 127, \
a61af66fc99e Initial load
duke
parents:
diff changeset
60 "assert_status(" XSTR(p) ", error: %s(%d), \"" msg "\")" , \
a61af66fc99e Initial load
duke
parents:
diff changeset
61 strerror((status)), (status)); \
a61af66fc99e Initial load
duke
parents:
diff changeset
62 report_assertion_failure(__FILE__, __LINE__, buf); \
a61af66fc99e Initial load
duke
parents:
diff changeset
63 BREAKPOINT; \
a61af66fc99e Initial load
duke
parents:
diff changeset
64 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } while (0)
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Another version of assert where the message is not a string literal
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // The boolean condition is not printed out because cpp doesn't like it.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 #define assert_msg(p, msg) \
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (!(p)) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
71 report_assertion_failure(__FILE__, __LINE__, msg); \
a61af66fc99e Initial load
duke
parents:
diff changeset
72 BREAKPOINT; \
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Do not assert this condition if there's already another error reported.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
77 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
78 #define assert(p,msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
79 #define assert_status(p,status,msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #define assert_if_no_error(cond,msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
81 #define assert_msg(cond,msg)
a61af66fc99e Initial load
duke
parents:
diff changeset
82 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // fatals
a61af66fc99e Initial load
duke
parents:
diff changeset
86 #define fatal(m) { report_fatal(__FILE__, __LINE__, m ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 #define fatal1(m,x1) { report_fatal_vararg(__FILE__, __LINE__, m, x1 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #define fatal2(m,x1,x2) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 #define fatal3(m,x1,x2,x3) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 #define fatal4(m,x1,x2,x3,x4) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3, x4 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // out of memory
a61af66fc99e Initial load
duke
parents:
diff changeset
93 #define vm_exit_out_of_memory(s,m) { report_vm_out_of_memory(__FILE__, __LINE__, s, m ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 #define vm_exit_out_of_memory1(s,m,x1) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 #define vm_exit_out_of_memory2(s,m,x1,x2) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 #define vm_exit_out_of_memory3(s,m,x1,x2,x3) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3 ); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 #define vm_exit_out_of_memory4(s,m,x1,x2,x3,x4) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3, x4); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // guarantee is like assert except it's always executed -- use it for
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // cheap tests that catch errors that would otherwise be hard to find
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // guarantee is also used for Verify options.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 #define guarantee(b,msg) { if (!(b)) fatal("guarantee(" XSTR(b) ",\"" msg "\")"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 #define ShouldNotCallThis() { report_should_not_call (__FILE__, __LINE__); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 #define ShouldNotReachHere() { report_should_not_reach_here (__FILE__, __LINE__); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 #define Unimplemented() { report_unimplemented (__FILE__, __LINE__); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 #define Untested(msg) { report_untested (__FILE__, __LINE__, msg); BREAKPOINT; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // error reporting helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void report_assertion_failure(const char* file_name, int line_no, const char* message);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void report_fatal_vararg(const char* file_name, int line_no, const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void report_fatal(const char* file_name, int line_no, const char* message);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void report_should_not_call(const char* file_name, int line_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void report_should_not_reach_here(const char* file_name, int line_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void report_unimplemented(const char* file_name, int line_no);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void report_untested(const char* file_name, int line_no, const char* msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void warning(const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // out of memory reporting
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void report_java_out_of_memory(const char* message);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Support for self-destruct
a61af66fc99e Initial load
duke
parents:
diff changeset
125 bool is_error_reported();
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void set_error_reported();
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void pd_ps(frame f);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void pd_obfuscate_location(char *buf, size_t buflen);