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