src/share/vm/utilities/debug.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7300
03e6d34be1f5
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial