src/share/vm/utilities/debug.hpp

Fri, 16 Aug 2013 14:11:40 -0700

author
kvn
date
Fri, 16 Aug 2013 14:11:40 -0700
changeset 5543
4b2838704fd5
parent 5365
59b052799158
child 5515
9766f73e770d
child 6461
bdd155477289
permissions
-rw-r--r--

8021898: Broken JIT compiler optimization for loop unswitching
Summary: fix method clone_projs() to clone all related MachProj nodes.
Reviewed-by: roland, adlertz

duke@435 1 /*
dcubed@5365 2 * Copyright (c) 1997, 2013, 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.
kvn@3971 34 class FormatBufferBase {
kvn@3971 35 protected:
kvn@3971 36 char* _buf;
kvn@3971 37 inline FormatBufferBase(char* buf) : _buf(buf) {}
kvn@3971 38 public:
kvn@3971 39 operator const char *() const { return _buf; }
kvn@3971 40 };
kvn@3971 41
kvn@3971 42 // Use resource area for buffer
kvn@3971 43 #define RES_BUFSZ 256
kvn@3971 44 class FormatBufferResource : public FormatBufferBase {
kvn@3971 45 public:
kvn@3971 46 FormatBufferResource(const char * format, ...);
kvn@3971 47 };
kvn@3971 48
kvn@3971 49 // Use stack for buffer
jcoomes@1845 50 template <size_t bufsz = 256>
kvn@3971 51 class FormatBuffer : public FormatBufferBase {
never@3499 52 public:
jcoomes@1845 53 inline FormatBuffer(const char * format, ...);
tonyp@2472 54 inline void append(const char* format, ...);
never@3499 55 inline void print(const char* format, ...);
never@3499 56 inline void printv(const char* format, va_list ap);
jcoomes@1845 57
never@3499 58 char* buffer() { return _buf; }
never@3499 59 int size() { return bufsz; }
never@3499 60
never@3499 61 private:
jcoomes@1845 62 FormatBuffer(const FormatBuffer &); // prevent copies
kvn@3971 63 char _buffer[bufsz];
jcoomes@1845 64
never@3499 65 protected:
never@3499 66 inline FormatBuffer();
jcoomes@1845 67 };
jcoomes@1845 68
jcoomes@1845 69 template <size_t bufsz>
kvn@3971 70 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) : FormatBufferBase(_buffer) {
jcoomes@1845 71 va_list argp;
jcoomes@1845 72 va_start(argp, format);
tonyp@2643 73 jio_vsnprintf(_buf, bufsz, format, argp);
jcoomes@1845 74 va_end(argp);
jcoomes@1845 75 }
jcoomes@1845 76
tonyp@2472 77 template <size_t bufsz>
kvn@3971 78 FormatBuffer<bufsz>::FormatBuffer() : FormatBufferBase(_buffer) {
never@3499 79 _buf[0] = '\0';
never@3499 80 }
never@3499 81
never@3499 82 template <size_t bufsz>
never@3499 83 void FormatBuffer<bufsz>::print(const char * format, ...) {
never@3499 84 va_list argp;
never@3499 85 va_start(argp, format);
never@3499 86 jio_vsnprintf(_buf, bufsz, format, argp);
never@3499 87 va_end(argp);
never@3499 88 }
never@3499 89
never@3499 90 template <size_t bufsz>
never@3499 91 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) {
never@3499 92 jio_vsnprintf(_buf, bufsz, format, argp);
never@3499 93 }
never@3499 94
never@3499 95 template <size_t bufsz>
tonyp@2472 96 void FormatBuffer<bufsz>::append(const char* format, ...) {
tonyp@2472 97 // Given that the constructor does a vsnprintf we can assume that
tonyp@2472 98 // _buf is already initialized.
tonyp@2472 99 size_t len = strlen(_buf);
tonyp@2472 100 char* buf_end = _buf + len;
tonyp@2472 101
tonyp@2472 102 va_list argp;
tonyp@2472 103 va_start(argp, format);
tonyp@2643 104 jio_vsnprintf(buf_end, bufsz - len, format, argp);
tonyp@2472 105 va_end(argp);
tonyp@2472 106 }
tonyp@2472 107
jcoomes@1845 108 // Used to format messages for assert(), guarantee(), fatal(), etc.
jcoomes@1845 109 typedef FormatBuffer<> err_msg;
kvn@3971 110 typedef FormatBufferResource err_msg_res;
jcoomes@1845 111
duke@435 112 // assertions
duke@435 113 #ifdef ASSERT
jcoomes@1845 114 #ifndef USE_REPEATED_ASSERTS
jcoomes@1845 115 #define assert(p, msg) \
jcoomes@1845 116 do { \
jcoomes@1845 117 if (!(p)) { \
jcoomes@1845 118 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
jcoomes@1845 119 BREAKPOINT; \
jcoomes@1845 120 } \
jcoomes@1845 121 } while (0)
jcoomes@1845 122 #else // #ifndef USE_REPEATED_ASSERTS
jcoomes@1845 123 #define assert(p, msg)
jcoomes@1845 124 do { \
jcoomes@1845 125 for (int __i = 0; __i < AssertRepeat; __i++) { \
jcoomes@1845 126 if (!(p)) { \
jcoomes@1845 127 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", msg); \
jcoomes@1845 128 BREAKPOINT; \
jcoomes@1845 129 } \
jcoomes@1845 130 } \
jcoomes@1845 131 } while (0)
jcoomes@1845 132 #endif // #ifndef USE_REPEATED_ASSERTS
duke@435 133
duke@435 134 // This version of assert is for use with checking return status from
duke@435 135 // library calls that return actual error values eg. EINVAL,
duke@435 136 // ENOMEM etc, rather than returning -1 and setting errno.
duke@435 137 // When the status is not what is expected it is very useful to know
duke@435 138 // what status was actually returned, so we pass the status variable as
duke@435 139 // an extra arg and use strerror to convert it to a meaningful string
duke@435 140 // like "Invalid argument", "out of memory" etc
jcoomes@1845 141 #define assert_status(p, status, msg) \
jcoomes@1845 142 do { \
jcoomes@1845 143 if (!(p)) { \
jcoomes@1845 144 report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", \
jcoomes@1845 145 err_msg("error %s(%d) %s", strerror(status), \
jcoomes@1845 146 status, msg)); \
jcoomes@1845 147 BREAKPOINT; \
jcoomes@1845 148 } \
jcoomes@1845 149 } while (0)
duke@435 150
duke@435 151 // Do not assert this condition if there's already another error reported.
duke@435 152 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
jcoomes@1845 153 #else // #ifdef ASSERT
duke@435 154 #define assert(p,msg)
duke@435 155 #define assert_status(p,status,msg)
duke@435 156 #define assert_if_no_error(cond,msg)
jcoomes@1845 157 #endif // #ifdef ASSERT
duke@435 158
jcoomes@1845 159 // guarantee is like assert except it's always executed -- use it for
jcoomes@1845 160 // cheap tests that catch errors that would otherwise be hard to find.
jcoomes@1845 161 // guarantee is also used for Verify options.
jcoomes@1845 162 #define guarantee(p, msg) \
jcoomes@1845 163 do { \
jcoomes@1845 164 if (!(p)) { \
jcoomes@1845 165 report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", msg); \
jcoomes@1845 166 BREAKPOINT; \
jcoomes@1845 167 } \
jcoomes@1845 168 } while (0)
duke@435 169
jcoomes@1845 170 #define fatal(msg) \
jcoomes@1845 171 do { \
jcoomes@1845 172 report_fatal(__FILE__, __LINE__, msg); \
jcoomes@1845 173 BREAKPOINT; \
jcoomes@1845 174 } while (0)
duke@435 175
duke@435 176 // out of memory
ccheung@4993 177 #define vm_exit_out_of_memory(size, vm_err_type, msg) \
jcoomes@1845 178 do { \
ccheung@4993 179 report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, msg); \
jcoomes@1845 180 BREAKPOINT; \
jcoomes@1845 181 } while (0)
duke@435 182
jcoomes@1845 183 #define ShouldNotCallThis() \
jcoomes@1845 184 do { \
jcoomes@1845 185 report_should_not_call(__FILE__, __LINE__); \
jcoomes@1845 186 BREAKPOINT; \
jcoomes@1845 187 } while (0)
duke@435 188
jcoomes@1845 189 #define ShouldNotReachHere() \
jcoomes@1845 190 do { \
jcoomes@1845 191 report_should_not_reach_here(__FILE__, __LINE__); \
jcoomes@1845 192 BREAKPOINT; \
jcoomes@1845 193 } while (0)
jcoomes@1845 194
jcoomes@1845 195 #define Unimplemented() \
jcoomes@1845 196 do { \
jcoomes@1845 197 report_unimplemented(__FILE__, __LINE__); \
jcoomes@1845 198 BREAKPOINT; \
jcoomes@1845 199 } while (0)
jcoomes@1845 200
jcoomes@1845 201 #define Untested(msg) \
jcoomes@1845 202 do { \
jcoomes@1845 203 report_untested(__FILE__, __LINE__, msg); \
jcoomes@1845 204 BREAKPOINT; \
jcoomes@1845 205 } while (0);
duke@435 206
ccheung@4993 207
ccheung@4993 208 // types of VM error - originally in vmError.hpp
ccheung@4993 209 enum VMErrorType {
ccheung@4993 210 INTERNAL_ERROR = 0xe0000000,
ccheung@4993 211 OOM_MALLOC_ERROR = 0xe0000001,
ccheung@4993 212 OOM_MMAP_ERROR = 0xe0000002
ccheung@4993 213 };
ccheung@4993 214
duke@435 215 // error reporting helper functions
jcoomes@1845 216 void report_vm_error(const char* file, int line, const char* error_msg,
jcoomes@1845 217 const char* detail_msg = NULL);
jcoomes@1845 218 void report_fatal(const char* file, int line, const char* message);
jcoomes@1845 219 void report_vm_out_of_memory(const char* file, int line, size_t size,
ccheung@4993 220 VMErrorType vm_err_type, const char* message);
jcoomes@1845 221 void report_should_not_call(const char* file, int line);
jcoomes@1845 222 void report_should_not_reach_here(const char* file, int line);
jcoomes@1845 223 void report_unimplemented(const char* file, int line);
jcoomes@1845 224 void report_untested(const char* file, int line, const char* message);
jcoomes@1845 225
duke@435 226 void warning(const char* format, ...);
duke@435 227
coleenp@2497 228 // out of shared space reporting
coleenp@2497 229 enum SharedSpaceType {
coleenp@2497 230 SharedPermGen,
coleenp@2497 231 SharedReadOnly,
coleenp@2497 232 SharedReadWrite,
coleenp@2497 233 SharedMiscData
coleenp@2497 234 };
coleenp@2497 235
coleenp@2497 236 void report_out_of_shared_space(SharedSpaceType space_type);
coleenp@2497 237
duke@435 238 // out of memory reporting
duke@435 239 void report_java_out_of_memory(const char* message);
duke@435 240
duke@435 241 // Support for self-destruct
duke@435 242 bool is_error_reported();
duke@435 243 void set_error_reported();
duke@435 244
jcoomes@1845 245 /* Test assert(), fatal(), guarantee(), etc. */
dcubed@5365 246 NOT_PRODUCT(void test_error_handler();)
jcoomes@1845 247
duke@435 248 void pd_ps(frame f);
duke@435 249 void pd_obfuscate_location(char *buf, size_t buflen);
stefank@2314 250
stefank@2314 251 #endif // SHARE_VM_UTILITIES_DEBUG_HPP

mercurial