1 /* 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/systemDictionary.hpp" 27 #include "code/codeCache.hpp" 28 #include "code/icBuffer.hpp" 29 #include "code/nmethod.hpp" 30 #include "code/vtableStubs.hpp" 31 #include "compiler/compileBroker.hpp" 32 #include "compiler/disassembler.hpp" 33 #include "gc/shared/collectedHeap.hpp" 34 #include "interpreter/bytecodeHistogram.hpp" 35 #include "interpreter/interpreter.hpp" 36 #include "memory/resourceArea.hpp" 37 #include "memory/universe.hpp" 38 #include "oops/oop.inline.hpp" 39 #include "prims/jvm.h" 40 #include "prims/privilegedStack.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/atomic.hpp" 43 #include "runtime/frame.hpp" 44 #include "runtime/java.hpp" 45 #include "runtime/os.hpp" 46 #include "runtime/sharedRuntime.hpp" 47 #include "runtime/stubCodeGenerator.hpp" 48 #include "runtime/stubRoutines.hpp" 49 #include "runtime/thread.inline.hpp" 50 #include "runtime/vframe.hpp" 51 #include "runtime/vm_version.hpp" 52 #include "services/heapDumper.hpp" 53 #include "utilities/defaultStream.hpp" 54 #include "utilities/events.hpp" 55 #include "utilities/macros.hpp" 56 #include "utilities/vmError.hpp" 57 58 #include <stdio.h> 59 60 #ifndef ASSERT 61 # ifdef _DEBUG 62 // NOTE: don't turn the lines below into a comment -- if you're getting 63 // a compile error here, change the settings to define ASSERT 64 ASSERT should be defined when _DEBUG is defined. It is not intended to be used for debugging 65 functions that do not slow down the system too much and thus can be left in optimized code. 66 On the other hand, the code should not be included in a production version. 67 # endif // _DEBUG 68 #endif // ASSERT 69 70 71 #ifdef _DEBUG 72 # ifndef ASSERT 73 configuration error: ASSERT must be defined in debug version 74 # endif // ASSERT 75 #endif // _DEBUG 76 77 78 #ifdef PRODUCT 79 # if -defined _DEBUG || -defined ASSERT 80 configuration error: ASSERT et al. must not be defined in PRODUCT version 81 # endif 82 #endif // PRODUCT 83 84 FormatBufferResource::FormatBufferResource(const char * format, ...) 85 : FormatBufferBase((char*)resource_allocate_bytes(FormatBufferBase::BufferSize)) { 86 va_list argp; 87 va_start(argp, format); 88 jio_vsnprintf(_buf, FormatBufferBase::BufferSize, format, argp); 89 va_end(argp); 90 } 91 92 ATTRIBUTE_PRINTF(1, 2) 93 void warning(const char* format, ...) { 94 if (PrintWarnings) { 95 FILE* const err = defaultStream::error_stream(); 96 jio_fprintf(err, "%s warning: ", VM_Version::vm_name()); 97 va_list ap; 98 va_start(ap, format); 99 vfprintf(err, format, ap); 100 va_end(ap); 101 fputc('\n', err); 102 } 103 if (BreakAtWarning) BREAKPOINT; 104 } 105 106 #ifndef PRODUCT 107 108 #define is_token_break(ch) (isspace(ch) || (ch) == ',') 109 110 static const char* last_file_name = NULL; 111 static int last_line_no = -1; 112 113 // assert/guarantee/... may happen very early during VM initialization. 114 // Don't rely on anything that is initialized by Threads::create_vm(). For 115 // example, don't use tty. 116 bool error_is_suppressed(const char* file_name, int line_no) { 117 // The following 1-element cache requires that passed-in 118 // file names are always only constant literals. 119 if (file_name == last_file_name && line_no == last_line_no) return true; 120 121 int file_name_len = (int)strlen(file_name); 122 char separator = os::file_separator()[0]; 123 const char* base_name = strrchr(file_name, separator); 124 if (base_name == NULL) 125 base_name = file_name; 126 127 // scan the SuppressErrorAt option 128 const char* cp = SuppressErrorAt; 129 for (;;) { 130 const char* sfile; 131 int sfile_len; 132 int sline; 133 bool noisy; 134 while ((*cp) != '\0' && is_token_break(*cp)) cp++; 135 if ((*cp) == '\0') break; 136 sfile = cp; 137 while ((*cp) != '\0' && !is_token_break(*cp) && (*cp) != ':') cp++; 138 sfile_len = cp - sfile; 139 if ((*cp) == ':') cp++; 140 sline = 0; 141 while ((*cp) != '\0' && isdigit(*cp)) { 142 sline *= 10; 143 sline += (*cp) - '0'; 144 cp++; 145 } 146 // "file:line!" means the assert suppression is not silent 147 noisy = ((*cp) == '!'); 148 while ((*cp) != '\0' && !is_token_break(*cp)) cp++; 149 // match the line 150 if (sline != 0) { 151 if (sline != line_no) continue; 152 } 153 // match the file 154 if (sfile_len > 0) { 155 const char* look = file_name; 156 const char* look_max = file_name + file_name_len - sfile_len; 157 const char* foundp; 158 bool match = false; 159 while (!match 160 && (foundp = strchr(look, sfile[0])) != NULL 161 && foundp <= look_max) { 162 match = true; 163 for (int i = 1; i < sfile_len; i++) { 164 if (sfile[i] != foundp[i]) { 165 match = false; 166 break; 167 } 168 } 169 look = foundp + 1; 170 } 171 if (!match) continue; 172 } 173 // got a match! 174 if (noisy) { 175 fdStream out(defaultStream::output_fd()); 176 out.print_raw("[error suppressed at "); 177 out.print_raw(base_name); 178 char buf[16]; 179 jio_snprintf(buf, sizeof(buf), ":%d]", line_no); 180 out.print_raw_cr(buf); 181 } else { 182 // update 1-element cache for fast silent matches 183 last_file_name = file_name; 184 last_line_no = line_no; 185 } 186 return true; 187 } 188 189 if (!is_error_reported() && !SuppressFatalErrorMessage) { 190 // print a friendly hint: 191 fdStream out(defaultStream::output_fd()); 192 out.print_raw_cr("# To suppress the following error report, specify this argument"); 193 out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt="); 194 out.print_raw (base_name); 195 char buf[16]; 196 jio_snprintf(buf, sizeof(buf), ":%d", line_no); 197 out.print_raw_cr(buf); 198 } 199 return false; 200 } 201 202 #undef is_token_break 203 204 #else 205 206 // Place-holder for non-existent suppression check: 207 #define error_is_suppressed(file_name, line_no) (false) 208 209 #endif // !PRODUCT 210 211 void report_vm_error(const char* file, int line, const char* error_msg) 212 { 213 report_vm_error(file, line, error_msg, "%s", ""); 214 } 215 216 void report_vm_error(const char* file, int line, const char* error_msg, const char* detail_fmt, ...) 217 { 218 if (Debugging || error_is_suppressed(file, line)) return; 219 va_list detail_args; 220 va_start(detail_args, detail_fmt); 221 VMError::report_and_die(Thread::current_or_null(), file, line, error_msg, detail_fmt, detail_args); 222 va_end(detail_args); 223 } 224 225 void report_vm_status_error(const char* file, int line, const char* error_msg, 226 int status, const char* detail) { 227 report_vm_error(file, line, error_msg, "error %s(%d), %s", os::errno_name(status), status, detail); 228 } 229 230 void report_fatal(const char* file, int line, const char* detail_fmt, ...) 231 { 232 if (Debugging || error_is_suppressed(file, line)) return; 233 va_list detail_args; 234 va_start(detail_args, detail_fmt); 235 VMError::report_and_die(Thread::current_or_null(), file, line, "fatal error", detail_fmt, detail_args); 236 va_end(detail_args); 237 } 238 239 void report_vm_out_of_memory(const char* file, int line, size_t size, 240 VMErrorType vm_err_type, const char* detail_fmt, ...) { 241 if (Debugging) return; 242 va_list detail_args; 243 va_start(detail_args, detail_fmt); 244 VMError::report_and_die(Thread::current_or_null(), file, line, size, vm_err_type, detail_fmt, detail_args); 245 va_end(detail_args); 246 247 // The UseOSErrorReporting option in report_and_die() may allow a return 248 // to here. If so then we'll have to figure out how to handle it. 249 guarantee(false, "report_and_die() should not return here"); 250 } 251 252 void report_should_not_call(const char* file, int line) { 253 report_vm_error(file, line, "ShouldNotCall()"); 254 } 255 256 void report_should_not_reach_here(const char* file, int line) { 257 report_vm_error(file, line, "ShouldNotReachHere()"); 258 } 259 260 void report_unimplemented(const char* file, int line) { 261 report_vm_error(file, line, "Unimplemented()"); 262 } 263 264 #ifdef ASSERT 265 bool is_executing_unit_tests() { 266 return ExecutingUnitTests; 267 } 268 269 void report_assert_msg(const char* msg, ...) { 270 va_list ap; 271 va_start(ap, msg); 272 273 fprintf(stderr, "assert failed: %s\n", err_msg(FormatBufferDummy(), msg, ap).buffer()); 274 275 va_end(ap); 276 } 277 #endif // ASSERT 278 279 void report_untested(const char* file, int line, const char* message) { 280 #ifndef PRODUCT 281 warning("Untested: %s in %s: %d\n", message, file, line); 282 #endif // !PRODUCT 283 } 284 285 void report_out_of_shared_space(SharedSpaceType shared_space) { 286 if (shared_space == SharedOptional) { 287 // The estimated shared_optional_space size is large enough 288 // for all class bytes. It should not run out of space. 289 ShouldNotReachHere(); 290 } 291 292 static const char* name[] = { 293 "shared read only space", 294 "shared read write space", 295 "shared miscellaneous data space", 296 "shared miscellaneous code space" 297 }; 298 static const char* flag[] = { 299 "SharedReadOnlySize", 300 "SharedReadWriteSize", 301 "SharedMiscDataSize", 302 "SharedMiscCodeSize" 303 }; 304 305 warning("\nThe %s is not large enough\n" 306 "to preload requested classes. Use -XX:%s=<size>\n" 307 "to increase the initial size of %s.\n", 308 name[shared_space], flag[shared_space], name[shared_space]); 309 exit(2); 310 } 311 312 313 void report_insufficient_metaspace(size_t required_size) { 314 warning("\nThe MaxMetaspaceSize of " SIZE_FORMAT " bytes is not large enough.\n" 315 "Either don't specify the -XX:MaxMetaspaceSize=<size>\n" 316 "or increase the size to at least " SIZE_FORMAT ".\n", 317 MaxMetaspaceSize, required_size); 318 exit(2); 319 } 320 321 void report_java_out_of_memory(const char* message) { 322 static jint out_of_memory_reported = 0; 323 324 // A number of threads may attempt to report OutOfMemoryError at around the 325 // same time. To avoid dumping the heap or executing the data collection 326 // commands multiple times we just do it once when the first threads reports 327 // the error. 328 if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) { 329 // create heap dump before OnOutOfMemoryError commands are executed 330 if (HeapDumpOnOutOfMemoryError) { 331 tty->print_cr("java.lang.OutOfMemoryError: %s", message); 332 HeapDumper::dump_heap_from_oome(); 333 } 334 335 if (OnOutOfMemoryError && OnOutOfMemoryError[0]) { 336 VMError::report_java_out_of_memory(message); 337 } 338 339 if (CrashOnOutOfMemoryError) { 340 tty->print_cr("Aborting due to java.lang.OutOfMemoryError: %s", message); 341 fatal("OutOfMemory encountered: %s", message); 342 } 343 344 if (ExitOnOutOfMemoryError) { 345 tty->print_cr("Terminating due to java.lang.OutOfMemoryError: %s", message); 346 os::exit(3); 347 } 348 } 349 } 350 351 static bool error_reported = false; 352 353 // call this when the VM is dying--it might loosen some asserts 354 void set_error_reported() { 355 error_reported = true; 356 } 357 358 bool is_error_reported() { 359 return error_reported; 360 } 361 362 #ifndef PRODUCT 363 #include <signal.h> 364 365 typedef void (*voidfun_t)(); 366 // Crash with an authentic sigfpe 367 static void crash_with_sigfpe() { 368 // generate a native synchronous SIGFPE where possible; 369 // if that did not cause a signal (e.g. on ppc), just 370 // raise the signal. 371 volatile int x = 0; 372 volatile int y = 1/x; 373 #ifndef _WIN32 374 // OSX implements raise(sig) incorrectly so we need to 375 // explicitly target the current thread 376 pthread_kill(pthread_self(), SIGFPE); 377 #endif 378 } // end: crash_with_sigfpe 379 380 // crash with sigsegv at non-null address. 381 static void crash_with_segfault() { 382 383 char* const crash_addr = (char*) get_segfault_address(); 384 *crash_addr = 'X'; 385 386 } // end: crash_with_segfault 387 388 // returns an address which is guaranteed to generate a SIGSEGV on read, 389 // for test purposes, which is not NULL and contains bits in every word 390 void* get_segfault_address() { 391 return (void*) 392 #ifdef _LP64 393 0xABC0000000000ABCULL; 394 #else 395 0x00000ABC; 396 #endif 397 } 398 399 void test_error_handler() { 400 controlled_crash(ErrorHandlerTest); 401 } 402 403 void controlled_crash(int how) { 404 if (how == 0) return; 405 406 // If asserts are disabled, use the corresponding guarantee instead. 407 NOT_DEBUG(if (how <= 2) how += 2); 408 409 const char* const str = "hello"; 410 const size_t num = (size_t)os::vm_page_size(); 411 412 const char* const eol = os::line_separator(); 413 const char* const msg = "this message should be truncated during formatting"; 414 char * const dataPtr = NULL; // bad data pointer 415 const void (*funcPtr)(void) = (const void(*)()) 0xF; // bad function pointer 416 417 // Keep this in sync with test/runtime/ErrorHandling/ErrorHandler.java 418 switch (how) { 419 case 1: vmassert(str == NULL, "expected null"); 420 case 2: vmassert(num == 1023 && *str == 'X', 421 "num=" SIZE_FORMAT " str=\"%s\"", num, str); 422 case 3: guarantee(str == NULL, "expected null"); 423 case 4: guarantee(num == 1023 && *str == 'X', 424 "num=" SIZE_FORMAT " str=\"%s\"", num, str); 425 case 5: fatal("expected null"); 426 case 6: fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str); 427 case 7: fatal("%s%s# %s%s# %s%s# %s%s# %s%s# " 428 "%s%s# %s%s# %s%s# %s%s# %s%s# " 429 "%s%s# %s%s# %s%s# %s%s# %s", 430 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, 431 msg, eol, msg, eol, msg, eol, msg, eol, msg, eol, 432 msg, eol, msg, eol, msg, eol, msg, eol, msg); 433 case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); 434 case 9: ShouldNotCallThis(); 435 case 10: ShouldNotReachHere(); 436 case 11: Unimplemented(); 437 // There's no guarantee the bad data pointer will crash us 438 // so "break" out to the ShouldNotReachHere(). 439 case 12: *dataPtr = '\0'; break; 440 // There's no guarantee the bad function pointer will crash us 441 // so "break" out to the ShouldNotReachHere(). 442 case 13: (*funcPtr)(); break; 443 case 14: crash_with_segfault(); break; 444 case 15: crash_with_sigfpe(); break; 445 446 default: tty->print_cr("ERROR: %d: unexpected test_num value.", how); 447 } 448 ShouldNotReachHere(); 449 } 450 #endif // !PRODUCT 451 452 // ------ helper functions for debugging go here ------------ 453 454 // All debug entries should be wrapped with a stack allocated 455 // Command object. It makes sure a resource mark is set and 456 // flushes the logfile to prevent file sharing problems. 457 458 class Command : public StackObj { 459 private: 460 ResourceMark rm; 461 ResetNoHandleMark rnhm; 462 HandleMark hm; 463 bool debug_save; 464 public: 465 static int level; 466 Command(const char* str) { 467 debug_save = Debugging; 468 Debugging = true; 469 if (level++ > 0) return; 470 tty->cr(); 471 tty->print_cr("\"Executing %s\"", str); 472 } 473 474 ~Command() { 475 tty->flush(); 476 Debugging = debug_save; 477 level--; 478 } 479 }; 480 481 int Command::level = 0; 482 483 #ifndef PRODUCT 484 485 extern "C" void blob(CodeBlob* cb) { 486 Command c("blob"); 487 cb->print(); 488 } 489 490 491 extern "C" void dump_vtable(address p) { 492 Command c("dump_vtable"); 493 Klass* k = (Klass*)p; 494 k->vtable().print(); 495 } 496 497 498 extern "C" void nm(intptr_t p) { 499 // Actually we look through all CodeBlobs (the nm name has been kept for backwards compatability) 500 Command c("nm"); 501 CodeBlob* cb = CodeCache::find_blob((address)p); 502 if (cb == NULL) { 503 tty->print_cr("NULL"); 504 } else { 505 cb->print(); 506 } 507 } 508 509 510 extern "C" void disnm(intptr_t p) { 511 Command c("disnm"); 512 CodeBlob* cb = CodeCache::find_blob((address) p); 513 if (cb != NULL) { 514 nmethod* nm = cb->as_nmethod_or_null(); 515 if (nm != NULL) { 516 nm->print(); 517 } else { 518 cb->print(); 519 } 520 Disassembler::decode(cb); 521 } 522 } 523 524 525 extern "C" void printnm(intptr_t p) { 526 char buffer[256]; 527 sprintf(buffer, "printnm: " INTPTR_FORMAT, p); 528 Command c(buffer); 529 CodeBlob* cb = CodeCache::find_blob((address) p); 530 if (cb->is_nmethod()) { 531 nmethod* nm = (nmethod*)cb; 532 nm->print_nmethod(true); 533 } 534 } 535 536 537 extern "C" void universe() { 538 Command c("universe"); 539 Universe::print_on(tty); 540 } 541 542 543 extern "C" void verify() { 544 // try to run a verify on the entire system 545 // note: this may not be safe if we're not at a safepoint; for debugging, 546 // this manipulates the safepoint settings to avoid assertion failures 547 Command c("universe verify"); 548 bool safe = SafepointSynchronize::is_at_safepoint(); 549 if (!safe) { 550 tty->print_cr("warning: not at safepoint -- verify may fail"); 551 SafepointSynchronize::set_is_at_safepoint(); 552 } 553 // Ensure Eden top is correct before verification 554 Universe::heap()->prepare_for_verify(); 555 Universe::verify(); 556 if (!safe) SafepointSynchronize::set_is_not_at_safepoint(); 557 } 558 559 560 extern "C" void pp(void* p) { 561 Command c("pp"); 562 FlagSetting fl(PrintVMMessages, true); 563 FlagSetting f2(DisplayVMOutput, true); 564 if (Universe::heap()->is_in(p)) { 565 oop obj = oop(p); 566 obj->print(); 567 } else { 568 tty->print(PTR_FORMAT, p2i(p)); 569 } 570 } 571 572 573 // pv: print vm-printable object 574 extern "C" void pa(intptr_t p) { ((AllocatedObj*) p)->print(); } 575 extern "C" void findpc(intptr_t x); 576 577 #endif // !PRODUCT 578 579 extern "C" void ps() { // print stack 580 if (Thread::current_or_null() == NULL) return; 581 Command c("ps"); 582 583 584 // Prints the stack of the current Java thread 585 JavaThread* p = JavaThread::active(); 586 tty->print(" for thread: "); 587 p->print(); 588 tty->cr(); 589 590 if (p->has_last_Java_frame()) { 591 // If the last_Java_fp is set we are in C land and 592 // can call the standard stack_trace function. 593 #ifdef PRODUCT 594 p->print_stack(); 595 } else { 596 tty->print_cr("Cannot find the last Java frame, printing stack disabled."); 597 #else // !PRODUCT 598 p->trace_stack(); 599 } else { 600 frame f = os::current_frame(); 601 RegisterMap reg_map(p); 602 f = f.sender(®_map); 603 tty->print("(guessing starting frame id=" PTR_FORMAT " based on current fp)\n", p2i(f.id())); 604 p->trace_stack_from(vframe::new_vframe(&f, ®_map, p)); 605 pd_ps(f); 606 #endif // PRODUCT 607 } 608 609 } 610 611 extern "C" void pfl() { 612 // print frame layout 613 Command c("pfl"); 614 JavaThread* p = JavaThread::active(); 615 tty->print(" for thread: "); 616 p->print(); 617 tty->cr(); 618 if (p->has_last_Java_frame()) { 619 p->print_frame_layout(); 620 } 621 } 622 623 #ifndef PRODUCT 624 625 extern "C" void psf() { // print stack frames 626 { 627 Command c("psf"); 628 JavaThread* p = JavaThread::active(); 629 tty->print(" for thread: "); 630 p->print(); 631 tty->cr(); 632 if (p->has_last_Java_frame()) { 633 p->trace_frames(); 634 } 635 } 636 } 637 638 639 extern "C" void threads() { 640 Command c("threads"); 641 Threads::print(false, true); 642 } 643 644 645 extern "C" void psd() { 646 Command c("psd"); 647 SystemDictionary::print(); 648 } 649 650 651 extern "C" void safepoints() { 652 Command c("safepoints"); 653 SafepointSynchronize::print_state(); 654 } 655 656 #endif // !PRODUCT 657 658 extern "C" void pss() { // print all stacks 659 if (Thread::current_or_null() == NULL) return; 660 Command c("pss"); 661 Threads::print(true, PRODUCT_ONLY(false) NOT_PRODUCT(true)); 662 } 663 664 #ifndef PRODUCT 665 666 extern "C" void debug() { // to set things up for compiler debugging 667 Command c("debug"); 668 WizardMode = true; 669 PrintVMMessages = PrintCompilation = true; 670 PrintInlining = PrintAssembly = true; 671 tty->flush(); 672 } 673 674 675 extern "C" void ndebug() { // undo debug() 676 Command c("ndebug"); 677 PrintCompilation = false; 678 PrintInlining = PrintAssembly = false; 679 tty->flush(); 680 } 681 682 683 extern "C" void flush() { 684 Command c("flush"); 685 tty->flush(); 686 } 687 688 extern "C" void events() { 689 Command c("events"); 690 Events::print(); 691 } 692 693 extern "C" Method* findm(intptr_t pc) { 694 Command c("findm"); 695 nmethod* nm = CodeCache::find_nmethod((address)pc); 696 return (nm == NULL) ? (Method*)NULL : nm->method(); 697 } 698 699 700 extern "C" nmethod* findnm(intptr_t addr) { 701 Command c("findnm"); 702 return CodeCache::find_nmethod((address)addr); 703 } 704 705 // Another interface that isn't ambiguous in dbx. 706 // Can we someday rename the other find to hsfind? 707 extern "C" void hsfind(intptr_t x) { 708 Command c("hsfind"); 709 os::print_location(tty, x, false); 710 } 711 712 713 extern "C" void find(intptr_t x) { 714 Command c("find"); 715 os::print_location(tty, x, false); 716 } 717 718 719 extern "C" void findpc(intptr_t x) { 720 Command c("findpc"); 721 os::print_location(tty, x, true); 722 } 723 724 725 // Need method pointer to find bcp, when not in permgen. 726 extern "C" void findbcp(intptr_t method, intptr_t bcp) { 727 Command c("findbcp"); 728 Method* mh = (Method*)method; 729 if (!mh->is_native()) { 730 tty->print_cr("bci_from(%p) = %d; print_codes():", 731 mh, mh->bci_from(address(bcp))); 732 mh->print_codes_on(tty); 733 } 734 } 735 736 // int versions of all methods to avoid having to type type casts in the debugger 737 738 void pp(intptr_t p) { pp((void*)p); } 739 void pp(oop p) { pp((void*)p); } 740 741 void help() { 742 Command c("help"); 743 tty->print_cr("basic"); 744 tty->print_cr(" pp(void* p) - try to make sense of p"); 745 tty->print_cr(" pv(intptr_t p)- ((PrintableResourceObj*) p)->print()"); 746 tty->print_cr(" ps() - print current thread stack"); 747 tty->print_cr(" pss() - print all thread stacks"); 748 tty->print_cr(" pm(int pc) - print Method* given compiled PC"); 749 tty->print_cr(" findm(intptr_t pc) - finds Method*"); 750 tty->print_cr(" find(intptr_t x) - finds & prints nmethod/stub/bytecode/oop based on pointer into it"); 751 tty->print_cr(" pns(void* sp, void* fp, void* pc) - print native (i.e. mixed) stack trace. E.g."); 752 tty->print_cr(" pns($sp, $rbp, $pc) on Linux/amd64 and Solaris/amd64 or"); 753 tty->print_cr(" pns($sp, $ebp, $pc) on Linux/x86 or"); 754 tty->print_cr(" pns($sp, 0, $pc) on Linux/ppc64 or"); 755 tty->print_cr(" pns($sp + 0x7ff, 0, $pc) on Solaris/SPARC"); 756 tty->print_cr(" - in gdb do 'set overload-resolution off' before calling pns()"); 757 tty->print_cr(" - in dbx do 'frame 1' before calling pns()"); 758 759 tty->print_cr("misc."); 760 tty->print_cr(" flush() - flushes the log file"); 761 tty->print_cr(" events() - dump events from ring buffers"); 762 763 764 tty->print_cr("compiler debugging"); 765 tty->print_cr(" debug() - to set things up for compiler debugging"); 766 tty->print_cr(" ndebug() - undo debug"); 767 } 768 769 #endif // !PRODUCT 770 771 void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) { 772 773 // see if it's a valid frame 774 if (fr.pc()) { 775 st->print_cr("Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)"); 776 777 int count = 0; 778 while (count++ < StackPrintLimit) { 779 fr.print_on_error(st, buf, buf_size); 780 st->cr(); 781 // Compiled code may use EBP register on x86 so it looks like 782 // non-walkable C frame. Use frame.sender() for java frames. 783 if (t && t->is_Java_thread()) { 784 // Catch very first native frame by using stack address. 785 // For JavaThread stack_base and stack_size should be set. 786 if (!t->on_local_stack((address)(fr.real_fp() + 1))) { 787 break; 788 } 789 if (fr.is_java_frame() || fr.is_native_frame() || fr.is_runtime_frame()) { 790 RegisterMap map((JavaThread*)t, false); // No update 791 fr = fr.sender(&map); 792 } else { 793 fr = os::get_sender_for_C_frame(&fr); 794 } 795 } else { 796 // is_first_C_frame() does only simple checks for frame pointer, 797 // it will pass if java compiled code has a pointer in EBP. 798 if (os::is_first_C_frame(&fr)) break; 799 fr = os::get_sender_for_C_frame(&fr); 800 } 801 } 802 803 if (count > StackPrintLimit) { 804 st->print_cr("...<more frames>..."); 805 } 806 807 st->cr(); 808 } 809 } 810 811 #ifndef PRODUCT 812 813 extern "C" void pns(void* sp, void* fp, void* pc) { // print native stack 814 Command c("pns"); 815 static char buf[O_BUFLEN]; 816 Thread* t = Thread::current_or_null(); 817 // Call generic frame constructor (certain arguments may be ignored) 818 frame fr(sp, fp, pc); 819 print_native_stack(tty, fr, t, buf, sizeof(buf)); 820 } 821 822 #endif // !PRODUCT 823 824 ////////////////////////////////////////////////////////////////////////////// 825 // Test multiple STATIC_ASSERT forms in various scopes. 826 827 #ifndef PRODUCT 828 829 // namespace scope 830 STATIC_ASSERT(true); 831 STATIC_ASSERT(true); 832 STATIC_ASSERT(1 == 1); 833 STATIC_ASSERT(0 == 0); 834 835 void test_multiple_static_assert_forms_in_function_scope() { 836 STATIC_ASSERT(true); 837 STATIC_ASSERT(true); 838 STATIC_ASSERT(0 == 0); 839 STATIC_ASSERT(1 == 1); 840 } 841 842 // class scope 843 struct TestMultipleStaticAssertFormsInClassScope { 844 STATIC_ASSERT(true); 845 STATIC_ASSERT(true); 846 STATIC_ASSERT(0 == 0); 847 STATIC_ASSERT(1 == 1); 848 }; 849 850 #endif // !PRODUCT