debug.cpp revision 1879
0N/A/*
1601N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "code/codeCache.hpp"
1879N/A#include "code/icBuffer.hpp"
1879N/A#include "code/nmethod.hpp"
1879N/A#include "code/vtableStubs.hpp"
1879N/A#include "compiler/compileBroker.hpp"
1879N/A#include "compiler/disassembler.hpp"
1879N/A#include "gc_implementation/shared/markSweep.hpp"
1879N/A#include "gc_interface/collectedHeap.hpp"
1879N/A#include "interpreter/bytecodeHistogram.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "memory/universe.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "prims/privilegedStack.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/frame.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/stubCodeGenerator.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "runtime/vframe.hpp"
1879N/A#include "services/heapDumper.hpp"
1879N/A#include "utilities/defaultStream.hpp"
1879N/A#include "utilities/events.hpp"
1879N/A#include "utilities/top.hpp"
1879N/A#include "utilities/vmError.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "os_linux.inline.hpp"
1879N/A# include "thread_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "os_solaris.inline.hpp"
1879N/A# include "thread_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "os_windows.inline.hpp"
1879N/A# include "thread_windows.inline.hpp"
1879N/A#endif
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, ...) {
1790N/A if (PrintWarnings) {
1790N/A // In case error happens before init or during shutdown
1790N/A if (tty == NULL) ostream_init();
0N/A
1790N/A tty->print("%s warning: ", VM_Version::vm_name());
1790N/A va_list ap;
1790N/A va_start(ap, format);
1790N/A tty->vprint_cr(format, ap);
1790N/A va_end(ap);
1790N/A }
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.
1410N/Abool error_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:
1410N/A#define error_is_suppressed(file_name, line_no) (false)
0N/A
0N/A#endif //PRODUCT
0N/A
1410N/Avoid report_vm_error(const char* file, int line, const char* error_msg,
1410N/A const char* detail_msg)
1410N/A{
1410N/A if (Debugging || error_is_suppressed(file, line)) return;
1410N/A Thread* const thread = ThreadLocalStorage::get_thread_slow();
1410N/A VMError err(thread, file, line, error_msg, detail_msg);
0N/A err.report_and_die();
0N/A}
0N/A
1410N/Avoid report_fatal(const char* file, int line, const char* message)
1410N/A{
1410N/A report_vm_error(file, line, "fatal error", message);
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
1410N/Avoid report_vm_out_of_memory(const char* file, int line, size_t size,
1410N/A const char* message) {
1410N/A if (Debugging || error_is_suppressed(file, line)) 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();
1410N/A VMError(thread, file, line, size, message).report_and_die();
0N/A }
227N/A
227N/A // Dump core and abort
227N/A vm_abort(true);
0N/A}
0N/A
1410N/Avoid report_should_not_call(const char* file, int line) {
1410N/A report_vm_error(file, line, "ShouldNotCall()");
0N/A}
0N/A
1410N/Avoid report_should_not_reach_here(const char* file, int line) {
1410N/A report_vm_error(file, line, "ShouldNotReachHere()");
0N/A}
0N/A
1410N/Avoid report_unimplemented(const char* file, int line) {
1410N/A report_vm_error(file, line, "Unimplemented()");
0N/A}
0N/A
1410N/Avoid report_untested(const char* file, int line, const char* message) {
0N/A#ifndef PRODUCT
1410N/A warning("Untested: %s in %s: %d\n", message, file, line);
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);
1695N/A HeapDumper::dump_heap_from_oome();
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
1410N/A#ifndef PRODUCT
1410N/A#include <signal.h>
1410N/A
1410N/Avoid test_error_handler(size_t test_num)
1410N/A{
1410N/A if (test_num == 0) return;
1410N/A
1410N/A // If asserts are disabled, use the corresponding guarantee instead.
1410N/A size_t n = test_num;
1410N/A NOT_DEBUG(if (n <= 2) n += 2);
1410N/A
1410N/A const char* const str = "hello";
1410N/A const size_t num = (size_t)os::vm_page_size();
1410N/A
1410N/A const char* const eol = os::line_separator();
1410N/A const char* const msg = "this message should be truncated during formatting";
1410N/A
1410N/A // Keep this in sync with test/runtime/6888954/vmerrors.sh.
1410N/A switch (n) {
1410N/A case 1: assert(str == NULL, "expected null");
1410N/A case 2: assert(num == 1023 && *str == 'X',
1410N/A err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
1410N/A case 3: guarantee(str == NULL, "expected null");
1410N/A case 4: guarantee(num == 1023 && *str == 'X',
1410N/A err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
1410N/A case 5: fatal("expected null");
1410N/A case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
1410N/A case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# "
1410N/A "%s%s# %s%s# %s%s# %s%s# %s%s# "
1410N/A "%s%s# %s%s# %s%s# %s%s# %s",
1410N/A msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
1410N/A msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
1410N/A msg, eol, msg, eol, msg, eol, msg, eol, msg));
1410N/A case 8: vm_exit_out_of_memory(num, "ChunkPool::allocate");
1410N/A case 9: ShouldNotCallThis();
1410N/A case 10: ShouldNotReachHere();
1410N/A case 11: Unimplemented();
1410N/A // This is last because it does not generate an hs_err* file on Windows.
1410N/A case 12: os::signal_raise(SIGSEGV);
1410N/A
1410N/A default: ShouldNotReachHere();
1410N/A }
1410N/A}
1410N/A#endif // #ifndef PRODUCT
1410N/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/Aclass LookForRefInGenClosure : public OopsInGenClosure {
0N/Apublic:
0N/A oop target;
0N/A void do_oop(oop* o) {
0N/A if (o != NULL && *o == target) {
342N/A tty->print_cr(INTPTR_FORMAT, 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) {
342N/A CollectedHeap *ch = Universe::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:");
342N/A ch->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
989N/A Threads::oops_do(&lookFor, NULL);
0N/A ObjectSynchronizer::oops_do(&lookFor);
0N/A //FlatProfiler::oops_do(&lookFor);
0N/A SystemDictionary::oops_do(&lookFor);
0N/A
989N/A tty->print_cr("Searching code cache:");
989N/A CodeCache::oops_do(&lookFor);
989N/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");
1601N/A os::print_location(tty, 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");
1601N/A os::print_location(tty, x, false);
0N/A}
0N/A
0N/A
0N/Aextern "C" void findpc(intptr_t x) {
0N/A Command c("findpc");
1601N/A os::print_location(tty, 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