src/share/vm/utilities/debug.hpp

Mon, 02 Jul 2012 13:11:28 -0400

author
coleenp
date
Mon, 02 Jul 2012 13:11:28 -0400
changeset 3901
24b9c7f4cae6
parent 3499
aa3d708d67c4
child 3971
6c5b7a6becc8
permissions
-rw-r--r--

Merge

duke@435 1 /*
never@3499 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_DEBUG_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_DEBUG_HPP
stefank@2314 27
tonyp@2643 28 #include "prims/jvm.h"
stefank@2314 29 #include "utilities/globalDefinitions.hpp"
stefank@2314 30
jcoomes@1845 31 #include <stdarg.h>
jcoomes@1845 32
jcoomes@1845 33 // Simple class to format the ctor arguments into a fixed-sized buffer.
jcoomes@1845 34 template <size_t bufsz = 256>
jcoomes@1845 35 class FormatBuffer {
never@3499 36 public:
jcoomes@1845 37 inline FormatBuffer(const char * format, ...);
tonyp@2472 38 inline void append(const char* format, ...);
never@3499 39 inline void print(const char* format, ...);
never@3499 40 inline void printv(const char* format, va_list ap);
jcoomes@1845 41 operator const char *() const { return _buf; }
jcoomes@1845 42
never@3499 43 char* buffer() { return _buf; }
never@3499 44 int size() { return bufsz; }
never@3499 45
never@3499 46 private:
jcoomes@1845 47 FormatBuffer(const FormatBuffer &); // prevent copies
jcoomes@1845 48
never@3499 49 protected:
jcoomes@1845 50 char _buf[bufsz];
never@3499 51
never@3499 52 inline FormatBuffer();
jcoomes@1845 53 };
jcoomes@1845 54
jcoomes@1845 55 template <size_t bufsz>
jcoomes@1845 56 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) {
jcoomes@1845 57 va_list argp;
jcoomes@1845 58 va_start(argp, format);
tonyp@2643 59 jio_vsnprintf(_buf, bufsz, format, argp);
jcoomes@1845 60 va_end(argp);
jcoomes@1845 61 }
jcoomes@1845 62
tonyp@2472 63 template <size_t bufsz>
never@3499 64 FormatBuffer<bufsz>::FormatBuffer() {
never@3499 65 _buf[0] = '\0';
never@3499 66 }
never@3499 67
never@3499 68 template <size_t bufsz>
never@3499 69 void FormatBuffer<bufsz>::print(const char * format, ...) {
never@3499 70 va_list argp;
never@3499 71 va_start(argp, format);
never@3499 72 jio_vsnprintf(_buf, bufsz, format, argp);
never@3499 73 va_end(argp);
never@3499 74 }
never@3499 75
never@3499 76 template <size_t bufsz>
never@3499 77 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
never@3499 78 jio_vsnprintf(_buf, bufsz, format, argp);
never@3499 79 }
never@3499 80
never@3499 81 template <size_t bufsz>
tonyp@2472 82 void FormatBuffer<bufsz>::append(const char* format, ...) {
tonyp@2472 83 // Given that the constructor does a vsnprintf we can assume that
tonyp@2472 84 // _buf is already initialized.
tonyp@2472 85 size_t len = strlen(_buf);
tonyp@2472 86 char* buf_end = _buf + len;
tonyp@2472 87
tonyp@2472 88 va_list argp;
tonyp@2472 89 va_start(argp, format);
tonyp@2643 90 jio_vsnprintf(buf_end, bufsz - len, format, argp);
tonyp@2472 91 va_end(argp);
tonyp@2472 92 }
tonyp@2472 93
jcoomes@1845 94 // Used to format messages for assert(), guarantee(), fatal(), etc.
jcoomes@1845 95 typedef FormatBuffer<> err_msg;
jcoomes@1845 96
duke@435 97 // assertions
duke@435 98 #ifdef ASSERT
jcoomes@1845 99 #ifndef USE_REPEATED_ASSERTS
jcoomes@1845 100 #define assert(p, msg) \
jcoomes@1845 101 do { \
jcoomes@1845 102 if (!(p)) { \
jcoomes@1845 103 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
jcoomes@1845 104 BREAKPOINT; \
jcoomes@1845 105 } \
jcoomes@1845 106 } while (0)
jcoomes@1845 107 #else // #ifndef USE_REPEATED_ASSERTS
jcoomes@1845 108 #define assert(p, msg)
jcoomes@1845 109 do { \
jcoomes@1845 110 for (int __i = 0; __i < AssertRepeat; __i++) { \
jcoomes@1845 111 if (!(p)) { \
jcoomes@1845 112 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
jcoomes@1845 113 BREAKPOINT; \
jcoomes@1845 114 } \
jcoomes@1845 115 } \
jcoomes@1845 116 } while (0)
jcoomes@1845 117 #endif // #ifndef USE_REPEATED_ASSERTS
duke@435 118
duke@435 119 // This version of assert is for use with checking return status from
duke@435 120 // library calls that return actual error values eg. EINVAL,
duke@435 121 // ENOMEM etc, rather than returning -1 and setting errno.
duke@435 122 // When the status is not what is expected it is very useful to know
duke@435 123 // what status was actually returned, so we pass the status variable as
duke@435 124 // an extra arg and use strerror to convert it to a meaningful string
duke@435 125 // like "Invalid argument", "out of memory" etc
jcoomes@1845 126 #define assert_status(p, status, msg) \
jcoomes@1845 127 do { \
jcoomes@1845 128 if (!(p)) { \
jcoomes@1845 129 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \
jcoomes@1845 130 err_msg("error %s(%d) %s", strerror(status), \
jcoomes@1845 131 status, msg)); \
jcoomes@1845 132 BREAKPOINT; \
jcoomes@1845 133 } \
jcoomes@1845 134 } while (0)
duke@435 135
duke@435 136 // Do not assert this condition if there's already another error reported.
duke@435 137 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
jcoomes@1845 138 #else // #ifdef ASSERT
duke@435 139 #define assert(p,msg)
duke@435 140 #define assert_status(p,status,msg)
duke@435 141 #define assert_if_no_error(cond,msg)
jcoomes@1845 142 #endif // #ifdef ASSERT
duke@435 143
jcoomes@1845 144 // guarantee is like assert except it's always executed -- use it for
jcoomes@1845 145 // cheap tests that catch errors that would otherwise be hard to find.
jcoomes@1845 146 // guarantee is also used for Verify options.
jcoomes@1845 147 #define guarantee(p, msg) \
jcoomes@1845 148 do { \
jcoomes@1845 149 if (!(p)) { \
jcoomes@1845 150 report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \
jcoomes@1845 151 BREAKPOINT; \
jcoomes@1845 152 } \
jcoomes@1845 153 } while (0)
duke@435 154
jcoomes@1845 155 #define fatal(msg) \
jcoomes@1845 156 do { \
jcoomes@1845 157 report_fatal(__FILE__, __LINE__, msg); \
jcoomes@1845 158 BREAKPOINT; \
jcoomes@1845 159 } while (0)
duke@435 160
duke@435 161 // out of memory
jcoomes@1845 162 #define vm_exit_out_of_memory(size, msg) \
jcoomes@1845 163 do { \
jcoomes@1845 164 report_vm_out_of_memory(__FILE__, __LINE__, size, msg); \
jcoomes@1845 165 BREAKPOINT; \
jcoomes@1845 166 } while (0)
duke@435 167
jcoomes@1845 168 #define ShouldNotCallThis() \
jcoomes@1845 169 do { \
jcoomes@1845 170 report_should_not_call(__FILE__, __LINE__); \
jcoomes@1845 171 BREAKPOINT; \
jcoomes@1845 172 } while (0)
duke@435 173
jcoomes@1845 174 #define ShouldNotReachHere() \
jcoomes@1845 175 do { \
jcoomes@1845 176 report_should_not_reach_here(__FILE__, __LINE__); \
jcoomes@1845 177 BREAKPOINT; \
jcoomes@1845 178 } while (0)
jcoomes@1845 179
jcoomes@1845 180 #define Unimplemented() \
jcoomes@1845 181 do { \
jcoomes@1845 182 report_unimplemented(__FILE__, __LINE__); \
jcoomes@1845 183 BREAKPOINT; \
jcoomes@1845 184 } while (0)
jcoomes@1845 185
jcoomes@1845 186 #define Untested(msg) \
jcoomes@1845 187 do { \
jcoomes@1845 188 report_untested(__FILE__, __LINE__, msg); \
jcoomes@1845 189 BREAKPOINT; \
jcoomes@1845 190 } while (0);
duke@435 191
duke@435 192 // error reporting helper functions
jcoomes@1845 193 void report_vm_error(const char* file, int line, const char* error_msg,
jcoomes@1845 194 const char* detail_msg = NULL);
jcoomes@1845 195 void report_fatal(const char* file, int line, const char* message);
jcoomes@1845 196 void report_vm_out_of_memory(const char* file, int line, size_t size,
jcoomes@1845 197 const char* message);
jcoomes@1845 198 void report_should_not_call(const char* file, int line);
jcoomes@1845 199 void report_should_not_reach_here(const char* file, int line);
jcoomes@1845 200 void report_unimplemented(const char* file, int line);
jcoomes@1845 201 void report_untested(const char* file, int line, const char* message);
jcoomes@1845 202
duke@435 203 void warning(const char* format, ...);
duke@435 204
coleenp@2497 205 // out of shared space reporting
coleenp@2497 206 enum SharedSpaceType {
coleenp@2497 207 SharedPermGen,
coleenp@2497 208 SharedReadOnly,
coleenp@2497 209 SharedReadWrite,
coleenp@2497 210 SharedMiscData
coleenp@2497 211 };
coleenp@2497 212
coleenp@2497 213 void report_out_of_shared_space(SharedSpaceType space_type);
coleenp@2497 214
duke@435 215 // out of memory reporting
duke@435 216 void report_java_out_of_memory(const char* message);
duke@435 217
duke@435 218 // Support for self-destruct
duke@435 219 bool is_error_reported();
duke@435 220 void set_error_reported();
duke@435 221
jcoomes@1845 222 /* Test assert(), fatal(), guarantee(), etc. */
jcoomes@1845 223 NOT_PRODUCT(void test_error_handler(size_t test_num);)
jcoomes@1845 224
duke@435 225 void pd_ps(frame f);
duke@435 226 void pd_obfuscate_location(char *buf, size_t buflen);
stefank@2314 227
stefank@2314 228 #endif // SHARE_VM_UTILITIES_DEBUG_HPP

mercurial