debug.cpp revision 2062
0N/A/*
2362N/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
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "classfile/systemDictionary.hpp"
0N/A#include "code/codeCache.hpp"
0N/A#include "code/icBuffer.hpp"
0N/A#include "code/nmethod.hpp"
0N/A#include "code/vtableStubs.hpp"
0N/A#include "compiler/compileBroker.hpp"
0N/A#include "compiler/disassembler.hpp"
0N/A#include "gc_implementation/shared/markSweep.hpp"
0N/A#include "gc_interface/collectedHeap.hpp"
0N/A#include "interpreter/bytecodeHistogram.hpp"
0N/A#include "interpreter/interpreter.hpp"
0N/A#include "memory/resourceArea.hpp"
0N/A#include "memory/universe.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A#include "prims/privilegedStack.hpp"
0N/A#include "runtime/arguments.hpp"
0N/A#include "runtime/frame.hpp"
0N/A#include "runtime/java.hpp"
0N/A#include "runtime/sharedRuntime.hpp"
0N/A#include "runtime/stubCodeGenerator.hpp"
0N/A#include "runtime/stubRoutines.hpp"
0N/A#include "runtime/vframe.hpp"
0N/A#include "services/heapDumper.hpp"
0N/A#include "utilities/defaultStream.hpp"
0N/A#include "utilities/events.hpp"
0N/A#include "utilities/top.hpp"
0N/A#include "utilities/vmError.hpp"
0N/A#ifdef TARGET_OS_FAMILY_linux
0N/A# include "os_linux.inline.hpp"
0N/A# include "thread_linux.inline.hpp"
0N/A#endif
0N/A#ifdef TARGET_OS_FAMILY_solaris
10N/A# include "os_solaris.inline.hpp"
10N/A# include "thread_solaris.inline.hpp"
10N/A#endif
10N/A#ifdef TARGET_OS_FAMILY_windows
0N/A# include "os_windows.inline.hpp"
0N/A# include "thread_windows.inline.hpp"
0N/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, ...) {
0N/A if (PrintWarnings) {
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());
1220N/A va_list ap;
1220N/A va_start(ap, format);
1220N/A tty->vprint_cr(format, ap);
1220N/A va_end(ap);
1220N/A }
1220N/A if (BreakAtWarning) BREAKPOINT;
1220N/A}
1220N/A
1220N/A#ifndef PRODUCT
1220N/A
1220N/A#define is_token_break(ch) (isspace(ch) || (ch) == ',')
1220N/A
1220N/Astatic const char* last_file_name = NULL;
1220N/Astatic int last_line_no = -1;
1220N/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 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++;
914N/A if ((*cp) == '\0') break;
0N/A sfile = cp;
914N/A while ((*cp) != '\0' && !is_token_break(*cp) && (*cp) != ':') cp++;
0N/A sfile_len = cp - sfile;
0N/A if ((*cp) == ':') cp++;
2664N/A sline = 0;
2664N/A while ((*cp) != '\0' && isdigit(*cp)) {
2664N/A sline *= 10;
2664N/A sline += (*cp) - '0';
2664N/A cp++;
0N/A }
0N/A // "file:line!" means the assert suppression is not silent
2664N/A noisy = ((*cp) == '!');
0N/A while ((*cp) != '\0' && !is_token_break(*cp)) cp++;
0N/A // match the line
2664N/A if (sline != 0) {
0N/A if (sline != line_no) continue;
0N/A }
2664N/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
914N/A && foundp <= look_max) {
914N/A match = true;
914N/A for (int i = 1; i < sfile_len; i++) {
914N/A if (sfile[i] != foundp[i]) {
914N/A match = false;
914N/A break;
914N/A }
914N/A }
914N/A look = foundp + 1;
914N/A }
914N/A if (!match) continue;
914N/A }
914N/A // got a match!
914N/A if (noisy) {
0N/A fdStream out(defaultStream::output_fd());
914N/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 error_is_suppressed(file_name, line_no) (false)
0N/A
0N/A#endif //PRODUCT
0N/A
0N/Avoid report_vm_error(const char* file, int line, const char* error_msg,
0N/A const char* detail_msg)
0N/A{
0N/A if (Debugging || error_is_suppressed(file, line)) return;
0N/A Thread* const thread = ThreadLocalStorage::get_thread_slow();
420N/A VMError err(thread, file, line, error_msg, detail_msg);
420N/A err.report_and_die();
420N/A}
420N/A
420N/Avoid report_fatal(const char* file, int line, const char* message)
420N/A{
420N/A report_vm_error(file, line, "fatal error", message);
2807N/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/Avoid report_vm_out_of_memory(const char* file, int line, size_t size,
0N/A const char* message) {
0N/A if (Debugging) 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, file, line, size, message).report_and_die();
0N/A }
0N/A
0N/A // Dump core and abort
0N/A vm_abort(true);
0N/A}
0N/A
0N/Avoid report_should_not_call(const char* file, int line) {
0N/A report_vm_error(file, line, "ShouldNotCall()");
0N/A}
0N/A
0N/Avoid report_should_not_reach_here(const char* file, int line) {
0N/A report_vm_error(file, line, "ShouldNotReachHere()");
0N/A}
0N/A
0N/Avoid report_unimplemented(const char* file, int line) {
0N/A report_vm_error(file, line, "Unimplemented()");
0N/A}
0N/A
0N/Avoid report_untested(const char* file, int line, const char* message) {
0N/A#ifndef PRODUCT
0N/A warning("Untested: %s in %s: %d\n", message, file, line);
0N/A#endif // PRODUCT
0N/A}
0N/A
0N/Avoid report_out_of_shared_space(SharedSpaceType shared_space) {
0N/A static const char* name[] = {
0N/A "permanent generation",
0N/A "shared read only space",
0N/A "shared read write space",
0N/A "shared miscellaneous data space"
0N/A };
0N/A static const char* flag[] = {
0N/A "PermGen",
0N/A "SharedReadOnlySize",
0N/A "SharedReadWriteSize",
0N/A "SharedMiscDataSize"
0N/A };
0N/A
0N/A warning("\nThe %s is not large enough\n"
0N/A "to preload requested classes. Use -XX:%s=\n"
0N/A "to increase the initial size of %s.\n",
0N/A name[shared_space], flag[shared_space], name[shared_space]);
0N/A exit(2);
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
167N/A // A number of threads may attempt to report OutOfMemoryError at around the
167N/A // same time. To avoid dumping the heap or executing the data collection
167N/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_from_oome();
0N/A }
1365N/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#ifndef PRODUCT
0N/A#include <signal.h>
0N/A
0N/Avoid test_error_handler(size_t test_num)
0N/A{
0N/A if (test_num == 0) return;
0N/A
0N/A // If asserts are disabled, use the corresponding guarantee instead.
0N/A size_t n = test_num;
0N/A NOT_DEBUG(if (n <= 2) n += 2);
0N/A
0N/A const char* const str = "hello";
0N/A const size_t num = (size_t)os::vm_page_size();
0N/A
0N/A const char* const eol = os::line_separator();
0N/A const char* const msg = "this message should be truncated during formatting";
0N/A
0N/A // Keep this in sync with test/runtime/6888954/vmerrors.sh.
0N/A switch (n) {
0N/A case 1: assert(str == NULL, "expected null");
0N/A case 2: assert(num == 1023 && *str == 'X',
0N/A err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
0N/A case 3: guarantee(str == NULL, "expected null");
0N/A case 4: guarantee(num == 1023 && *str == 'X',
0N/A err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
0N/A case 5: fatal("expected null");
0N/A case 6: fatal(err_msg("num=" SIZE_FORMAT " str=\"%s\"", num, str));
0N/A case 7: fatal(err_msg("%s%s# %s%s# %s%s# %s%s# %s%s# "
0N/A "%s%s# %s%s# %s%s# %s%s# %s%s# "
0N/A "%s%s# %s%s# %s%s# %s%s# %s",
0N/A msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
0N/A msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
0N/A msg, eol, msg, eol, msg, eol, msg, eol, msg));
0N/A case 8: vm_exit_out_of_memory(num, "ChunkPool::allocate");
0N/A case 9: ShouldNotCallThis();
0N/A case 10: ShouldNotReachHere();
0N/A case 11: Unimplemented();
0N/A // This is last because it does not generate an hs_err* file on Windows.
0N/A case 12: os::signal_raise(SIGSEGV);
0N/A
0N/A default: ShouldNotReachHere();
0N/A }
0N/A}
0N/A#endif // #ifndef PRODUCT
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;
1220N/A public:
0N/A static int level;
0N/A Command(const char* str) {
0N/A debug_save = Debugging;
1220N/A Debugging = true;
1220N/A if (level++ > 0) return;
1220N/A tty->cr();
1220N/A tty->print_cr("\"Executing %s\"", str);
1220N/A }
0N/A
0N/A ~Command() { tty->flush(); Debugging = debug_save; level--; }
0N/A};
0N/A
0N/Aint Command::level = 0;
533N/A
533N/Aextern "C" void blob(CodeBlob* cb) {
0N/A Command c("blob");
0N/A cb->print();
0N/A}
533N/A
533N/A
0N/Aextern "C" void dump_vtable(address p) {
533N/A Command c("dump_vtable");
533N/A klassOop k = (klassOop)p;
533N/A instanceKlass::cast(k)->vtable()->print();
533N/A}
533N/A
533N/A
533N/Aextern "C" void nm(intptr_t p) {
533N/A // Actually we look through all CodeBlobs (the nm name has been kept for backwards compatability)
533N/A Command c("nm");
533N/A CodeBlob* cb = CodeCache::find_blob((address)p);
533N/A if (cb == NULL) {
533N/A tty->print_cr("NULL");
533N/A } else {
533N/A cb->print();
533N/A }
533N/A}
533N/A
533N/A
533N/Aextern "C" void disnm(intptr_t p) {
533N/A Command c("disnm");
533N/A CodeBlob* cb = CodeCache::find_blob((address) p);
533N/A nmethod* nm = cb->as_nmethod_or_null();
533N/A if (nm) {
533N/A nm->print();
533N/A Disassembler::decode(nm);
533N/A } else {
533N/A cb->print();
533N/A Disassembler::decode(cb);
533N/A }
533N/A}
533N/A
533N/A
533N/Aextern "C" void printnm(intptr_t p) {
533N/A char buffer[256];
533N/A sprintf(buffer, "printnm: " INTPTR_FORMAT, p);
533N/A Command c(buffer);
533N/A CodeBlob* cb = CodeCache::find_blob((address) p);
533N/A if (cb->is_nmethod()) {
533N/A nmethod* nm = (nmethod*)cb;
533N/A nm->print_nmethod(true);
533N/A }
533N/A}
533N/A
533N/A
533N/Aextern "C" void universe() {
533N/A Command c("universe");
533N/A Universe::print();
533N/A}
533N/A
533N/A
533N/Aextern "C" void verify() {
533N/A // try to run a verify on the entire system
533N/A // note: this may not be safe if we're not at a safepoint; for debugging,
533N/A // this manipulates the safepoint settings to avoid assertion failures
533N/A Command c("universe verify");
533N/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(); }
10N/Aextern "C" void findpc(intptr_t x);
10N/A
10N/Aextern "C" void ps() { // print stack
0N/A Command c("ps");
0N/A
10N/A
10N/A // Prints the stack of the current Java thread
10N/A JavaThread* p = JavaThread::active();
10N/A tty->print(" for thread: ");
10N/A p->print();
10N/A tty->cr();
10N/A
10N/A if (p->has_last_Java_frame()) {
10N/A // If the last_Java_fp is set we are in C land and
10N/A // can call the standard stack_trace function.
10N/A p->trace_stack();
10N/A } else {
0N/A frame f = os::current_frame();
10N/A RegisterMap reg_map(p);
0N/A f = f.sender(&reg_map);
10N/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);
160N/A }
160N/A
160N/A}
160N/A
160N/A
160N/Aextern "C" void psf() { // print stack frames
160N/A {
10N/A Command c("psf");
10N/A JavaThread* p = JavaThread::active();
10N/A tty->print(" for thread: ");
10N/A p->print();
10N/A tty->cr();
160N/A if (p->has_last_Java_frame()) {
160N/A p->trace_frames();
10N/A }
10N/A }
10N/A}
10N/A
10N/A
10N/Aextern "C" void threads() {
10N/A Command c("threads");
10N/A Threads::print(false, true);
10N/A}
10N/A
10N/A
10N/Aextern "C" void psd() {
10N/A Command c("psd");
10N/A SystemDictionary::print();
10N/A}
10N/A
10N/A
10N/Aextern "C" void safepoints() {
10N/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
1173N/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();
535N/A}
535N/A
535N/A
535N/Aextern "C" void events() {
535N/A Command c("events");
117N/A Events::print_last(tty, 50);
117N/A}
117N/A
117N/A
117N/Aextern "C" void nevents(int n) {
117N/A Command c("events");
117N/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
944N/A// certain kinds of naked oop and oop map bugs.
944N/Aextern "C" void pnl(intptr_t old_heap_addr) {
944N/A // Print New Location of old heap address
944N/A Command c("pnl");
0N/A#ifndef VALIDATE_MARK_SWEEP
944N/A tty->print_cr("Requires build with VALIDATE_MARK_SWEEP defined (debug build) and RecordMarkSweepCompaction enabled");
944N/A#else
944N/A MarkSweep::print_new_location_of_heap_address((HeapWord*) old_heap_addr);
944N/A#endif
0N/A}
944N/A
944N/A
944N/Aextern "C" methodOop findm(intptr_t pc) {
944N/A Command c("findm");
944N/A nmethod* nm = CodeCache::find_nmethod((address)pc);
944N/A return (nm == NULL) ? (methodOop)NULL : nm->method();
914N/A}
914N/A
944N/A
944N/Aextern "C" nmethod* findnm(intptr_t addr) {
944N/A Command c("findnm");
return CodeCache::find_nmethod((address)addr);
}
static address same_page(address x, address y) {
intptr_t page_bits = -os::vm_page_size();
if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits)) {
return x;
} else if (x > y) {
return (address)(intptr_t(y) | ~page_bits) + 1;
} else {
return (address)(intptr_t(y) & page_bits);
}
}
class LookForRefInGenClosure : public OopsInGenClosure {
public:
oop target;
void do_oop(oop* o) {
if (o != NULL && *o == target) {
tty->print_cr(INTPTR_FORMAT, o);
}
}
void do_oop(narrowOop* o) { ShouldNotReachHere(); }
};
class LookForRefInObjectClosure : public ObjectClosure {
private:
LookForRefInGenClosure look_in_object;
public:
LookForRefInObjectClosure(oop target) { look_in_object.target = target; }
void do_object(oop obj) {
obj->oop_iterate(&look_in_object);
}
};
static void findref(intptr_t x) {
CollectedHeap *ch = Universe::heap();
LookForRefInGenClosure lookFor;
lookFor.target = (oop) x;
LookForRefInObjectClosure look_in_object((oop) x);
tty->print_cr("Searching heap:");
ch->object_iterate(&look_in_object);
tty->print_cr("Searching strong roots:");
Universe::oops_do(&lookFor, false);
JNIHandles::oops_do(&lookFor); // Global (strong) JNI handles
Threads::oops_do(&lookFor, NULL);
ObjectSynchronizer::oops_do(&lookFor);
//FlatProfiler::oops_do(&lookFor);
SystemDictionary::oops_do(&lookFor);
tty->print_cr("Searching code cache:");
CodeCache::oops_do(&lookFor);
tty->print_cr("Done.");
}
class FindClassObjectClosure: public ObjectClosure {
private:
const char* _target;
public:
FindClassObjectClosure(const char name[]) { _target = name; }
virtual void do_object(oop obj) {
if (obj->is_klass()) {
Klass* k = klassOop(obj)->klass_part();
if (k->name() != NULL) {
ResourceMark rm;
const char* ext = k->external_name();
if ( strcmp(_target, ext) == 0 ) {
tty->print_cr("Found " INTPTR_FORMAT, obj);
obj->print();
}
}
}
}
};
//
extern "C" void findclass(const char name[]) {
Command c("findclass");
if (name != NULL) {
tty->print_cr("Finding class %s -> ", name);
FindClassObjectClosure srch(name);
Universe::heap()->permanent_object_iterate(&srch);
}
}
// Another interface that isn't ambiguous in dbx.
// Can we someday rename the other find to hsfind?
extern "C" void hsfind(intptr_t x) {
Command c("hsfind");
os::print_location(tty, x, false);
}
extern "C" void hsfindref(intptr_t x) {
Command c("hsfindref");
findref(x);
}
extern "C" void find(intptr_t x) {
Command c("find");
os::print_location(tty, x, false);
}
extern "C" void findpc(intptr_t x) {
Command c("findpc");
os::print_location(tty, x, true);
}
// int versions of all methods to avoid having to type type casts in the debugger
void pp(intptr_t p) { pp((void*)p); }
void pp(oop p) { pp((void*)p); }
void help() {
Command c("help");
tty->print_cr("basic");
tty->print_cr(" pp(void* p) - try to make sense of p");
tty->print_cr(" pv(intptr_t p)- ((PrintableResourceObj*) p)->print()");
tty->print_cr(" ps() - print current thread stack");
tty->print_cr(" pss() - print all thread stacks");
tty->print_cr(" pm(int pc) - print methodOop given compiled PC");
tty->print_cr(" findm(intptr_t pc) - finds methodOop");
tty->print_cr(" find(intptr_t x) - finds & prints nmethod/stub/bytecode/oop based on pointer into it");
tty->print_cr("misc.");
tty->print_cr(" flush() - flushes the log file");
tty->print_cr(" events() - dump last 50 events");
tty->print_cr("compiler debugging");
tty->print_cr(" debug() - to set things up for compiler debugging");
tty->print_cr(" ndebug() - undo debug");
}
#if 0
// BobV's command parser for debugging on windows when nothing else works.
enum CommandID {
CMDID_HELP,
CMDID_QUIT,
CMDID_HSFIND,
CMDID_PSS,
CMDID_PS,
CMDID_PSF,
CMDID_FINDM,
CMDID_FINDNM,
CMDID_PP,
CMDID_BPT,
CMDID_EXIT,
CMDID_VERIFY,
CMDID_THREADS,
CMDID_ILLEGAL = 99
};
struct CommandParser {
char *name;
CommandID code;
char *description;
};
struct CommandParser CommandList[] = {
(char *)"help", CMDID_HELP, " Dump this list",
(char *)"quit", CMDID_QUIT, " Return from this routine",
(char *)"hsfind", CMDID_HSFIND, "Perform an hsfind on an address",
(char *)"ps", CMDID_PS, " Print Current Thread Stack Trace",
(char *)"pss", CMDID_PSS, " Print All Thread Stack Trace",
(char *)"psf", CMDID_PSF, " Print All Stack Frames",
(char *)"findm", CMDID_FINDM, " Find a methodOop from a PC",
(char *)"findnm", CMDID_FINDNM, "Find an nmethod from a PC",
(char *)"pp", CMDID_PP, " Find out something about a pointer",
(char *)"break", CMDID_BPT, " Execute a breakpoint",
(char *)"exitvm", CMDID_EXIT, "Exit the VM",
(char *)"verify", CMDID_VERIFY, "Perform a Heap Verify",
(char *)"thread", CMDID_THREADS, "Dump Info on all Threads",
(char *)0, CMDID_ILLEGAL
};
// get_debug_command()
//
// Read a command from standard input.
// This is useful when you have a debugger
// which doesn't support calling into functions.
//
void get_debug_command()
{
ssize_t count;
int i,j;
bool gotcommand;
intptr_t addr;
char buffer[256];
nmethod *nm;
methodOop m;
tty->print_cr("You have entered the diagnostic command interpreter");
tty->print("The supported commands are:\n");
for ( i=0; ; i++ ) {
if ( CommandList[i].code == CMDID_ILLEGAL )
break;
tty->print_cr(" %s \n", CommandList[i].name );
}
while ( 1 ) {
gotcommand = false;
tty->print("Please enter a command: ");
count = scanf("%s", buffer) ;
if ( count >=0 ) {
for ( i=0; ; i++ ) {
if ( CommandList[i].code == CMDID_ILLEGAL ) {
if (!gotcommand) tty->print("Invalid command, please try again\n");
break;
}
if ( strcmp(buffer, CommandList[i].name) == 0 ) {
gotcommand = true;
switch ( CommandList[i].code ) {
case CMDID_PS:
ps();
break;
case CMDID_PSS:
pss();
break;
case CMDID_PSF:
psf();
break;
case CMDID_FINDM:
tty->print("Please enter the hex addr to pass to findm: ");
scanf("%I64X", &addr);
m = (methodOop)findm(addr);
tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m);
break;
case CMDID_FINDNM:
tty->print("Please enter the hex addr to pass to findnm: ");
scanf("%I64X", &addr);
nm = (nmethod*)findnm(addr);
tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm);
break;
case CMDID_PP:
tty->print("Please enter the hex addr to pass to pp: ");
scanf("%I64X", &addr);
pp((void*)addr);
break;
case CMDID_EXIT:
exit(0);
case CMDID_HELP:
tty->print("Here are the supported commands: ");
for ( j=0; ; j++ ) {
if ( CommandList[j].code == CMDID_ILLEGAL )
break;
tty->print_cr(" %s -- %s\n", CommandList[j].name,
CommandList[j].description );
}
break;
case CMDID_QUIT:
return;
break;
case CMDID_BPT:
BREAKPOINT;
break;
case CMDID_VERIFY:
verify();;
break;
case CMDID_THREADS:
threads();;
break;
case CMDID_HSFIND:
tty->print("Please enter the hex addr to pass to hsfind: ");
scanf("%I64X", &addr);
tty->print("Calling hsfind(0x%I64X)\n", addr);
hsfind(addr);
break;
default:
case CMDID_ILLEGAL:
break;
}
}
}
}
}
}
#endif
#endif // PRODUCT