< prev index next >

src/share/vm/utilities/debug.cpp

Print this page
rev 13107 : imported patch jvm_h
rev 13108 : imported patch move_format_buffer
rev 13109 : imported patch move_pns


  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/privilegedStack.hpp"
  40 #include "runtime/arguments.hpp"
  41 #include "runtime/atomic.hpp"
  42 #include "runtime/frame.hpp"
  43 #include "runtime/java.hpp"
  44 #include "runtime/os.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 #include "runtime/stubCodeGenerator.hpp"
  47 #include "runtime/stubRoutines.hpp"
  48 #include "runtime/thread.inline.hpp"
  49 #include "runtime/vframe.hpp"
  50 #include "runtime/vm_version.hpp"
  51 #include "services/heapDumper.hpp"
  52 #include "utilities/defaultStream.hpp"
  53 #include "utilities/events.hpp"

  54 #include "utilities/macros.hpp"
  55 #include "utilities/vmError.hpp"
  56 
  57 #include <stdio.h>
  58 
  59 #ifndef ASSERT
  60 #  ifdef _DEBUG
  61    // NOTE: don't turn the lines below into a comment -- if you're getting
  62    // a compile error here, change the settings to define ASSERT
  63    ASSERT should be defined when _DEBUG is defined.  It is not intended to be used for debugging
  64    functions that do not slow down the system too much and thus can be left in optimized code.
  65    On the other hand, the code should not be included in a production version.
  66 #  endif // _DEBUG
  67 #endif // ASSERT
  68 
  69 
  70 #ifdef _DEBUG
  71 #  ifndef ASSERT
  72      configuration error: ASSERT must be defined in debug version
  73 #  endif // ASSERT
  74 #endif // _DEBUG
  75 
  76 
  77 #ifdef PRODUCT
  78 #  if -defined _DEBUG || -defined ASSERT
  79      configuration error: ASSERT et al. must not be defined in PRODUCT version
  80 #  endif
  81 #endif // PRODUCT
  82 
  83 FormatBufferResource::FormatBufferResource(const char * format, ...)
  84   : FormatBufferBase((char*)resource_allocate_bytes(FormatBufferBase::BufferSize)) {
  85   va_list argp;
  86   va_start(argp, format);
  87   jio_vsnprintf(_buf, FormatBufferBase::BufferSize, format, argp);
  88   va_end(argp);
  89 }
  90 
  91 ATTRIBUTE_PRINTF(1, 2)
  92 void warning(const char* format, ...) {
  93   if (PrintWarnings) {
  94     FILE* const err = defaultStream::error_stream();
  95     jio_fprintf(err, "%s warning: ", VM_Version::vm_name());
  96     va_list ap;
  97     va_start(ap, format);
  98     vfprintf(err, format, ap);
  99     va_end(ap);
 100     fputc('\n', err);
 101   }
 102   if (BreakAtWarning) BREAKPOINT;
 103 }
 104 
 105 #ifndef PRODUCT
 106 
 107 #define is_token_break(ch) (isspace(ch) || (ch) == ',')
 108 
 109 static const char* last_file_name = NULL;
 110 static int         last_line_no   = -1;


 572 // pv: print vm-printable object
 573 extern "C" void pa(intptr_t p)   { ((AllocatedObj*) p)->print(); }
 574 extern "C" void findpc(intptr_t x);
 575 
 576 #endif // !PRODUCT
 577 
 578 extern "C" void ps() { // print stack
 579   if (Thread::current_or_null() == NULL) return;
 580   Command c("ps");
 581 
 582 
 583   // Prints the stack of the current Java thread
 584   JavaThread* p = JavaThread::active();
 585   tty->print(" for thread: ");
 586   p->print();
 587   tty->cr();
 588 
 589   if (p->has_last_Java_frame()) {
 590     // If the last_Java_fp is set we are in C land and
 591     // can call the standard stack_trace function.
 592 #ifdef PRODUCT
 593     p->print_stack();
 594   } else {

 595     tty->print_cr("Cannot find the last Java frame, printing stack disabled.");
 596 #else // !PRODUCT
 597     p->trace_stack();
 598   } else {
 599     frame f = os::current_frame();
 600     RegisterMap reg_map(p);
 601     f = f.sender(&reg_map);
 602     tty->print("(guessing starting frame id=" PTR_FORMAT " based on current fp)\n", p2i(f.id()));
 603     p->trace_stack_from(vframe::new_vframe(&f, &reg_map, p));
 604   pd_ps(f);
 605 #endif // PRODUCT
 606   }
 607 
 608 }
 609 
 610 extern "C" void pfl() {
 611   // print frame layout
 612   Command c("pfl");
 613   JavaThread* p = JavaThread::active();
 614   tty->print(" for thread: ");
 615   p->print();
 616   tty->cr();
 617   if (p->has_last_Java_frame()) {
 618     p->print_frame_layout();


 748   tty->print_cr("  findm(intptr_t pc) - finds Method*");
 749   tty->print_cr("  find(intptr_t x)   - finds & prints nmethod/stub/bytecode/oop based on pointer into it");
 750   tty->print_cr("  pns(void* sp, void* fp, void* pc)  - print native (i.e. mixed) stack trace. E.g.");
 751   tty->print_cr("                   pns($sp, $rbp, $pc) on Linux/amd64 and Solaris/amd64 or");
 752   tty->print_cr("                   pns($sp, $ebp, $pc) on Linux/x86 or");
 753   tty->print_cr("                   pns($sp, 0, $pc)    on Linux/ppc64 or");
 754   tty->print_cr("                   pns($sp + 0x7ff, 0, $pc) on Solaris/SPARC");
 755   tty->print_cr("                 - in gdb do 'set overload-resolution off' before calling pns()");
 756   tty->print_cr("                 - in dbx do 'frame 1' before calling pns()");
 757 
 758   tty->print_cr("misc.");
 759   tty->print_cr("  flush()       - flushes the log file");
 760   tty->print_cr("  events()      - dump events from ring buffers");
 761 
 762 
 763   tty->print_cr("compiler debugging");
 764   tty->print_cr("  debug()       - to set things up for compiler debugging");
 765   tty->print_cr("  ndebug()      - undo debug");
 766 }
 767 
 768 #endif // !PRODUCT
 769 
 770 void print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) {
 771 
 772   // see if it's a valid frame
 773   if (fr.pc()) {
 774     st->print_cr("Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)");
 775 
 776     int count = 0;
 777     while (count++ < StackPrintLimit) {
 778       fr.print_on_error(st, buf, buf_size);
 779       st->cr();
 780       // Compiled code may use EBP register on x86 so it looks like
 781       // non-walkable C frame. Use frame.sender() for java frames.
 782       if (t && t->is_Java_thread()) {
 783         // Catch very first native frame by using stack address.
 784         // For JavaThread stack_base and stack_size should be set.
 785         if (!t->on_local_stack((address)(fr.real_fp() + 1))) {
 786           break;
 787         }
 788         if (fr.is_java_frame() || fr.is_native_frame() || fr.is_runtime_frame()) {
 789           RegisterMap map((JavaThread*)t, false); // No update
 790           fr = fr.sender(&map);
 791         } else {
 792           fr = os::get_sender_for_C_frame(&fr);
 793         }
 794       } else {
 795         // is_first_C_frame() does only simple checks for frame pointer,
 796         // it will pass if java compiled code has a pointer in EBP.
 797         if (os::is_first_C_frame(&fr)) break;
 798         fr = os::get_sender_for_C_frame(&fr);
 799       }
 800     }
 801 
 802     if (count > StackPrintLimit) {
 803       st->print_cr("...<more frames>...");
 804     }
 805 
 806     st->cr();
 807   }
 808 }
 809 
 810 #ifndef PRODUCT
 811 
 812 extern "C" void pns(void* sp, void* fp, void* pc) { // print native stack
 813   Command c("pns");
 814   static char buf[O_BUFLEN];
 815   Thread* t = Thread::current_or_null();
 816   // Call generic frame constructor (certain arguments may be ignored)
 817   frame fr(sp, fp, pc);
 818   print_native_stack(tty, fr, t, buf, sizeof(buf));
 819 }
 820 
 821 #endif // !PRODUCT
 822 
 823 //////////////////////////////////////////////////////////////////////////////
 824 // Test multiple STATIC_ASSERT forms in various scopes.
 825 
 826 #ifndef PRODUCT
 827 
 828 // namespace scope
 829 STATIC_ASSERT(true);
 830 STATIC_ASSERT(true);
 831 STATIC_ASSERT(1 == 1);
 832 STATIC_ASSERT(0 == 0);
 833 
 834 void test_multiple_static_assert_forms_in_function_scope() {
 835   STATIC_ASSERT(true);
 836   STATIC_ASSERT(true);
 837   STATIC_ASSERT(0 == 0);
 838   STATIC_ASSERT(1 == 1);


  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/formatBuffer.hpp"
  56 #include "utilities/macros.hpp"
  57 #include "utilities/vmError.hpp"
  58 
  59 #include <stdio.h>
  60 
  61 #ifndef ASSERT
  62 #  ifdef _DEBUG
  63    // NOTE: don't turn the lines below into a comment -- if you're getting
  64    // a compile error here, change the settings to define ASSERT
  65    ASSERT should be defined when _DEBUG is defined.  It is not intended to be used for debugging
  66    functions that do not slow down the system too much and thus can be left in optimized code.
  67    On the other hand, the code should not be included in a production version.
  68 #  endif // _DEBUG
  69 #endif // ASSERT
  70 
  71 
  72 #ifdef _DEBUG
  73 #  ifndef ASSERT
  74      configuration error: ASSERT must be defined in debug version
  75 #  endif // ASSERT
  76 #endif // _DEBUG
  77 
  78 
  79 #ifdef PRODUCT
  80 #  if -defined _DEBUG || -defined ASSERT
  81      configuration error: ASSERT et al. must not be defined in PRODUCT version
  82 #  endif
  83 #endif // PRODUCT
  84 








  85 ATTRIBUTE_PRINTF(1, 2)
  86 void warning(const char* format, ...) {
  87   if (PrintWarnings) {
  88     FILE* const err = defaultStream::error_stream();
  89     jio_fprintf(err, "%s warning: ", VM_Version::vm_name());
  90     va_list ap;
  91     va_start(ap, format);
  92     vfprintf(err, format, ap);
  93     va_end(ap);
  94     fputc('\n', err);
  95   }
  96   if (BreakAtWarning) BREAKPOINT;
  97 }
  98 
  99 #ifndef PRODUCT
 100 
 101 #define is_token_break(ch) (isspace(ch) || (ch) == ',')
 102 
 103 static const char* last_file_name = NULL;
 104 static int         last_line_no   = -1;


 566 // pv: print vm-printable object
 567 extern "C" void pa(intptr_t p)   { ((AllocatedObj*) p)->print(); }
 568 extern "C" void findpc(intptr_t x);
 569 
 570 #endif // !PRODUCT
 571 
 572 extern "C" void ps() { // print stack
 573   if (Thread::current_or_null() == NULL) return;
 574   Command c("ps");
 575 
 576 
 577   // Prints the stack of the current Java thread
 578   JavaThread* p = JavaThread::active();
 579   tty->print(" for thread: ");
 580   p->print();
 581   tty->cr();
 582 
 583   if (p->has_last_Java_frame()) {
 584     // If the last_Java_fp is set we are in C land and
 585     // can call the standard stack_trace function.

 586     p->print_stack();
 587   } else {
 588 #ifdef PRODUCT
 589     tty->print_cr("Cannot find the last Java frame, printing stack disabled.");
 590 #else // !PRODUCT


 591     frame f = os::current_frame();
 592     RegisterMap reg_map(p);
 593     f = f.sender(&reg_map);
 594     tty->print("(guessing starting frame id=" PTR_FORMAT " based on current fp)\n", p2i(f.id()));
 595     p->trace_stack_from(vframe::new_vframe(&f, &reg_map, p));
 596     pd_ps(f);
 597 #endif // PRODUCT
 598   }
 599 
 600 }
 601 
 602 extern "C" void pfl() {
 603   // print frame layout
 604   Command c("pfl");
 605   JavaThread* p = JavaThread::active();
 606   tty->print(" for thread: ");
 607   p->print();
 608   tty->cr();
 609   if (p->has_last_Java_frame()) {
 610     p->print_frame_layout();


 740   tty->print_cr("  findm(intptr_t pc) - finds Method*");
 741   tty->print_cr("  find(intptr_t x)   - finds & prints nmethod/stub/bytecode/oop based on pointer into it");
 742   tty->print_cr("  pns(void* sp, void* fp, void* pc)  - print native (i.e. mixed) stack trace. E.g.");
 743   tty->print_cr("                   pns($sp, $rbp, $pc) on Linux/amd64 and Solaris/amd64 or");
 744   tty->print_cr("                   pns($sp, $ebp, $pc) on Linux/x86 or");
 745   tty->print_cr("                   pns($sp, 0, $pc)    on Linux/ppc64 or");
 746   tty->print_cr("                   pns($sp + 0x7ff, 0, $pc) on Solaris/SPARC");
 747   tty->print_cr("                 - in gdb do 'set overload-resolution off' before calling pns()");
 748   tty->print_cr("                 - in dbx do 'frame 1' before calling pns()");
 749 
 750   tty->print_cr("misc.");
 751   tty->print_cr("  flush()       - flushes the log file");
 752   tty->print_cr("  events()      - dump events from ring buffers");
 753 
 754 
 755   tty->print_cr("compiler debugging");
 756   tty->print_cr("  debug()       - to set things up for compiler debugging");
 757   tty->print_cr("  ndebug()      - undo debug");
 758 }
 759 












































 760 extern "C" void pns(void* sp, void* fp, void* pc) { // print native stack
 761   Command c("pns");
 762   static char buf[O_BUFLEN];
 763   Thread* t = Thread::current_or_null();
 764   // Call generic frame constructor (certain arguments may be ignored)
 765   frame fr(sp, fp, pc);
 766   VMError::print_native_stack(tty, fr, t, buf, sizeof(buf));
 767 }
 768 
 769 #endif // !PRODUCT
 770 
 771 //////////////////////////////////////////////////////////////////////////////
 772 // Test multiple STATIC_ASSERT forms in various scopes.
 773 
 774 #ifndef PRODUCT
 775 
 776 // namespace scope
 777 STATIC_ASSERT(true);
 778 STATIC_ASSERT(true);
 779 STATIC_ASSERT(1 == 1);
 780 STATIC_ASSERT(0 == 0);
 781 
 782 void test_multiple_static_assert_forms_in_function_scope() {
 783   STATIC_ASSERT(true);
 784   STATIC_ASSERT(true);
 785   STATIC_ASSERT(0 == 0);
 786   STATIC_ASSERT(1 == 1);
< prev index next >