debug.cpp revision 113
0N/A/*
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A# include "incls/_precompiled.incl"
0N/A# include "incls/_debug.cpp.incl"
0N/A
0N/A#ifndef ASSERT
0N/A# ifdef _DEBUG
0N/A // NOTE: don't turn the lines below into a comment -- if you're getting
0N/A // a compile error here, change the settings to define ASSERT
0N/A ASSERT should be defined when _DEBUG is defined. It is not intended to be used for debugging
0N/A functions that do not slow down the system too much and thus can be left in optimized code.
0N/A On the other hand, the code should not be included in a production version.
0N/A# endif // _DEBUG
0N/A#endif // ASSERT
0N/A
0N/A
0N/A#ifdef _DEBUG
0N/A# ifndef ASSERT
0N/A configuration error: ASSERT must be defined in debug version
0N/A# endif // ASSERT
0N/A#endif // _DEBUG
0N/A
0N/A
0N/A#ifdef PRODUCT
0N/A# if -defined _DEBUG || -defined ASSERT
0N/A configuration error: ASSERT et al. must not be defined in PRODUCT version
0N/A# endif
0N/A#endif // PRODUCT
0N/A
0N/A
0N/Avoid warning(const char* format, ...) {
0N/A // In case error happens before init or during shutdown
0N/A if (tty == NULL) ostream_init();
0N/A
0N/A tty->print("%s warning: ", VM_Version::vm_name());
0N/A va_list ap;
0N/A va_start(ap, format);
0N/A tty->vprint_cr(format, ap);
0N/A va_end(ap);
0N/A if (BreakAtWarning) BREAKPOINT;
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A
0N/A#define is_token_break(ch) (isspace(ch) || (ch) == ',')
0N/A
0N/Astatic const char* last_file_name = NULL;
0N/Astatic int last_line_no = -1;
0N/A
0N/A// assert/guarantee/... may happen very early during VM initialization.
0N/A// Don't rely on anything that is initialized by Threads::create_vm(). For
0N/A// example, don't use tty.
0N/Abool assert_is_suppressed(const char* file_name, int line_no) {
0N/A // The following 1-element cache requires that passed-in
0N/A // file names are always only constant literals.
0N/A if (file_name == last_file_name && line_no == last_line_no) return true;
0N/A
0N/A int file_name_len = (int)strlen(file_name);
0N/A char separator = os::file_separator()[0];
0N/A const char* base_name = strrchr(file_name, separator);
0N/A if (base_name == NULL)
0N/A base_name = file_name;
0N/A
0N/A // scan the SuppressErrorAt option
0N/A const char* cp = SuppressErrorAt;
0N/A for (;;) {
0N/A const char* sfile;
0N/A int sfile_len;
0N/A int sline;
0N/A bool noisy;
0N/A while ((*cp) != '\0' && is_token_break(*cp)) cp++;
0N/A if ((*cp) == '\0') break;
0N/A sfile = cp;
0N/A while ((*cp) != '\0' && !is_token_break(*cp) && (*cp) != ':') cp++;
0N/A sfile_len = cp - sfile;
0N/A if ((*cp) == ':') cp++;
0N/A sline = 0;
0N/A while ((*cp) != '\0' && isdigit(*cp)) {
0N/A sline *= 10;
0N/A sline += (*cp) - '0';
0N/A cp++;
0N/A }
0N/A // "file:line!" means the assert suppression is not silent
0N/A noisy = ((*cp) == '!');
0N/A while ((*cp) != '\0' && !is_token_break(*cp)) cp++;
0N/A // match the line
0N/A if (sline != 0) {
0N/A if (sline != line_no) continue;
0N/A }
0N/A // match the file
0N/A if (sfile_len > 0) {
0N/A const char* look = file_name;
0N/A const char* look_max = file_name + file_name_len - sfile_len;
0N/A const char* foundp;
0N/A bool match = false;
0N/A while (!match
0N/A && (foundp = strchr(look, sfile[0])) != NULL
0N/A && foundp <= look_max) {
0N/A match = true;
0N/A for (int i = 1; i < sfile_len; i++) {
0N/A if (sfile[i] != foundp[i]) {
0N/A match = false;
0N/A break;
0N/A }
0N/A }
0N/A look = foundp + 1;
0N/A }
0N/A if (!match) continue;
0N/A }
0N/A // got a match!
0N/A if (noisy) {
0N/A fdStream out(defaultStream::output_fd());
0N/A out.print_raw("[error suppressed at ");
0N/A out.print_raw(base_name);
0N/A char buf[16];
0N/A jio_snprintf(buf, sizeof(buf), ":%d]", line_no);
0N/A out.print_raw_cr(buf);
0N/A } else {
0N/A // update 1-element cache for fast silent matches
0N/A last_file_name = file_name;
0N/A last_line_no = line_no;
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A if (!is_error_reported()) {
0N/A // print a friendly hint:
0N/A fdStream out(defaultStream::output_fd());
0N/A out.print_raw_cr("# To suppress the following error report, specify this argument");
0N/A out.print_raw ("# after -XX: or in .hotspotrc: SuppressErrorAt=");
0N/A out.print_raw (base_name);
0N/A char buf[16];
0N/A jio_snprintf(buf, sizeof(buf), ":%d", line_no);
0N/A out.print_raw_cr(buf);
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A#undef is_token_break
0N/A
0N/A#else
0N/A
0N/A// Place-holder for non-existent suppression check:
0N/A#define assert_is_suppressed(file_name, line_no) (false)
0N/A
0N/A#endif //PRODUCT
0N/A
0N/Avoid report_assertion_failure(const char* file_name, int line_no, const char* message) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A VMError err(ThreadLocalStorage::get_thread_slow(), message, file_name, line_no);
0N/A err.report_and_die();
0N/A}
0N/A
0N/Avoid report_fatal(const char* file_name, int line_no, const char* message) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A VMError err(ThreadLocalStorage::get_thread_slow(), message, file_name, line_no);
0N/A err.report_and_die();
0N/A}
0N/A
0N/Avoid report_fatal_vararg(const char* file_name, int line_no, const char* format, ...) {
0N/A char buffer[256];
0N/A va_list ap;
0N/A va_start(ap, format);
0N/A jio_vsnprintf(buffer, sizeof(buffer), format, ap);
0N/A va_end(ap);
0N/A report_fatal(file_name, line_no, buffer);
0N/A}
0N/A
0N/A
0N/A// Used by report_vm_out_of_memory to detect recursion.
0N/Astatic jint _exiting_out_of_mem = 0;
0N/A
0N/A// Just passing the flow to VMError to handle error
0N/Avoid report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A
0N/A // We try to gather additional information for the first out of memory
0N/A // error only; gathering additional data might cause an allocation and a
0N/A // recursive out_of_memory condition.
0N/A
0N/A const jint exiting = 1;
0N/A // If we succeed in changing the value, we're the first one in.
0N/A bool first_time_here = Atomic::xchg(exiting, &_exiting_out_of_mem) != exiting;
0N/A
0N/A if (first_time_here) {
0N/A Thread* thread = ThreadLocalStorage::get_thread_slow();
0N/A VMError(thread, size, message, file_name, line_no).report_and_die();
0N/A }
0N/A vm_abort();
0N/A}
0N/A
0N/Avoid report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...) {
0N/A char buffer[256];
0N/A va_list ap;
0N/A va_start(ap, format);
0N/A jio_vsnprintf(buffer, sizeof(buffer), format, ap);
0N/A va_end(ap);
0N/A report_vm_out_of_memory(file_name, line_no, size, buffer);
0N/A}
0N/A
0N/Avoid report_should_not_call(const char* file_name, int line_no) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A VMError err(ThreadLocalStorage::get_thread_slow(), "ShouldNotCall()", file_name, line_no);
0N/A err.report_and_die();
0N/A}
0N/A
0N/A
0N/Avoid report_should_not_reach_here(const char* file_name, int line_no) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A VMError err(ThreadLocalStorage::get_thread_slow(), "ShouldNotReachHere()", file_name, line_no);
0N/A err.report_and_die();
0N/A}
0N/A
0N/A
0N/Avoid report_unimplemented(const char* file_name, int line_no) {
0N/A if (Debugging || assert_is_suppressed(file_name, line_no)) return;
0N/A VMError err(ThreadLocalStorage::get_thread_slow(), "Unimplemented()", file_name, line_no);
0N/A err.report_and_die();
0N/A}
0N/A
0N/A
0N/Avoid report_untested(const char* file_name, int line_no, const char* msg) {
0N/A#ifndef PRODUCT
0N/A warning("Untested: %s in %s: %d\n", msg, file_name, line_no);
0N/A#endif // PRODUCT
0N/A}
0N/A
0N/Avoid report_java_out_of_memory(const char* message) {
0N/A static jint out_of_memory_reported = 0;
0N/A
0N/A // A number of threads may attempt to report OutOfMemoryError at around the
0N/A // same time. To avoid dumping the heap or executing the data collection
0N/A // commands multiple times we just do it once when the first threads reports
0N/A // the error.
0N/A if (Atomic::cmpxchg(1, &out_of_memory_reported, 0) == 0) {
0N/A // create heap dump before OnOutOfMemoryError commands are executed
0N/A if (HeapDumpOnOutOfMemoryError) {
0N/A tty->print_cr("java.lang.OutOfMemoryError: %s", message);
0N/A HeapDumper::dump_heap();
0N/A }
0N/A
0N/A if (OnOutOfMemoryError && OnOutOfMemoryError[0]) {
0N/A VMError err(message);
0N/A err.report_java_out_of_memory();
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Aextern "C" void ps();
0N/A
0N/Astatic bool error_reported = false;
0N/A
0N/A// call this when the VM is dying--it might loosen some asserts
0N/Avoid set_error_reported() {
0N/A error_reported = true;
0N/A}
0N/A
0N/Abool is_error_reported() {
0N/A return error_reported;
0N/A}
0N/A
0N/A// ------ helper functions for debugging go here ------------
0N/A
0N/A#ifndef PRODUCT
0N/A// All debug entries should be wrapped with a stack allocated
0N/A// Command object. It makes sure a resource mark is set and
0N/A// flushes the logfile to prevent file sharing problems.
0N/A
0N/Aclass Command : public StackObj {
0N/A private:
0N/A ResourceMark rm;
0N/A ResetNoHandleMark rnhm;
0N/A HandleMark hm;
0N/A bool debug_save;
0N/A public:
0N/A static int level;
0N/A Command(const char* str) {
0N/A debug_save = Debugging;
0N/A Debugging = true;
0N/A if (level++ > 0) return;
0N/A tty->cr();
0N/A tty->print_cr("\"Executing %s\"", str);
0N/A }
0N/A
0N/A ~Command() { tty->flush(); Debugging = debug_save; level--; }
0N/A};
0N/A
0N/Aint Command::level = 0;
0N/A
0N/Aextern "C" void blob(CodeBlob* cb) {
0N/A Command c("blob");
0N/A cb->print();
0N/A}
0N/A
0N/A
0N/Aextern "C" void dump_vtable(address p) {
0N/A Command c("dump_vtable");
0N/A klassOop k = (klassOop)p;
0N/A instanceKlass::cast(k)->vtable()->print();
0N/A}
0N/A
0N/A
0N/Aextern "C" void nm(intptr_t p) {
0N/A // Actually we look through all CodeBlobs (the nm name has been kept for backwards compatability)
0N/A Command c("nm");
0N/A CodeBlob* cb = CodeCache::find_blob((address)p);
0N/A if (cb == NULL) {
0N/A tty->print_cr("NULL");
0N/A } else {
0N/A cb->print();
0N/A }
0N/A}
0N/A
0N/A
0N/Aextern "C" void disnm(intptr_t p) {
0N/A Command c("disnm");
0N/A CodeBlob* cb = CodeCache::find_blob((address) p);
0N/A cb->print();
0N/A Disassembler::decode(cb);
0N/A}
0N/A
0N/A
0N/Aextern "C" void printnm(intptr_t p) {
0N/A char buffer[256];
0N/A sprintf(buffer, "printnm: " INTPTR_FORMAT, p);
0N/A Command c(buffer);
0N/A CodeBlob* cb = CodeCache::find_blob((address) p);
0N/A if (cb->is_nmethod()) {
0N/A nmethod* nm = (nmethod*)cb;
0N/A nm->print_nmethod(true);
0N/A }
0N/A}
0N/A
0N/A
0N/Aextern "C" void universe() {
0N/A Command c("universe");
0N/A Universe::print();
0N/A}
0N/A
0N/A
0N/Aextern "C" void verify() {
0N/A // try to run a verify on the entire system
0N/A // note: this may not be safe if we're not at a safepoint; for debugging,
0N/A // this manipulates the safepoint settings to avoid assertion failures
0N/A Command c("universe verify");
0N/A bool safe = SafepointSynchronize::is_at_safepoint();
0N/A if (!safe) {
0N/A tty->print_cr("warning: not at safepoint -- verify may fail");
0N/A SafepointSynchronize::set_is_at_safepoint();
0N/A }
0N/A // Ensure Eden top is correct before verification
0N/A Universe::heap()->prepare_for_verify();
0N/A Universe::verify(true);
0N/A if (!safe) SafepointSynchronize::set_is_not_at_safepoint();
0N/A}
0N/A
0N/A
0N/Aextern "C" void pp(void* p) {
0N/A Command c("pp");
0N/A FlagSetting fl(PrintVMMessages, true);
0N/A if (Universe::heap()->is_in(p)) {
0N/A oop obj = oop(p);
0N/A obj->print();
0N/A } else {
0N/A tty->print("%#p", p);
0N/A }
0N/A}
0N/A
0N/A
0N/A// pv: print vm-printable object
0N/Aextern "C" void pa(intptr_t p) { ((AllocatedObj*) p)->print(); }
0N/Aextern "C" void findpc(intptr_t x);
0N/A
0N/Aextern "C" void ps() { // print stack
0N/A Command c("ps");
0N/A
0N/A
0N/A // Prints the stack of the current Java thread
0N/A JavaThread* p = JavaThread::active();
0N/A tty->print(" for thread: ");
0N/A p->print();
0N/A tty->cr();
0N/A
0N/A if (p->has_last_Java_frame()) {
0N/A // If the last_Java_fp is set we are in C land and
0N/A // can call the standard stack_trace function.
0N/A p->trace_stack();
0N/A } else {
0N/A frame f = os::current_frame();
0N/A RegisterMap reg_map(p);
0N/A f = f.sender(&reg_map);
0N/A tty->print("(guessing starting frame id=%#p based on current fp)\n", f.id());
0N/A p->trace_stack_from(vframe::new_vframe(&f, &reg_map, p));
0N/A pd_ps(f);
0N/A }
0N/A
0N/A}
0N/A
0N/A
0N/Aextern "C" void psf() { // print stack frames
0N/A {
0N/A Command c("psf");
0N/A JavaThread* p = JavaThread::active();
0N/A tty->print(" for thread: ");
0N/A p->print();
0N/A tty->cr();
0N/A if (p->has_last_Java_frame()) {
0N/A p->trace_frames();
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Aextern "C" void threads() {
0N/A Command c("threads");
0N/A Threads::print(false, true);
0N/A}
0N/A
0N/A
0N/Aextern "C" void psd() {
0N/A Command c("psd");
0N/A SystemDictionary::print();
0N/A}
0N/A
0N/A
0N/Aextern "C" void safepoints() {
0N/A Command c("safepoints");
0N/A SafepointSynchronize::print_state();
0N/A}
0N/A
0N/A
0N/Aextern "C" void pss() { // print all stacks
0N/A Command c("pss");
0N/A Threads::print(true, true);
0N/A}
0N/A
0N/A
0N/Aextern "C" void debug() { // to set things up for compiler debugging
0N/A Command c("debug");
0N/A WizardMode = true;
0N/A PrintVMMessages = PrintCompilation = true;
0N/A PrintInlining = PrintAssembly = true;
0N/A tty->flush();
0N/A}
0N/A
0N/A
0N/Aextern "C" void ndebug() { // undo debug()
0N/A Command c("ndebug");
0N/A PrintCompilation = false;
0N/A PrintInlining = PrintAssembly = false;
0N/A tty->flush();
0N/A}
0N/A
0N/A
0N/Aextern "C" void flush() {
0N/A Command c("flush");
0N/A tty->flush();
0N/A}
0N/A
0N/A
0N/Aextern "C" void events() {
0N/A Command c("events");
0N/A Events::print_last(tty, 50);
0N/A}
0N/A
0N/A
0N/Aextern "C" void nevents(int n) {
0N/A Command c("events");
0N/A Events::print_last(tty, n);
0N/A}
0N/A
0N/A
0N/A// Given a heap address that was valid before the most recent GC, if
0N/A// the oop that used to contain it is still live, prints the new
0N/A// location of the oop and the address. Useful for tracking down
0N/A// certain kinds of naked oop and oop map bugs.
0N/Aextern "C" void pnl(intptr_t old_heap_addr) {
0N/A // Print New Location of old heap address
0N/A Command c("pnl");
0N/A#ifndef VALIDATE_MARK_SWEEP
0N/A tty->print_cr("Requires build with VALIDATE_MARK_SWEEP defined (debug build) and RecordMarkSweepCompaction enabled");
0N/A#else
0N/A MarkSweep::print_new_location_of_heap_address((HeapWord*) old_heap_addr);
0N/A#endif
0N/A}
0N/A
0N/A
0N/Aextern "C" methodOop findm(intptr_t pc) {
0N/A Command c("findm");
0N/A nmethod* nm = CodeCache::find_nmethod((address)pc);
0N/A return (nm == NULL) ? (methodOop)NULL : nm->method();
0N/A}
0N/A
0N/A
0N/Aextern "C" nmethod* findnm(intptr_t addr) {
0N/A Command c("findnm");
0N/A return CodeCache::find_nmethod((address)addr);
0N/A}
0N/A
0N/Astatic address same_page(address x, address y) {
0N/A intptr_t page_bits = -os::vm_page_size();
0N/A if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits)) {
0N/A return x;
0N/A } else if (x > y) {
0N/A return (address)(intptr_t(y) | ~page_bits) + 1;
0N/A } else {
0N/A return (address)(intptr_t(y) & page_bits);
0N/A }
0N/A}
0N/A
0N/A
0N/Astatic void find(intptr_t x, bool print_pc) {
0N/A address addr = (address)x;
0N/A
0N/A CodeBlob* b = CodeCache::find_blob_unsafe(addr);
0N/A if (b != NULL) {
0N/A if (b->is_buffer_blob()) {
0N/A // the interpreter is generated into a buffer blob
0N/A InterpreterCodelet* i = Interpreter::codelet_containing(addr);
0N/A if (i != NULL) {
0N/A i->print();
0N/A return;
0N/A }
0N/A if (Interpreter::contains(addr)) {
0N/A tty->print_cr(INTPTR_FORMAT " is pointing into interpreter code (not bytecode specific)", addr);
0N/A return;
0N/A }
0N/A //
0N/A if (AdapterHandlerLibrary::contains(b)) {
0N/A AdapterHandlerLibrary::print_handler(b);
0N/A }
0N/A // the stubroutines are generated into a buffer blob
0N/A StubCodeDesc* d = StubCodeDesc::desc_for(addr);
0N/A if (d != NULL) {
0N/A d->print();
0N/A if (print_pc) tty->cr();
0N/A return;
0N/A }
0N/A if (StubRoutines::contains(addr)) {
0N/A tty->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) stub routine", addr);
0N/A return;
0N/A }
0N/A // the InlineCacheBuffer is using stubs generated into a buffer blob
0N/A if (InlineCacheBuffer::contains(addr)) {
0N/A tty->print_cr(INTPTR_FORMAT "is pointing into InlineCacheBuffer", addr);
0N/A return;
0N/A }
0N/A VtableStub* v = VtableStubs::stub_containing(addr);
0N/A if (v != NULL) {
0N/A v->print();
0N/A return;
0N/A }
0N/A }
0N/A if (print_pc && b->is_nmethod()) {
0N/A ResourceMark rm;
0N/A tty->print("%#p: Compiled ", addr);
0N/A ((nmethod*)b)->method()->print_value_on(tty);
0N/A tty->print(" = (CodeBlob*)" INTPTR_FORMAT, b);
0N/A tty->cr();
0N/A return;
0N/A }
0N/A if ( b->is_nmethod()) {
0N/A if (b->is_zombie()) {
0N/A tty->print_cr(INTPTR_FORMAT " is zombie nmethod", b);
0N/A } else if (b->is_not_entrant()) {
0N/A tty->print_cr(INTPTR_FORMAT " is non-entrant nmethod", b);
0N/A }
0N/A }
0N/A b->print();
0N/A return;
0N/A }
0N/A
0N/A if (Universe::heap()->is_in_reserved(addr)) {
0N/A HeapWord* p = Universe::heap()->block_start(addr);
0N/A bool print = false;
0N/A // If we couldn't find it it just may mean that heap wasn't parseable
0N/A // See if we were just given an oop directly
0N/A if (p != NULL && Universe::heap()->block_is_obj(p)) {
0N/A print = true;
0N/A } else if (p == NULL && ((oopDesc*)addr)->is_oop()) {
0N/A p = (HeapWord*) addr;
0N/A print = true;
0N/A }
0N/A if (print) {
0N/A oop(p)->print();
0N/A if (p != (HeapWord*)x && oop(p)->is_constMethod() &&
0N/A constMethodOop(p)->contains(addr)) {
0N/A Thread *thread = Thread::current();
0N/A HandleMark hm(thread);
0N/A methodHandle mh (thread, constMethodOop(p)->method());
0N/A if (!mh->is_native()) {
0N/A tty->print_cr("bci_from(%p) = %d; print_codes():",
0N/A addr, mh->bci_from(address(x)));
0N/A mh->print_codes();
0N/A }
0N/A }
0N/A return;
0N/A }
0N/A }
0N/A if (JNIHandles::is_global_handle((jobject) addr)) {
0N/A tty->print_cr(INTPTR_FORMAT "is a global jni handle", addr);
0N/A return;
0N/A }
0N/A if (JNIHandles::is_weak_global_handle((jobject) addr)) {
0N/A tty->print_cr(INTPTR_FORMAT "is a weak global jni handle", addr);
0N/A return;
0N/A }
0N/A if (JNIHandleBlock::any_contains((jobject) addr)) {
0N/A tty->print_cr(INTPTR_FORMAT "is a local jni handle", addr);
0N/A return;
0N/A }
0N/A
0N/A for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
0N/A // Check for priviledge stack
0N/A if (thread->privileged_stack_top() != NULL && thread->privileged_stack_top()->contains(addr)) {
0N/A tty->print_cr(INTPTR_FORMAT "is pointing into the priviledge stack for thread: " INTPTR_FORMAT, addr, thread);
0N/A return;
0N/A }
0N/A // If the addr is a java thread print information about that.
0N/A if (addr == (address)thread) {
0N/A thread->print();
0N/A return;
0N/A }
0N/A }
0N/A
0N/A // Try an OS specific find
0N/A if (os::find(addr)) {
0N/A return;
0N/A }
0N/A
0N/A if (print_pc) {
0N/A tty->print_cr(INTPTR_FORMAT ": probably in C++ code; check debugger", addr);
0N/A Disassembler::decode(same_page(addr-40,addr),same_page(addr+40,addr));
0N/A return;
0N/A }
0N/A
0N/A tty->print_cr(INTPTR_FORMAT "is pointing to unknown location", addr);
0N/A}
0N/A
0N/A
0N/Aclass LookForRefInGenClosure : public OopsInGenClosure {
0N/Apublic:
0N/A oop target;
0N/A void do_oop(oop* o) {
0N/A if (o != NULL && *o == target) {
0N/A tty->print_cr("0x%08x", o);
0N/A }
0N/A }
113N/A void do_oop(narrowOop* o) { ShouldNotReachHere(); }
0N/A};
0N/A
0N/A
0N/Aclass LookForRefInObjectClosure : public ObjectClosure {
0N/Aprivate:
0N/A LookForRefInGenClosure look_in_object;
0N/Apublic:
0N/A LookForRefInObjectClosure(oop target) { look_in_object.target = target; }
0N/A void do_object(oop obj) {
0N/A obj->oop_iterate(&look_in_object);
0N/A }
0N/A};
0N/A
0N/A
0N/Astatic void findref(intptr_t x) {
0N/A GenCollectedHeap *gch = GenCollectedHeap::heap();
0N/A LookForRefInGenClosure lookFor;
0N/A lookFor.target = (oop) x;
0N/A LookForRefInObjectClosure look_in_object((oop) x);
0N/A
0N/A tty->print_cr("Searching heap:");
0N/A gch->object_iterate(&look_in_object);
0N/A
0N/A tty->print_cr("Searching strong roots:");
0N/A Universe::oops_do(&lookFor, false);
0N/A JNIHandles::oops_do(&lookFor); // Global (strong) JNI handles
0N/A Threads::oops_do(&lookFor);
0N/A ObjectSynchronizer::oops_do(&lookFor);
0N/A //FlatProfiler::oops_do(&lookFor);
0N/A SystemDictionary::oops_do(&lookFor);
0N/A
0N/A tty->print_cr("Done.");
0N/A}
0N/A
0N/Aclass FindClassObjectClosure: public ObjectClosure {
0N/A private:
0N/A const char* _target;
0N/A public:
0N/A FindClassObjectClosure(const char name[]) { _target = name; }
0N/A
0N/A virtual void do_object(oop obj) {
0N/A if (obj->is_klass()) {
0N/A Klass* k = klassOop(obj)->klass_part();
0N/A if (k->name() != NULL) {
0N/A ResourceMark rm;
0N/A const char* ext = k->external_name();
0N/A if ( strcmp(_target, ext) == 0 ) {
0N/A tty->print_cr("Found " INTPTR_FORMAT, obj);
0N/A obj->print();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A};
0N/A
0N/A//
0N/Aextern "C" void findclass(const char name[]) {
0N/A Command c("findclass");
0N/A if (name != NULL) {
0N/A tty->print_cr("Finding class %s -> ", name);
0N/A FindClassObjectClosure srch(name);
0N/A Universe::heap()->permanent_object_iterate(&srch);
0N/A }
0N/A}
0N/A
0N/A// Another interface that isn't ambiguous in dbx.
0N/A// Can we someday rename the other find to hsfind?
0N/Aextern "C" void hsfind(intptr_t x) {
0N/A Command c("hsfind");
0N/A find(x, false);
0N/A}
0N/A
0N/A
0N/Aextern "C" void hsfindref(intptr_t x) {
0N/A Command c("hsfindref");
0N/A findref(x);
0N/A}
0N/A
0N/Aextern "C" void find(intptr_t x) {
0N/A Command c("find");
0N/A find(x, false);
0N/A}
0N/A
0N/A
0N/Aextern "C" void findpc(intptr_t x) {
0N/A Command c("findpc");
0N/A find(x, true);
0N/A}
0N/A
0N/A
0N/A// int versions of all methods to avoid having to type type casts in the debugger
0N/A
0N/Avoid pp(intptr_t p) { pp((void*)p); }
0N/Avoid pp(oop p) { pp((void*)p); }
0N/A
0N/Avoid help() {
0N/A Command c("help");
0N/A tty->print_cr("basic");
0N/A tty->print_cr(" pp(void* p) - try to make sense of p");
0N/A tty->print_cr(" pv(intptr_t p)- ((PrintableResourceObj*) p)->print()");
0N/A tty->print_cr(" ps() - print current thread stack");
0N/A tty->print_cr(" pss() - print all thread stacks");
0N/A tty->print_cr(" pm(int pc) - print methodOop given compiled PC");
0N/A tty->print_cr(" findm(intptr_t pc) - finds methodOop");
0N/A tty->print_cr(" find(intptr_t x) - finds & prints nmethod/stub/bytecode/oop based on pointer into it");
0N/A
0N/A tty->print_cr("misc.");
0N/A tty->print_cr(" flush() - flushes the log file");
0N/A tty->print_cr(" events() - dump last 50 events");
0N/A
0N/A
0N/A tty->print_cr("compiler debugging");
0N/A tty->print_cr(" debug() - to set things up for compiler debugging");
0N/A tty->print_cr(" ndebug() - undo debug");
0N/A}
0N/A
0N/A#if 0
0N/A
0N/A// BobV's command parser for debugging on windows when nothing else works.
0N/A
0N/Aenum CommandID {
0N/A CMDID_HELP,
0N/A CMDID_QUIT,
0N/A CMDID_HSFIND,
0N/A CMDID_PSS,
0N/A CMDID_PS,
0N/A CMDID_PSF,
0N/A CMDID_FINDM,
0N/A CMDID_FINDNM,
0N/A CMDID_PP,
0N/A CMDID_BPT,
0N/A CMDID_EXIT,
0N/A CMDID_VERIFY,
0N/A CMDID_THREADS,
0N/A CMDID_ILLEGAL = 99
0N/A};
0N/A
0N/Astruct CommandParser {
0N/A char *name;
0N/A CommandID code;
0N/A char *description;
0N/A};
0N/A
0N/Astruct CommandParser CommandList[] = {
0N/A (char *)"help", CMDID_HELP, " Dump this list",
0N/A (char *)"quit", CMDID_QUIT, " Return from this routine",
0N/A (char *)"hsfind", CMDID_HSFIND, "Perform an hsfind on an address",
0N/A (char *)"ps", CMDID_PS, " Print Current Thread Stack Trace",
0N/A (char *)"pss", CMDID_PSS, " Print All Thread Stack Trace",
0N/A (char *)"psf", CMDID_PSF, " Print All Stack Frames",
0N/A (char *)"findm", CMDID_FINDM, " Find a methodOop from a PC",
0N/A (char *)"findnm", CMDID_FINDNM, "Find an nmethod from a PC",
0N/A (char *)"pp", CMDID_PP, " Find out something about a pointer",
0N/A (char *)"break", CMDID_BPT, " Execute a breakpoint",
0N/A (char *)"exitvm", CMDID_EXIT, "Exit the VM",
0N/A (char *)"verify", CMDID_VERIFY, "Perform a Heap Verify",
0N/A (char *)"thread", CMDID_THREADS, "Dump Info on all Threads",
0N/A (char *)0, CMDID_ILLEGAL
0N/A};
0N/A
0N/A
0N/A// get_debug_command()
0N/A//
0N/A// Read a command from standard input.
0N/A// This is useful when you have a debugger
0N/A// which doesn't support calling into functions.
0N/A//
0N/Avoid get_debug_command()
0N/A{
0N/A ssize_t count;
0N/A int i,j;
0N/A bool gotcommand;
0N/A intptr_t addr;
0N/A char buffer[256];
0N/A nmethod *nm;
0N/A methodOop m;
0N/A
0N/A tty->print_cr("You have entered the diagnostic command interpreter");
0N/A tty->print("The supported commands are:\n");
0N/A for ( i=0; ; i++ ) {
0N/A if ( CommandList[i].code == CMDID_ILLEGAL )
0N/A break;
0N/A tty->print_cr(" %s \n", CommandList[i].name );
0N/A }
0N/A
0N/A while ( 1 ) {
0N/A gotcommand = false;
0N/A tty->print("Please enter a command: ");
0N/A count = scanf("%s", buffer) ;
0N/A if ( count >=0 ) {
0N/A for ( i=0; ; i++ ) {
0N/A if ( CommandList[i].code == CMDID_ILLEGAL ) {
0N/A if (!gotcommand) tty->print("Invalid command, please try again\n");
0N/A break;
0N/A }
0N/A if ( strcmp(buffer, CommandList[i].name) == 0 ) {
0N/A gotcommand = true;
0N/A switch ( CommandList[i].code ) {
0N/A case CMDID_PS:
0N/A ps();
0N/A break;
0N/A case CMDID_PSS:
0N/A pss();
0N/A break;
0N/A case CMDID_PSF:
0N/A psf();
0N/A break;
0N/A case CMDID_FINDM:
0N/A tty->print("Please enter the hex addr to pass to findm: ");
0N/A scanf("%I64X", &addr);
0N/A m = (methodOop)findm(addr);
0N/A tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m);
0N/A break;
0N/A case CMDID_FINDNM:
0N/A tty->print("Please enter the hex addr to pass to findnm: ");
0N/A scanf("%I64X", &addr);
0N/A nm = (nmethod*)findnm(addr);
0N/A tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm);
0N/A break;
0N/A case CMDID_PP:
0N/A tty->print("Please enter the hex addr to pass to pp: ");
0N/A scanf("%I64X", &addr);
0N/A pp((void*)addr);
0N/A break;
0N/A case CMDID_EXIT:
0N/A exit(0);
0N/A case CMDID_HELP:
0N/A tty->print("Here are the supported commands: ");
0N/A for ( j=0; ; j++ ) {
0N/A if ( CommandList[j].code == CMDID_ILLEGAL )
0N/A break;
0N/A tty->print_cr(" %s -- %s\n", CommandList[j].name,
0N/A CommandList[j].description );
0N/A }
0N/A break;
0N/A case CMDID_QUIT:
0N/A return;
0N/A break;
0N/A case CMDID_BPT:
0N/A BREAKPOINT;
0N/A break;
0N/A case CMDID_VERIFY:
0N/A verify();;
0N/A break;
0N/A case CMDID_THREADS:
0N/A threads();;
0N/A break;
0N/A case CMDID_HSFIND:
0N/A tty->print("Please enter the hex addr to pass to hsfind: ");
0N/A scanf("%I64X", &addr);
0N/A tty->print("Calling hsfind(0x%I64X)\n", addr);
0N/A hsfind(addr);
0N/A break;
0N/A default:
0N/A case CMDID_ILLEGAL:
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A#endif // PRODUCT