aoqi@0: /* aoqi@0: * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/javaClasses.hpp" aoqi@0: #include "code/codeCache.hpp" aoqi@0: #include "compiler/disassembler.hpp" aoqi@0: #include "gc_interface/collectedHeap.hpp" aoqi@0: #include "memory/cardTableModRefBS.hpp" aoqi@0: #include "runtime/fprofiler.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/stubCodeGenerator.hpp" aoqi@0: #include "runtime/stubRoutines.hpp" aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "depChecker_x86.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "depChecker_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "depChecker_zero.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "depChecker_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "depChecker_ppc.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "depChecker_mips.hpp" aoqi@1: #endif aoqi@0: #ifdef SHARK aoqi@0: #include "shark/sharkEntry.hpp" aoqi@0: #endif aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: void* Disassembler::_library = NULL; aoqi@0: bool Disassembler::_tried_to_load_library = false; aoqi@0: aoqi@0: // This routine is in the shared library: aoqi@0: Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; aoqi@0: Disassembler::decode_func Disassembler::_decode_instructions = NULL; aoqi@0: aoqi@0: static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH; aoqi@0: static const char decode_instructions_virtual_name[] = "decode_instructions_virtual"; aoqi@0: static const char decode_instructions_name[] = "decode_instructions"; aoqi@0: static bool use_new_version = true; aoqi@0: #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/ aoqi@0: #define BYTES_COMMENT ";..." /* funky byte display comment */ aoqi@0: aoqi@0: bool Disassembler::load_library() { aoqi@0: if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) { aoqi@0: // Already succeeded. aoqi@0: return true; aoqi@0: } aoqi@0: if (_tried_to_load_library) { aoqi@0: // Do not try twice. aoqi@0: // To force retry in debugger: assign _tried_to_load_library=0 aoqi@0: return false; aoqi@0: } aoqi@0: // Try to load it. aoqi@0: char ebuf[1024]; aoqi@0: char buf[JVM_MAXPATHLEN]; aoqi@0: os::jvm_path(buf, sizeof(buf)); aoqi@0: int jvm_offset = -1; aoqi@0: int lib_offset = -1; aoqi@0: { aoqi@0: // Match "jvm[^/]*" in jvm_path. aoqi@0: const char* base = buf; aoqi@0: const char* p = strrchr(buf, '/'); aoqi@0: if (p != NULL) lib_offset = p - base + 1; aoqi@0: p = strstr(p ? p : base, "jvm"); aoqi@0: if (p != NULL) jvm_offset = p - base; aoqi@0: } aoqi@0: // Find the disassembler shared library. aoqi@0: // Search for several paths derived from libjvm, in this order: aoqi@0: // 1. /jre/lib///libhsdis-.so (for compatibility) aoqi@0: // 2. /jre/lib///hsdis-.so aoqi@0: // 3. /jre/lib//hsdis-.so aoqi@0: // 4. hsdis-.so (using LD_LIBRARY_PATH) aoqi@0: if (jvm_offset >= 0) { aoqi@0: // 1. /jre/lib///libhsdis-.so aoqi@0: strcpy(&buf[jvm_offset], hsdis_library_name); aoqi@0: strcat(&buf[jvm_offset], os::dll_file_extension()); aoqi@0: _library = os::dll_load(buf, ebuf, sizeof ebuf); aoqi@0: if (_library == NULL) { aoqi@0: // 2. /jre/lib///hsdis-.so aoqi@0: strcpy(&buf[lib_offset], hsdis_library_name); aoqi@0: strcat(&buf[lib_offset], os::dll_file_extension()); aoqi@0: _library = os::dll_load(buf, ebuf, sizeof ebuf); aoqi@0: } aoqi@0: if (_library == NULL) { aoqi@0: // 3. /jre/lib//hsdis-.so aoqi@0: buf[lib_offset - 1] = '\0'; aoqi@0: const char* p = strrchr(buf, '/'); aoqi@0: if (p != NULL) { aoqi@0: lib_offset = p - buf + 1; aoqi@0: strcpy(&buf[lib_offset], hsdis_library_name); aoqi@0: strcat(&buf[lib_offset], os::dll_file_extension()); aoqi@0: _library = os::dll_load(buf, ebuf, sizeof ebuf); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: if (_library == NULL) { aoqi@0: // 4. hsdis-.so (using LD_LIBRARY_PATH) aoqi@0: strcpy(&buf[0], hsdis_library_name); aoqi@0: strcat(&buf[0], os::dll_file_extension()); aoqi@0: _library = os::dll_load(buf, ebuf, sizeof ebuf); aoqi@0: } aoqi@0: if (_library != NULL) { aoqi@0: _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual, aoqi@0: os::dll_lookup(_library, decode_instructions_virtual_name)); aoqi@0: } aoqi@0: if (_decode_instructions_virtual == NULL) { aoqi@0: // could not spot in new version, try old version aoqi@0: _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, aoqi@0: os::dll_lookup(_library, decode_instructions_name)); aoqi@0: use_new_version = false; aoqi@0: } else { aoqi@0: use_new_version = true; aoqi@0: } aoqi@0: _tried_to_load_library = true; aoqi@0: if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) { aoqi@0: tty->print_cr("Could not load %s; %s; %s", buf, aoqi@0: ((_library != NULL) aoqi@0: ? "entry point is missing" aoqi@0: : (WizardMode || PrintMiscellaneous) aoqi@0: ? (const char*)ebuf aoqi@0: : "library not loadable"), aoqi@0: "PrintAssembly is disabled"); aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Success. aoqi@0: tty->print_cr("Loaded disassembler from %s", buf); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: class decode_env { aoqi@0: private: aoqi@0: nmethod* _nm; aoqi@0: CodeBlob* _code; aoqi@0: CodeStrings _strings; aoqi@0: outputStream* _output; aoqi@0: address _start, _end; aoqi@0: aoqi@0: char _option_buf[512]; aoqi@0: char _print_raw; aoqi@0: bool _print_pc; aoqi@0: bool _print_bytes; aoqi@0: address _cur_insn; aoqi@0: int _total_ticks; aoqi@0: int _bytes_per_line; // arch-specific formatting option aoqi@0: aoqi@0: static bool match(const char* event, const char* tag) { aoqi@0: size_t taglen = strlen(tag); aoqi@0: if (strncmp(event, tag, taglen) != 0) aoqi@0: return false; aoqi@0: char delim = event[taglen]; aoqi@0: return delim == '\0' || delim == ' ' || delim == '/' || delim == '='; aoqi@0: } aoqi@0: aoqi@0: void collect_options(const char* p) { aoqi@0: if (p == NULL || p[0] == '\0') return; aoqi@0: size_t opt_so_far = strlen(_option_buf); aoqi@0: if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf)) return; aoqi@0: char* fillp = &_option_buf[opt_so_far]; aoqi@0: if (opt_so_far > 0) *fillp++ = ','; aoqi@0: strcat(fillp, p); aoqi@0: // replace white space by commas: aoqi@0: char* q = fillp; aoqi@0: while ((q = strpbrk(q, " \t\n")) != NULL) aoqi@0: *q++ = ','; aoqi@0: // Note that multiple PrintAssemblyOptions flags accumulate with \n, aoqi@0: // which we want to be changed to a comma... aoqi@0: } aoqi@0: aoqi@0: void print_insn_labels(); aoqi@0: void print_insn_bytes(address pc0, address pc); aoqi@0: void print_address(address value); aoqi@0: aoqi@0: public: aoqi@0: decode_env(CodeBlob* code, outputStream* output, CodeStrings c = CodeStrings()); aoqi@0: aoqi@0: address decode_instructions(address start, address end); aoqi@0: aoqi@0: void start_insn(address pc) { aoqi@0: _cur_insn = pc; aoqi@0: output()->bol(); aoqi@0: print_insn_labels(); aoqi@0: } aoqi@0: aoqi@0: void end_insn(address pc) { aoqi@0: address pc0 = cur_insn(); aoqi@0: outputStream* st = output(); aoqi@0: if (_print_bytes && pc > pc0) aoqi@0: print_insn_bytes(pc0, pc); aoqi@0: if (_nm != NULL) { aoqi@0: _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc); aoqi@0: // this calls reloc_string_for which calls oop::print_value_on aoqi@0: } aoqi@0: aoqi@0: // Output pc bucket ticks if we have any aoqi@0: if (total_ticks() != 0) { aoqi@0: address bucket_pc = FlatProfiler::bucket_start_for(pc); aoqi@0: if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) { aoqi@0: int bucket_count = FlatProfiler::bucket_count_for(pc0); aoqi@0: if (bucket_count != 0) { aoqi@0: st->bol(); aoqi@0: st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // follow each complete insn by a nice newline aoqi@0: st->cr(); aoqi@0: } aoqi@0: aoqi@0: address handle_event(const char* event, address arg); aoqi@0: aoqi@0: outputStream* output() { return _output; } aoqi@0: address cur_insn() { return _cur_insn; } aoqi@0: int total_ticks() { return _total_ticks; } aoqi@0: void set_total_ticks(int n) { _total_ticks = n; } aoqi@0: const char* options() { return _option_buf; } aoqi@0: }; aoqi@0: aoqi@0: decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) { drchase@7149: memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields. aoqi@0: _output = output ? output : tty; aoqi@0: _code = code; aoqi@0: if (code != NULL && code->is_nmethod()) aoqi@0: _nm = (nmethod*) code; drchase@7149: _strings.copy(c); aoqi@0: aoqi@0: // by default, output pc but not bytes: aoqi@0: _print_pc = true; aoqi@0: _print_bytes = false; aoqi@0: _bytes_per_line = Disassembler::pd_instruction_alignment(); aoqi@0: aoqi@0: // parse the global option string: aoqi@0: collect_options(Disassembler::pd_cpu_opts()); aoqi@0: collect_options(PrintAssemblyOptions); aoqi@0: aoqi@0: if (strstr(options(), "hsdis-")) { aoqi@0: if (strstr(options(), "hsdis-print-raw")) aoqi@0: _print_raw = (strstr(options(), "xml") ? 2 : 1); aoqi@0: if (strstr(options(), "hsdis-print-pc")) aoqi@0: _print_pc = !_print_pc; aoqi@0: if (strstr(options(), "hsdis-print-bytes")) aoqi@0: _print_bytes = !_print_bytes; aoqi@0: } aoqi@0: if (strstr(options(), "help")) { aoqi@0: tty->print_cr("PrintAssemblyOptions help:"); aoqi@0: tty->print_cr(" hsdis-print-raw test plugin by requesting raw output"); aoqi@0: tty->print_cr(" hsdis-print-raw-xml test plugin by requesting raw xml"); aoqi@0: tty->print_cr(" hsdis-print-pc turn off PC printing (on by default)"); aoqi@0: tty->print_cr(" hsdis-print-bytes turn on instruction byte output"); aoqi@0: tty->print_cr("combined options: %s", options()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: address decode_env::handle_event(const char* event, address arg) { aoqi@0: if (match(event, "insn")) { aoqi@0: start_insn(arg); aoqi@0: } else if (match(event, "/insn")) { aoqi@0: end_insn(arg); aoqi@0: } else if (match(event, "addr")) { aoqi@0: if (arg != NULL) { aoqi@0: print_address(arg); aoqi@0: return arg; aoqi@0: } aoqi@0: } else if (match(event, "mach")) { aoqi@0: static char buffer[32] = { 0, }; aoqi@0: if (strcmp(buffer, (const char*)arg) != 0 || aoqi@0: strlen((const char*)arg) > sizeof(buffer) - 1) { aoqi@0: // Only print this when the mach changes aoqi@0: strncpy(buffer, (const char*)arg, sizeof(buffer) - 1); aoqi@0: output()->print_cr("[Disassembling for mach='%s']", arg); aoqi@0: } aoqi@0: } else if (match(event, "format bytes-per-line")) { aoqi@0: _bytes_per_line = (int) (intptr_t) arg; aoqi@0: } else { aoqi@0: // ignore unrecognized markup aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // called by the disassembler to print out jump targets and data addresses aoqi@0: void decode_env::print_address(address adr) { aoqi@0: outputStream* st = _output; aoqi@0: aoqi@0: if (adr == NULL) { aoqi@0: st->print("NULL"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: int small_num = (int)(intptr_t)adr; aoqi@0: if ((intptr_t)adr == (intptr_t)small_num aoqi@0: && -1 <= small_num && small_num <= 9) { aoqi@0: st->print("%d", small_num); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (Universe::is_fully_initialized()) { aoqi@0: if (StubRoutines::contains(adr)) { aoqi@0: StubCodeDesc* desc = StubCodeDesc::desc_for(adr); aoqi@0: if (desc == NULL) aoqi@0: desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset); aoqi@0: if (desc != NULL) { aoqi@0: st->print("Stub::%s", desc->name()); aoqi@0: if (desc->begin() != adr) aoqi@0: st->print("%+d 0x%p",adr - desc->begin(), adr); aoqi@0: else if (WizardMode) st->print(" " PTR_FORMAT, adr); aoqi@0: return; aoqi@0: } aoqi@0: st->print("Stub:: " PTR_FORMAT, adr); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: BarrierSet* bs = Universe::heap()->barrier_set(); aoqi@0: if (bs->kind() == BarrierSet::CardTableModRef && aoqi@0: adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) { aoqi@0: st->print("word_map_base"); aoqi@0: if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: oop obj; aoqi@0: if (_nm != NULL aoqi@0: && (obj = _nm->embeddedOop_at(cur_insn())) != NULL aoqi@0: && (address) obj == adr aoqi@0: && Universe::heap()->is_in(obj) aoqi@0: && Universe::heap()->is_in(obj->klass())) { aoqi@0: julong c = st->count(); aoqi@0: obj->print_value_on(st); aoqi@0: if (st->count() == c) { aoqi@0: // No output. (Can happen in product builds.) aoqi@0: st->print("(a %s)", obj->klass()->external_name()); aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Fall through to a simple (hexadecimal) numeral. aoqi@0: st->print(PTR_FORMAT, adr); aoqi@0: } aoqi@0: aoqi@0: void decode_env::print_insn_labels() { aoqi@0: address p = cur_insn(); aoqi@0: outputStream* st = output(); aoqi@0: CodeBlob* cb = _code; aoqi@0: if (cb != NULL) { aoqi@0: cb->print_block_comment(st, p); aoqi@0: } aoqi@0: _strings.print_block_comment(st, (intptr_t)(p - _start)); aoqi@0: if (_print_pc) { aoqi@0: st->print(" " PTR_FORMAT ": ", p); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void decode_env::print_insn_bytes(address pc, address pc_limit) { aoqi@0: outputStream* st = output(); aoqi@0: size_t incr = 1; aoqi@0: size_t perline = _bytes_per_line; aoqi@0: if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int) aoqi@0: && !((uintptr_t)pc % sizeof(int)) aoqi@0: && !((uintptr_t)pc_limit % sizeof(int))) { aoqi@0: incr = sizeof(int); aoqi@0: if (perline % incr) perline += incr - (perline % incr); aoqi@0: } aoqi@0: while (pc < pc_limit) { aoqi@0: // tab to the desired column: aoqi@0: st->move_to(COMMENT_COLUMN); aoqi@0: address pc0 = pc; aoqi@0: address pc1 = pc + perline; aoqi@0: if (pc1 > pc_limit) pc1 = pc_limit; aoqi@0: for (; pc < pc1; pc += incr) { aoqi@0: if (pc == pc0) aoqi@0: st->print(BYTES_COMMENT); aoqi@0: else if ((uint)(pc - pc0) % sizeof(int) == 0) aoqi@0: st->print(" "); // put out a space on word boundaries aoqi@0: if (incr == sizeof(int)) aoqi@0: st->print("%08lx", *(int*)pc); aoqi@0: else st->print("%02x", (*pc)&0xFF); aoqi@0: } aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static void* event_to_env(void* env_pv, const char* event, void* arg) { aoqi@0: decode_env* env = (decode_env*) env_pv; aoqi@0: return env->handle_event(event, (address) arg); aoqi@0: } aoqi@0: aoqi@0: ATTRIBUTE_PRINTF(2, 3) aoqi@0: static int printf_to_env(void* env_pv, const char* format, ...) { aoqi@0: decode_env* env = (decode_env*) env_pv; aoqi@0: outputStream* st = env->output(); aoqi@0: size_t flen = strlen(format); aoqi@0: const char* raw = NULL; aoqi@0: if (flen == 0) return 0; aoqi@0: if (flen == 1 && format[0] == '\n') { st->bol(); return 1; } aoqi@0: if (flen < 2 || aoqi@0: strchr(format, '%') == NULL) { aoqi@0: raw = format; aoqi@0: } else if (format[0] == '%' && format[1] == '%' && aoqi@0: strchr(format+2, '%') == NULL) { aoqi@0: // happens a lot on machines with names like %foo aoqi@0: flen--; aoqi@0: raw = format+1; aoqi@0: } aoqi@0: if (raw != NULL) { aoqi@0: st->print_raw(raw, (int) flen); aoqi@0: return (int) flen; aoqi@0: } aoqi@0: va_list ap; aoqi@0: va_start(ap, format); aoqi@0: julong cnt0 = st->count(); aoqi@0: st->vprint(format, ap); aoqi@0: julong cnt1 = st->count(); aoqi@0: va_end(ap); aoqi@0: return (int)(cnt1 - cnt0); aoqi@0: } aoqi@0: aoqi@0: address decode_env::decode_instructions(address start, address end) { aoqi@0: _start = start; _end = end; aoqi@0: aoqi@0: assert(((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment()) == 0), "misaligned insn addr"); aoqi@0: aoqi@0: const int show_bytes = false; // for disassembler debugging aoqi@0: aoqi@0: //_version = Disassembler::pd_cpu_version(); aoqi@0: aoqi@0: if (!Disassembler::can_decode()) { aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // decode a series of instructions and return the end of the last instruction aoqi@0: aoqi@0: if (_print_raw) { aoqi@0: // Print whatever the library wants to print, w/o fancy callbacks. aoqi@0: // This is mainly for debugging the library itself. aoqi@0: FILE* out = stdout; aoqi@0: FILE* xmlout = (_print_raw > 1 ? out : NULL); aoqi@0: return use_new_version ? aoqi@0: (address) aoqi@0: (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end, aoqi@0: start, end - start, aoqi@0: NULL, (void*) xmlout, aoqi@0: NULL, (void*) out, aoqi@0: options(), 0/*nice new line*/) aoqi@0: : aoqi@0: (address) aoqi@0: (*Disassembler::_decode_instructions)(start, end, aoqi@0: NULL, (void*) xmlout, aoqi@0: NULL, (void*) out, aoqi@0: options()); aoqi@0: } aoqi@0: aoqi@0: return use_new_version ? aoqi@0: (address) aoqi@0: (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end, aoqi@0: start, end - start, aoqi@0: &event_to_env, (void*) this, aoqi@0: &printf_to_env, (void*) this, aoqi@0: options(), 0/*nice new line*/) aoqi@0: : aoqi@0: (address) aoqi@0: (*Disassembler::_decode_instructions)(start, end, aoqi@0: &event_to_env, (void*) this, aoqi@0: &printf_to_env, (void*) this, aoqi@0: options()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Disassembler::decode(CodeBlob* cb, outputStream* st) { aoqi@0: if (!load_library()) return; aoqi@0: decode_env env(cb, st); aoqi@0: env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb); aoqi@0: env.decode_instructions(cb->code_begin(), cb->code_end()); aoqi@0: } aoqi@0: aoqi@0: void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) { aoqi@0: if (!load_library()) return; aoqi@0: decode_env env(CodeCache::find_blob_unsafe(start), st, c); aoqi@0: env.decode_instructions(start, end); aoqi@0: } aoqi@0: aoqi@0: void Disassembler::decode(nmethod* nm, outputStream* st) { aoqi@0: if (!load_library()) return; aoqi@0: decode_env env(nm, st); aoqi@0: env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm); aoqi@0: env.output()->print_cr("Code:"); aoqi@0: aoqi@0: #ifdef SHARK aoqi@0: SharkEntry* entry = (SharkEntry *) nm->code_begin(); aoqi@0: unsigned char* p = entry->code_start(); aoqi@0: unsigned char* end = entry->code_limit(); aoqi@0: #else aoqi@0: unsigned char* p = nm->code_begin(); aoqi@0: unsigned char* end = nm->code_end(); aoqi@0: #endif // SHARK aoqi@0: aoqi@0: // If there has been profiling, print the buckets. aoqi@0: if (FlatProfiler::bucket_start_for(p) != NULL) { aoqi@0: unsigned char* p1 = p; aoqi@0: int total_bucket_count = 0; aoqi@0: while (p1 < end) { aoqi@0: unsigned char* p0 = p1; aoqi@0: p1 += pd_instruction_alignment(); aoqi@0: address bucket_pc = FlatProfiler::bucket_start_for(p1); aoqi@0: if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1) aoqi@0: total_bucket_count += FlatProfiler::bucket_count_for(p0); aoqi@0: } aoqi@0: env.set_total_ticks(total_bucket_count); aoqi@0: } aoqi@0: aoqi@0: // Print constant table. aoqi@0: if (nm->consts_size() > 0) { aoqi@0: nm->print_nmethod_labels(env.output(), nm->consts_begin()); aoqi@0: int offset = 0; aoqi@0: for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) { aoqi@0: if ((offset % 8) == 0) { aoqi@0: env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p, offset, *((int32_t*) p), *((int64_t*) p)); aoqi@0: } else { aoqi@0: env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p, offset, *((int32_t*) p)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: env.decode_instructions(p, end); aoqi@0: }