Thu, 22 May 2014 15:52:41 -0400
8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, 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 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "code/codeCache.hpp" |
stefank@2314 | 28 | #include "code/icBuffer.hpp" |
stefank@2314 | 29 | #include "code/nmethod.hpp" |
stefank@2314 | 30 | #include "code/vtableStubs.hpp" |
stefank@2314 | 31 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 32 | #include "compiler/disassembler.hpp" |
stefank@2314 | 33 | #include "gc_implementation/shared/markSweep.hpp" |
stefank@2314 | 34 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 35 | #include "interpreter/bytecodeHistogram.hpp" |
stefank@2314 | 36 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 37 | #include "memory/resourceArea.hpp" |
stefank@2314 | 38 | #include "memory/universe.hpp" |
stefank@2314 | 39 | #include "oops/oop.inline.hpp" |
stefank@2314 | 40 | #include "prims/privilegedStack.hpp" |
stefank@2314 | 41 | #include "runtime/arguments.hpp" |
stefank@2314 | 42 | #include "runtime/frame.hpp" |
stefank@2314 | 43 | #include "runtime/java.hpp" |
stefank@2314 | 44 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 45 | #include "runtime/stubCodeGenerator.hpp" |
stefank@2314 | 46 | #include "runtime/stubRoutines.hpp" |
stefank@4299 | 47 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 48 | #include "runtime/vframe.hpp" |
stefank@2314 | 49 | #include "services/heapDumper.hpp" |
stefank@2314 | 50 | #include "utilities/defaultStream.hpp" |
stefank@2314 | 51 | #include "utilities/events.hpp" |
stefank@2314 | 52 | #include "utilities/top.hpp" |
stefank@2314 | 53 | #include "utilities/vmError.hpp" |
stefank@2314 | 54 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 55 | # include "os_linux.inline.hpp" |
stefank@2314 | 56 | #endif |
stefank@2314 | 57 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 58 | # include "os_solaris.inline.hpp" |
stefank@2314 | 59 | #endif |
stefank@2314 | 60 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 61 | # include "os_windows.inline.hpp" |
stefank@2314 | 62 | #endif |
never@3156 | 63 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 64 | # include "os_bsd.inline.hpp" |
never@3156 | 65 | #endif |
duke@435 | 66 | |
duke@435 | 67 | #ifndef ASSERT |
duke@435 | 68 | # ifdef _DEBUG |
duke@435 | 69 | // NOTE: don't turn the lines below into a comment -- if you're getting |
duke@435 | 70 | // a compile error here, change the settings to define ASSERT |
duke@435 | 71 | ASSERT should be defined when _DEBUG is defined. It is not intended to be used for debugging |
duke@435 | 72 | functions that do not slow down the system too much and thus can be left in optimized code. |
duke@435 | 73 | On the other hand, the code should not be included in a production version. |
duke@435 | 74 | # endif // _DEBUG |
duke@435 | 75 | #endif // ASSERT |
duke@435 | 76 | |
duke@435 | 77 | |
duke@435 | 78 | #ifdef _DEBUG |
duke@435 | 79 | # ifndef ASSERT |
duke@435 | 80 | configuration error: ASSERT must be defined in debug version |
duke@435 | 81 | # endif // ASSERT |
duke@435 | 82 | #endif // _DEBUG |
duke@435 | 83 | |
duke@435 | 84 | |
duke@435 | 85 | #ifdef PRODUCT |
duke@435 | 86 | # if -defined _DEBUG || -defined ASSERT |
duke@435 | 87 | configuration error: ASSERT et al. must not be defined in PRODUCT version |
duke@435 | 88 | # endif |
duke@435 | 89 | #endif // PRODUCT |
duke@435 | 90 | |
drchase@6680 | 91 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 92 | |
kvn@3971 | 93 | FormatBufferResource::FormatBufferResource(const char * format, ...) |
kvn@3971 | 94 | : FormatBufferBase((char*)resource_allocate_bytes(RES_BUFSZ)) { |
kvn@3971 | 95 | va_list argp; |
kvn@3971 | 96 | va_start(argp, format); |
kvn@3971 | 97 | jio_vsnprintf(_buf, RES_BUFSZ, format, argp); |
kvn@3971 | 98 | va_end(argp); |
kvn@3971 | 99 | } |
duke@435 | 100 | |
drchase@6680 | 101 | ATTRIBUTE_PRINTF(1, 2) |
duke@435 | 102 | void warning(const char* format, ...) { |
kamg@2225 | 103 | if (PrintWarnings) { |
jcoomes@4070 | 104 | FILE* const err = defaultStream::error_stream(); |
jcoomes@4070 | 105 | jio_fprintf(err, "%s warning: ", VM_Version::vm_name()); |
kamg@2225 | 106 | va_list ap; |
kamg@2225 | 107 | va_start(ap, format); |
jcoomes@4070 | 108 | vfprintf(err, format, ap); |
kamg@2225 | 109 | va_end(ap); |
jcoomes@4070 | 110 | fputc('\n', err); |
kamg@2225 | 111 | } |
duke@435 | 112 | if (BreakAtWarning) BREAKPOINT; |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | #ifndef PRODUCT |
duke@435 | 116 | |
duke@435 | 117 | #define is_token_break(ch) (isspace(ch) || (ch) == ',') |
duke@435 | 118 | |
duke@435 | 119 | static const char* last_file_name = NULL; |
duke@435 | 120 | static int last_line_no = -1; |
duke@435 | 121 | |
duke@435 | 122 | // assert/guarantee/... may happen very early during VM initialization. |
duke@435 | 123 | // Don't rely on anything that is initialized by Threads::create_vm(). For |
duke@435 | 124 | // example, don't use tty. |
jcoomes@1845 | 125 | bool error_is_suppressed(const char* file_name, int line_no) { |
duke@435 | 126 | // The following 1-element cache requires that passed-in |
duke@435 | 127 | // file names are always only constant literals. |
duke@435 | 128 | if (file_name == last_file_name && line_no == last_line_no) return true; |
duke@435 | 129 | |
duke@435 | 130 | int file_name_len = (int)strlen(file_name); |
duke@435 | 131 | char separator = os::file_separator()[0]; |
duke@435 | 132 | const char* base_name = strrchr(file_name, separator); |
duke@435 | 133 | if (base_name == NULL) |
duke@435 | 134 | base_name = file_name; |
duke@435 | 135 | |
duke@435 | 136 | // scan the SuppressErrorAt option |
duke@435 | 137 | const char* cp = SuppressErrorAt; |
duke@435 | 138 | for (;;) { |
duke@435 | 139 | const char* sfile; |
duke@435 | 140 | int sfile_len; |
duke@435 | 141 | int sline; |
duke@435 | 142 | bool noisy; |
duke@435 | 143 | while ((*cp) != '\0' && is_token_break(*cp)) cp++; |
duke@435 | 144 | if ((*cp) == '\0') break; |
duke@435 | 145 | sfile = cp; |
duke@435 | 146 | while ((*cp) != '\0' && !is_token_break(*cp) && (*cp) != ':') cp++; |
duke@435 | 147 | sfile_len = cp - sfile; |
duke@435 | 148 | if ((*cp) == ':') cp++; |
duke@435 | 149 | sline = 0; |
duke@435 | 150 | while ((*cp) != '\0' && isdigit(*cp)) { |
duke@435 | 151 | sline *= 10; |
duke@435 | 152 | sline += (*cp) - '0'; |
duke@435 | 153 | cp++; |
duke@435 | 154 | } |
duke@435 | 155 | // "file:line!" means the assert suppression is not silent |
duke@435 | 156 | noisy = ((*cp) == '!'); |
duke@435 | 157 | while ((*cp) != '\0' && !is_token_break(*cp)) cp++; |
duke@435 | 158 | // match the line |
duke@435 | 159 | if (sline != 0) { |
duke@435 | 160 | if (sline != line_no) continue; |
duke@435 | 161 | } |
duke@435 | 162 | // match the file |
duke@435 | 163 | if (sfile_len > 0) { |
duke@435 | 164 | const char* look = file_name; |
duke@435 | 165 | const char* look_max = file_name + file_name_len - sfile_len; |
duke@435 | 166 | const char* foundp; |
duke@435 | 167 | bool match = false; |
duke@435 | 168 | while (!match |
duke@435 | 169 | && (foundp = strchr(look, sfile[0])) != NULL |
duke@435 | 170 | && foundp <= look_max) { |
duke@435 | 171 | match = true; |
duke@435 | 172 | for (int i = 1; i < sfile_len; i++) { |
duke@435 | 173 | if (sfile[i] != foundp[i]) { |
duke@435 | 174 | match = false; |
duke@435 | 175 | break; |
duke@435 | 176 | } |
duke@435 | 177 | } |
duke@435 | 178 | look = foundp + 1; |
duke@435 | 179 | } |
duke@435 | 180 | if (!match) continue; |
duke@435 | 181 | } |
duke@435 | 182 | // got a match! |
duke@435 | 183 | if (noisy) { |
duke@435 | 184 | fdStream out(defaultStream::output_fd()); |
duke@435 | 185 | out.print_raw("[error suppressed at "); |
duke@435 | 186 | out.print_raw(base_name); |
duke@435 | 187 | char buf[16]; |
duke@435 | 188 | jio_snprintf(buf, sizeof(buf), ":%d]", line_no); |
duke@435 | 189 | out.print_raw_cr(buf); |
duke@435 | 190 | } else { |
duke@435 | 191 | // update 1-element cache for fast silent matches |
duke@435 | 192 | last_file_name = file_name; |
duke@435 | 193 | last_line_no = line_no; |
duke@435 | 194 | } |
duke@435 | 195 | return true; |
duke@435 | 196 | } |
duke@435 | 197 | |
duke@435 | 198 | if (!is_error_reported()) { |
duke@435 | 199 | // print a friendly hint: |
duke@435 | 200 | fdStream out(defaultStream::output_fd()); |
duke@435 | 201 | out.print_raw_cr("# To suppress the following error report, specify this argument"); |
duke@435 | 202 | out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt="); |
duke@435 | 203 | out.print_raw (base_name); |
duke@435 | 204 | char buf[16]; |
duke@435 | 205 | jio_snprintf(buf, sizeof(buf), ":%d", line_no); |
duke@435 | 206 | out.print_raw_cr(buf); |
duke@435 | 207 | } |
duke@435 | 208 | return false; |
duke@435 | 209 | } |
duke@435 | 210 | |
duke@435 | 211 | #undef is_token_break |
duke@435 | 212 | |
duke@435 | 213 | #else |
duke@435 | 214 | |
duke@435 | 215 | // Place-holder for non-existent suppression check: |
jcoomes@1845 | 216 | #define error_is_suppressed(file_name, line_no) (false) |
duke@435 | 217 | |
dcubed@3202 | 218 | #endif // !PRODUCT |
duke@435 | 219 | |
jcoomes@1845 | 220 | void report_vm_error(const char* file, int line, const char* error_msg, |
jcoomes@1845 | 221 | const char* detail_msg) |
jcoomes@1845 | 222 | { |
jcoomes@1845 | 223 | if (Debugging || error_is_suppressed(file, line)) return; |
jcoomes@1845 | 224 | Thread* const thread = ThreadLocalStorage::get_thread_slow(); |
jcoomes@1845 | 225 | VMError err(thread, file, line, error_msg, detail_msg); |
duke@435 | 226 | err.report_and_die(); |
duke@435 | 227 | } |
duke@435 | 228 | |
jcoomes@1845 | 229 | void report_fatal(const char* file, int line, const char* message) |
jcoomes@1845 | 230 | { |
jcoomes@1845 | 231 | report_vm_error(file, line, "fatal error", message); |
duke@435 | 232 | } |
duke@435 | 233 | |
jcoomes@1845 | 234 | void report_vm_out_of_memory(const char* file, int line, size_t size, |
ccheung@4993 | 235 | VMErrorType vm_err_type, const char* message) { |
coleenp@2418 | 236 | if (Debugging) return; |
duke@435 | 237 | |
dcubed@4640 | 238 | Thread* thread = ThreadLocalStorage::get_thread_slow(); |
ccheung@4993 | 239 | VMError(thread, file, line, size, vm_err_type, message).report_and_die(); |
duke@435 | 240 | |
dcubed@4640 | 241 | // The UseOSErrorReporting option in report_and_die() may allow a return |
dcubed@4640 | 242 | // to here. If so then we'll have to figure out how to handle it. |
dcubed@4640 | 243 | guarantee(false, "report_and_die() should not return here"); |
duke@435 | 244 | } |
duke@435 | 245 | |
jcoomes@1845 | 246 | void report_should_not_call(const char* file, int line) { |
jcoomes@1845 | 247 | report_vm_error(file, line, "ShouldNotCall()"); |
duke@435 | 248 | } |
duke@435 | 249 | |
jcoomes@1845 | 250 | void report_should_not_reach_here(const char* file, int line) { |
jcoomes@1845 | 251 | report_vm_error(file, line, "ShouldNotReachHere()"); |
duke@435 | 252 | } |
duke@435 | 253 | |
jcoomes@1845 | 254 | void report_unimplemented(const char* file, int line) { |
jcoomes@1845 | 255 | report_vm_error(file, line, "Unimplemented()"); |
duke@435 | 256 | } |
duke@435 | 257 | |
jcoomes@1845 | 258 | void report_untested(const char* file, int line, const char* message) { |
duke@435 | 259 | #ifndef PRODUCT |
jcoomes@1845 | 260 | warning("Untested: %s in %s: %d\n", message, file, line); |
dcubed@3202 | 261 | #endif // !PRODUCT |
duke@435 | 262 | } |
duke@435 | 263 | |
coleenp@2497 | 264 | void report_out_of_shared_space(SharedSpaceType shared_space) { |
coleenp@2497 | 265 | static const char* name[] = { |
coleenp@4037 | 266 | "native memory for metadata", |
coleenp@2497 | 267 | "shared read only space", |
coleenp@2497 | 268 | "shared read write space", |
coleenp@2497 | 269 | "shared miscellaneous data space" |
coleenp@2497 | 270 | }; |
coleenp@2497 | 271 | static const char* flag[] = { |
coleenp@4037 | 272 | "Metaspace", |
coleenp@2497 | 273 | "SharedReadOnlySize", |
coleenp@2497 | 274 | "SharedReadWriteSize", |
coleenp@2497 | 275 | "SharedMiscDataSize" |
coleenp@2497 | 276 | }; |
coleenp@2497 | 277 | |
coleenp@2497 | 278 | warning("\nThe %s is not large enough\n" |
coleenp@2497 | 279 | "to preload requested classes. Use -XX:%s=\n" |
coleenp@2497 | 280 | "to increase the initial size of %s.\n", |
coleenp@2497 | 281 | name[shared_space], flag[shared_space], name[shared_space]); |
coleenp@2497 | 282 | exit(2); |
coleenp@2497 | 283 | } |
coleenp@2497 | 284 | |
duke@435 | 285 | void report_java_out_of_memory(const char* message) { |
duke@435 | 286 | static jint out_of_memory_reported = 0; |
duke@435 | 287 | |
duke@435 | 288 | // A number of threads may attempt to report OutOfMemoryError at around the |
duke@435 | 289 | // same time. To avoid dumping the heap or executing the data collection |
duke@435 | 290 | // commands multiple times we just do it once when the first threads reports |
duke@435 | 291 | // the error. |
duke@435 | 292 | if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) { |
duke@435 | 293 | // create heap dump before OnOutOfMemoryError commands are executed |
duke@435 | 294 | if (HeapDumpOnOutOfMemoryError) { |
duke@435 | 295 | tty->print_cr("java.lang.OutOfMemoryError: %s", message); |
thurka@2130 | 296 | HeapDumper::dump_heap_from_oome(); |
duke@435 | 297 | } |
duke@435 | 298 | |
duke@435 | 299 | if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { |
duke@435 | 300 | VMError err(message); |
duke@435 | 301 | err.report_java_out_of_memory(); |
duke@435 | 302 | } |
duke@435 | 303 | } |
duke@435 | 304 | } |
duke@435 | 305 | |
duke@435 | 306 | static bool error_reported = false; |
duke@435 | 307 | |
duke@435 | 308 | // call this when the VM is dying--it might loosen some asserts |
duke@435 | 309 | void set_error_reported() { |
duke@435 | 310 | error_reported = true; |
duke@435 | 311 | } |
duke@435 | 312 | |
duke@435 | 313 | bool is_error_reported() { |
duke@435 | 314 | return error_reported; |
duke@435 | 315 | } |
duke@435 | 316 | |
jcoomes@1845 | 317 | #ifndef PRODUCT |
jcoomes@1845 | 318 | #include <signal.h> |
jcoomes@1845 | 319 | |
dcubed@5365 | 320 | void test_error_handler() { |
dcubed@5365 | 321 | uintx test_num = ErrorHandlerTest; |
jcoomes@1845 | 322 | if (test_num == 0) return; |
jcoomes@1845 | 323 | |
jcoomes@1845 | 324 | // If asserts are disabled, use the corresponding guarantee instead. |
jcoomes@1845 | 325 | size_t n = test_num; |
jcoomes@1845 | 326 | NOT_DEBUG(if (n <= 2) n += 2); |
jcoomes@1845 | 327 | |
jcoomes@1845 | 328 | const char* const str = "hello"; |
jcoomes@1845 | 329 | const size_t num = (size_t)os::vm_page_size(); |
jcoomes@1845 | 330 | |
jcoomes@1845 | 331 | const char* const eol = os::line_separator(); |
jcoomes@1845 | 332 | const char* const msg = "this message should be truncated during formatting"; |
dcubed@5365 | 333 | char * const dataPtr = NULL; // bad data pointer |
dcubed@5365 | 334 | const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer |
jcoomes@1845 | 335 | |
jcoomes@1845 | 336 | // Keep this in sync with test/runtime/6888954/vmerrors.sh. |
jcoomes@1845 | 337 | switch (n) { |
jcoomes@1845 | 338 | case 1: assert(str == NULL, "expected null"); |
jcoomes@1845 | 339 | case 2: assert(num == 1023 && *str == 'X', |
jcoomes@1845 | 340 | err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
jcoomes@1845 | 341 | case 3: guarantee(str == NULL, "expected null"); |
jcoomes@1845 | 342 | case 4: guarantee(num == 1023 && *str == 'X', |
jcoomes@1845 | 343 | err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
jcoomes@1845 | 344 | case 5: fatal("expected null"); |
jcoomes@1845 | 345 | case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str)); |
jcoomes@1845 | 346 | case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# " |
jcoomes@1845 | 347 | "%s%s# %s%s# %s%s# %s%s# %s%s# " |
jcoomes@1845 | 348 | "%s%s# %s%s# %s%s# %s%s# %s", |
jcoomes@1845 | 349 | msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, |
jcoomes@1845 | 350 | msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, |
jcoomes@1845 | 351 | msg, eol, msg, eol, msg, eol, msg, eol, msg)); |
ccheung@4993 | 352 | case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); |
jcoomes@1845 | 353 | case 9: ShouldNotCallThis(); |
jcoomes@1845 | 354 | case 10: ShouldNotReachHere(); |
jcoomes@1845 | 355 | case 11: Unimplemented(); |
dcubed@5365 | 356 | // There's no guarantee the bad data pointer will crash us |
dcubed@5365 | 357 | // so "break" out to the ShouldNotReachHere(). |
dcubed@5365 | 358 | case 12: *dataPtr = '\0'; break; |
dcubed@5365 | 359 | // There's no guarantee the bad function pointer will crash us |
dcubed@5365 | 360 | // so "break" out to the ShouldNotReachHere(). |
dcubed@5365 | 361 | case 13: (*funcPtr)(); break; |
jcoomes@1845 | 362 | |
dcubed@5365 | 363 | default: tty->print_cr("ERROR: %d: unexpected test_num value.", n); |
jcoomes@1845 | 364 | } |
dcubed@5365 | 365 | ShouldNotReachHere(); |
jcoomes@1845 | 366 | } |
dcubed@3202 | 367 | #endif // !PRODUCT |
jcoomes@1845 | 368 | |
duke@435 | 369 | // ------ helper functions for debugging go here ------------ |
duke@435 | 370 | |
duke@435 | 371 | // All debug entries should be wrapped with a stack allocated |
duke@435 | 372 | // Command object. It makes sure a resource mark is set and |
duke@435 | 373 | // flushes the logfile to prevent file sharing problems. |
duke@435 | 374 | |
duke@435 | 375 | class Command : public StackObj { |
duke@435 | 376 | private: |
duke@435 | 377 | ResourceMark rm; |
duke@435 | 378 | ResetNoHandleMark rnhm; |
duke@435 | 379 | HandleMark hm; |
duke@435 | 380 | bool debug_save; |
duke@435 | 381 | public: |
duke@435 | 382 | static int level; |
duke@435 | 383 | Command(const char* str) { |
duke@435 | 384 | debug_save = Debugging; |
duke@435 | 385 | Debugging = true; |
duke@435 | 386 | if (level++ > 0) return; |
duke@435 | 387 | tty->cr(); |
duke@435 | 388 | tty->print_cr("\"Executing %s\"", str); |
duke@435 | 389 | } |
duke@435 | 390 | |
dcubed@3202 | 391 | ~Command() { |
dcubed@3202 | 392 | tty->flush(); |
dcubed@3202 | 393 | Debugging = debug_save; |
dcubed@3202 | 394 | level--; |
dcubed@3202 | 395 | } |
duke@435 | 396 | }; |
duke@435 | 397 | |
duke@435 | 398 | int Command::level = 0; |
duke@435 | 399 | |
dcubed@3202 | 400 | #ifndef PRODUCT |
dcubed@3202 | 401 | |
duke@435 | 402 | extern "C" void blob(CodeBlob* cb) { |
duke@435 | 403 | Command c("blob"); |
duke@435 | 404 | cb->print(); |
duke@435 | 405 | } |
duke@435 | 406 | |
duke@435 | 407 | |
duke@435 | 408 | extern "C" void dump_vtable(address p) { |
duke@435 | 409 | Command c("dump_vtable"); |
coleenp@4037 | 410 | Klass* k = (Klass*)p; |
coleenp@4037 | 411 | InstanceKlass::cast(k)->vtable()->print(); |
duke@435 | 412 | } |
duke@435 | 413 | |
duke@435 | 414 | |
duke@435 | 415 | extern "C" void nm(intptr_t p) { |
duke@435 | 416 | // Actually we look through all CodeBlobs (the nm name has been kept for backwards compatability) |
duke@435 | 417 | Command c("nm"); |
duke@435 | 418 | CodeBlob* cb = CodeCache::find_blob((address)p); |
duke@435 | 419 | if (cb == NULL) { |
duke@435 | 420 | tty->print_cr("NULL"); |
duke@435 | 421 | } else { |
duke@435 | 422 | cb->print(); |
duke@435 | 423 | } |
duke@435 | 424 | } |
duke@435 | 425 | |
duke@435 | 426 | |
duke@435 | 427 | extern "C" void disnm(intptr_t p) { |
duke@435 | 428 | Command c("disnm"); |
duke@435 | 429 | CodeBlob* cb = CodeCache::find_blob((address) p); |
twisti@2350 | 430 | nmethod* nm = cb->as_nmethod_or_null(); |
twisti@2350 | 431 | if (nm) { |
twisti@2350 | 432 | nm->print(); |
twisti@2350 | 433 | Disassembler::decode(nm); |
twisti@2350 | 434 | } else { |
twisti@2350 | 435 | cb->print(); |
twisti@2350 | 436 | Disassembler::decode(cb); |
twisti@2350 | 437 | } |
duke@435 | 438 | } |
duke@435 | 439 | |
duke@435 | 440 | |
duke@435 | 441 | extern "C" void printnm(intptr_t p) { |
duke@435 | 442 | char buffer[256]; |
duke@435 | 443 | sprintf(buffer, "printnm: " INTPTR_FORMAT, p); |
duke@435 | 444 | Command c(buffer); |
duke@435 | 445 | CodeBlob* cb = CodeCache::find_blob((address) p); |
duke@435 | 446 | if (cb->is_nmethod()) { |
duke@435 | 447 | nmethod* nm = (nmethod*)cb; |
duke@435 | 448 | nm->print_nmethod(true); |
duke@435 | 449 | } |
duke@435 | 450 | } |
duke@435 | 451 | |
duke@435 | 452 | |
duke@435 | 453 | extern "C" void universe() { |
duke@435 | 454 | Command c("universe"); |
duke@435 | 455 | Universe::print(); |
duke@435 | 456 | } |
duke@435 | 457 | |
duke@435 | 458 | |
duke@435 | 459 | extern "C" void verify() { |
duke@435 | 460 | // try to run a verify on the entire system |
duke@435 | 461 | // note: this may not be safe if we're not at a safepoint; for debugging, |
duke@435 | 462 | // this manipulates the safepoint settings to avoid assertion failures |
duke@435 | 463 | Command c("universe verify"); |
duke@435 | 464 | bool safe = SafepointSynchronize::is_at_safepoint(); |
duke@435 | 465 | if (!safe) { |
duke@435 | 466 | tty->print_cr("warning: not at safepoint -- verify may fail"); |
duke@435 | 467 | SafepointSynchronize::set_is_at_safepoint(); |
duke@435 | 468 | } |
duke@435 | 469 | // Ensure Eden top is correct before verification |
duke@435 | 470 | Universe::heap()->prepare_for_verify(); |
johnc@4176 | 471 | Universe::verify(); |
duke@435 | 472 | if (!safe) SafepointSynchronize::set_is_not_at_safepoint(); |
duke@435 | 473 | } |
duke@435 | 474 | |
duke@435 | 475 | |
duke@435 | 476 | extern "C" void pp(void* p) { |
duke@435 | 477 | Command c("pp"); |
duke@435 | 478 | FlagSetting fl(PrintVMMessages, true); |
never@2868 | 479 | FlagSetting f2(DisplayVMOutput, true); |
duke@435 | 480 | if (Universe::heap()->is_in(p)) { |
duke@435 | 481 | oop obj = oop(p); |
duke@435 | 482 | obj->print(); |
duke@435 | 483 | } else { |
dcubed@3202 | 484 | tty->print(PTR_FORMAT, p); |
duke@435 | 485 | } |
duke@435 | 486 | } |
duke@435 | 487 | |
duke@435 | 488 | |
duke@435 | 489 | // pv: print vm-printable object |
duke@435 | 490 | extern "C" void pa(intptr_t p) { ((AllocatedObj*) p)->print(); } |
duke@435 | 491 | extern "C" void findpc(intptr_t x); |
duke@435 | 492 | |
dcubed@3202 | 493 | #endif // !PRODUCT |
dcubed@3202 | 494 | |
duke@435 | 495 | extern "C" void ps() { // print stack |
dcubed@3202 | 496 | if (Thread::current() == NULL) return; |
duke@435 | 497 | Command c("ps"); |
duke@435 | 498 | |
duke@435 | 499 | |
duke@435 | 500 | // Prints the stack of the current Java thread |
duke@435 | 501 | JavaThread* p = JavaThread::active(); |
duke@435 | 502 | tty->print(" for thread: "); |
duke@435 | 503 | p->print(); |
duke@435 | 504 | tty->cr(); |
duke@435 | 505 | |
duke@435 | 506 | if (p->has_last_Java_frame()) { |
duke@435 | 507 | // If the last_Java_fp is set we are in C land and |
duke@435 | 508 | // can call the standard stack_trace function. |
dcubed@3202 | 509 | #ifdef PRODUCT |
dcubed@3202 | 510 | p->print_stack(); |
dcubed@3202 | 511 | } else { |
dcubed@3202 | 512 | tty->print_cr("Cannot find the last Java frame, printing stack disabled."); |
dcubed@3202 | 513 | #else // !PRODUCT |
duke@435 | 514 | p->trace_stack(); |
duke@435 | 515 | } else { |
duke@435 | 516 | frame f = os::current_frame(); |
duke@435 | 517 | RegisterMap reg_map(p); |
duke@435 | 518 | f = f.sender(®_map); |
duke@435 | 519 | tty->print("(guessing starting frame id=%#p based on current fp)\n", f.id()); |
duke@435 | 520 | p->trace_stack_from(vframe::new_vframe(&f, ®_map, p)); |
duke@435 | 521 | pd_ps(f); |
dcubed@3202 | 522 | #endif // PRODUCT |
duke@435 | 523 | } |
duke@435 | 524 | |
duke@435 | 525 | } |
duke@435 | 526 | |
never@2868 | 527 | extern "C" void pfl() { |
never@2868 | 528 | // print frame layout |
never@2868 | 529 | Command c("pfl"); |
never@2868 | 530 | JavaThread* p = JavaThread::active(); |
never@2868 | 531 | tty->print(" for thread: "); |
never@2868 | 532 | p->print(); |
never@2868 | 533 | tty->cr(); |
never@2868 | 534 | if (p->has_last_Java_frame()) { |
never@2868 | 535 | p->print_frame_layout(); |
never@2868 | 536 | } |
never@2868 | 537 | } |
duke@435 | 538 | |
dcubed@3202 | 539 | #ifndef PRODUCT |
dcubed@3202 | 540 | |
duke@435 | 541 | extern "C" void psf() { // print stack frames |
duke@435 | 542 | { |
duke@435 | 543 | Command c("psf"); |
duke@435 | 544 | JavaThread* p = JavaThread::active(); |
duke@435 | 545 | tty->print(" for thread: "); |
duke@435 | 546 | p->print(); |
duke@435 | 547 | tty->cr(); |
duke@435 | 548 | if (p->has_last_Java_frame()) { |
duke@435 | 549 | p->trace_frames(); |
duke@435 | 550 | } |
duke@435 | 551 | } |
duke@435 | 552 | } |
duke@435 | 553 | |
duke@435 | 554 | |
duke@435 | 555 | extern "C" void threads() { |
duke@435 | 556 | Command c("threads"); |
duke@435 | 557 | Threads::print(false, true); |
duke@435 | 558 | } |
duke@435 | 559 | |
duke@435 | 560 | |
duke@435 | 561 | extern "C" void psd() { |
duke@435 | 562 | Command c("psd"); |
duke@435 | 563 | SystemDictionary::print(); |
duke@435 | 564 | } |
duke@435 | 565 | |
duke@435 | 566 | |
duke@435 | 567 | extern "C" void safepoints() { |
duke@435 | 568 | Command c("safepoints"); |
duke@435 | 569 | SafepointSynchronize::print_state(); |
duke@435 | 570 | } |
duke@435 | 571 | |
dcubed@3202 | 572 | #endif // !PRODUCT |
duke@435 | 573 | |
duke@435 | 574 | extern "C" void pss() { // print all stacks |
dcubed@3202 | 575 | if (Thread::current() == NULL) return; |
duke@435 | 576 | Command c("pss"); |
dcubed@3202 | 577 | Threads::print(true, PRODUCT_ONLY(false) NOT_PRODUCT(true)); |
duke@435 | 578 | } |
duke@435 | 579 | |
dcubed@3202 | 580 | #ifndef PRODUCT |
duke@435 | 581 | |
duke@435 | 582 | extern "C" void debug() { // to set things up for compiler debugging |
duke@435 | 583 | Command c("debug"); |
duke@435 | 584 | WizardMode = true; |
duke@435 | 585 | PrintVMMessages = PrintCompilation = true; |
duke@435 | 586 | PrintInlining = PrintAssembly = true; |
duke@435 | 587 | tty->flush(); |
duke@435 | 588 | } |
duke@435 | 589 | |
duke@435 | 590 | |
duke@435 | 591 | extern "C" void ndebug() { // undo debug() |
duke@435 | 592 | Command c("ndebug"); |
duke@435 | 593 | PrintCompilation = false; |
duke@435 | 594 | PrintInlining = PrintAssembly = false; |
duke@435 | 595 | tty->flush(); |
duke@435 | 596 | } |
duke@435 | 597 | |
duke@435 | 598 | |
duke@435 | 599 | extern "C" void flush() { |
duke@435 | 600 | Command c("flush"); |
duke@435 | 601 | tty->flush(); |
duke@435 | 602 | } |
duke@435 | 603 | |
never@3571 | 604 | extern "C" void events() { |
never@3571 | 605 | Command c("events"); |
never@3571 | 606 | Events::print(); |
never@3571 | 607 | } |
duke@435 | 608 | |
coleenp@4037 | 609 | extern "C" Method* findm(intptr_t pc) { |
duke@435 | 610 | Command c("findm"); |
duke@435 | 611 | nmethod* nm = CodeCache::find_nmethod((address)pc); |
coleenp@4037 | 612 | return (nm == NULL) ? (Method*)NULL : nm->method(); |
duke@435 | 613 | } |
duke@435 | 614 | |
duke@435 | 615 | |
duke@435 | 616 | extern "C" nmethod* findnm(intptr_t addr) { |
duke@435 | 617 | Command c("findnm"); |
duke@435 | 618 | return CodeCache::find_nmethod((address)addr); |
duke@435 | 619 | } |
duke@435 | 620 | |
duke@435 | 621 | // Another interface that isn't ambiguous in dbx. |
duke@435 | 622 | // Can we someday rename the other find to hsfind? |
duke@435 | 623 | extern "C" void hsfind(intptr_t x) { |
duke@435 | 624 | Command c("hsfind"); |
bobv@2036 | 625 | os::print_location(tty, x, false); |
duke@435 | 626 | } |
duke@435 | 627 | |
duke@435 | 628 | |
duke@435 | 629 | extern "C" void find(intptr_t x) { |
duke@435 | 630 | Command c("find"); |
bobv@2036 | 631 | os::print_location(tty, x, false); |
duke@435 | 632 | } |
duke@435 | 633 | |
duke@435 | 634 | |
duke@435 | 635 | extern "C" void findpc(intptr_t x) { |
duke@435 | 636 | Command c("findpc"); |
bobv@2036 | 637 | os::print_location(tty, x, true); |
duke@435 | 638 | } |
duke@435 | 639 | |
duke@435 | 640 | |
coleenp@4037 | 641 | // Need method pointer to find bcp, when not in permgen. |
coleenp@4037 | 642 | extern "C" void findbcp(intptr_t method, intptr_t bcp) { |
coleenp@4037 | 643 | Command c("findbcp"); |
coleenp@4037 | 644 | Method* mh = (Method*)method; |
coleenp@4037 | 645 | if (!mh->is_native()) { |
coleenp@4037 | 646 | tty->print_cr("bci_from(%p) = %d; print_codes():", |
coleenp@4037 | 647 | mh, mh->bci_from(address(bcp))); |
coleenp@4037 | 648 | mh->print_codes_on(tty); |
coleenp@4037 | 649 | } |
coleenp@4037 | 650 | } |
coleenp@4037 | 651 | |
duke@435 | 652 | // int versions of all methods to avoid having to type type casts in the debugger |
duke@435 | 653 | |
duke@435 | 654 | void pp(intptr_t p) { pp((void*)p); } |
duke@435 | 655 | void pp(oop p) { pp((void*)p); } |
duke@435 | 656 | |
duke@435 | 657 | void help() { |
duke@435 | 658 | Command c("help"); |
duke@435 | 659 | tty->print_cr("basic"); |
duke@435 | 660 | tty->print_cr(" pp(void* p) - try to make sense of p"); |
duke@435 | 661 | tty->print_cr(" pv(intptr_t p)- ((PrintableResourceObj*) p)->print()"); |
duke@435 | 662 | tty->print_cr(" ps() - print current thread stack"); |
duke@435 | 663 | tty->print_cr(" pss() - print all thread stacks"); |
coleenp@4037 | 664 | tty->print_cr(" pm(int pc) - print Method* given compiled PC"); |
coleenp@4037 | 665 | tty->print_cr(" findm(intptr_t pc) - finds Method*"); |
duke@435 | 666 | tty->print_cr(" find(intptr_t x) - finds & prints nmethod/stub/bytecode/oop based on pointer into it"); |
duke@435 | 667 | |
duke@435 | 668 | tty->print_cr("misc."); |
duke@435 | 669 | tty->print_cr(" flush() - flushes the log file"); |
never@3571 | 670 | tty->print_cr(" events() - dump events from ring buffers"); |
duke@435 | 671 | |
duke@435 | 672 | |
duke@435 | 673 | tty->print_cr("compiler debugging"); |
duke@435 | 674 | tty->print_cr(" debug() - to set things up for compiler debugging"); |
duke@435 | 675 | tty->print_cr(" ndebug() - undo debug"); |
duke@435 | 676 | } |
duke@435 | 677 | |
dcubed@3202 | 678 | #endif // !PRODUCT |