Thu, 19 Mar 2009 09:13:24 -0700
Merge
jrose@535 | 1 | /* |
jrose@535 | 2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
jrose@535 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jrose@535 | 4 | * |
jrose@535 | 5 | * This code is free software; you can redistribute it and/or modify it |
jrose@535 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jrose@535 | 7 | * published by the Free Software Foundation. |
jrose@535 | 8 | * |
jrose@535 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jrose@535 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jrose@535 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jrose@535 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jrose@535 | 13 | * accompanied this code). |
jrose@535 | 14 | * |
jrose@535 | 15 | * You should have received a copy of the GNU General Public License version |
jrose@535 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jrose@535 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jrose@535 | 18 | * |
jrose@535 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
jrose@535 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
jrose@535 | 21 | * have any questions. |
jrose@535 | 22 | * |
jrose@535 | 23 | */ |
jrose@535 | 24 | |
jrose@535 | 25 | # include "incls/_precompiled.incl" |
jrose@535 | 26 | # include "incls/_disassembler.cpp.incl" |
jrose@535 | 27 | |
jrose@535 | 28 | void* Disassembler::_library = NULL; |
jrose@535 | 29 | bool Disassembler::_tried_to_load_library = false; |
jrose@535 | 30 | |
jrose@535 | 31 | // This routine is in the shared library: |
jrose@535 | 32 | Disassembler::decode_func Disassembler::_decode_instructions = NULL; |
jrose@535 | 33 | |
jrose@535 | 34 | static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH; |
jrose@535 | 35 | static const char decode_instructions_name[] = "decode_instructions"; |
jrose@535 | 36 | |
jrose@535 | 37 | #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/ |
jrose@535 | 38 | #define BYTES_COMMENT ";..." /* funky byte display comment */ |
jrose@535 | 39 | |
jrose@535 | 40 | bool Disassembler::load_library() { |
jrose@535 | 41 | if (_decode_instructions != NULL) { |
jrose@535 | 42 | // Already succeeded. |
jrose@535 | 43 | return true; |
jrose@535 | 44 | } |
jrose@535 | 45 | if (_tried_to_load_library) { |
jrose@535 | 46 | // Do not try twice. |
jrose@535 | 47 | // To force retry in debugger: assign _tried_to_load_library=0 |
jrose@535 | 48 | return false; |
jrose@535 | 49 | } |
jrose@535 | 50 | // Try to load it. |
jrose@535 | 51 | char ebuf[1024]; |
jrose@535 | 52 | char buf[JVM_MAXPATHLEN]; |
jrose@535 | 53 | os::jvm_path(buf, sizeof(buf)); |
jrose@535 | 54 | int jvm_offset = -1; |
jrose@535 | 55 | { |
jrose@535 | 56 | // Match "jvm[^/]*" in jvm_path. |
jrose@535 | 57 | const char* base = buf; |
jrose@535 | 58 | const char* p = strrchr(buf, '/'); |
jrose@535 | 59 | p = strstr(p ? p : base, "jvm"); |
jrose@535 | 60 | if (p != NULL) jvm_offset = p - base; |
jrose@535 | 61 | } |
jrose@535 | 62 | if (jvm_offset >= 0) { |
jrose@535 | 63 | // Find the disassembler next to libjvm.so. |
jrose@535 | 64 | strcpy(&buf[jvm_offset], hsdis_library_name); |
jrose@535 | 65 | strcat(&buf[jvm_offset], os::dll_file_extension()); |
jrose@535 | 66 | _library = hpi::dll_load(buf, ebuf, sizeof ebuf); |
jrose@535 | 67 | } |
jrose@535 | 68 | if (_library == NULL) { |
jrose@535 | 69 | // Try a free-floating lookup. |
jrose@535 | 70 | strcpy(&buf[0], hsdis_library_name); |
jrose@535 | 71 | strcat(&buf[0], os::dll_file_extension()); |
jrose@535 | 72 | _library = hpi::dll_load(buf, ebuf, sizeof ebuf); |
jrose@535 | 73 | } |
jrose@535 | 74 | if (_library != NULL) { |
jrose@535 | 75 | _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, |
jrose@535 | 76 | hpi::dll_lookup(_library, decode_instructions_name)); |
jrose@535 | 77 | } |
jrose@535 | 78 | _tried_to_load_library = true; |
jrose@535 | 79 | if (_decode_instructions == NULL) { |
jrose@535 | 80 | tty->print_cr("Could not load %s; %s; %s", buf, |
jrose@535 | 81 | ((_library != NULL) |
jrose@535 | 82 | ? "entry point is missing" |
jrose@535 | 83 | : (WizardMode || PrintMiscellaneous) |
jrose@535 | 84 | ? (const char*)ebuf |
jrose@535 | 85 | : "library not loadable"), |
jrose@535 | 86 | "PrintAssembly is disabled"); |
jrose@535 | 87 | return false; |
jrose@535 | 88 | } |
jrose@535 | 89 | |
jrose@535 | 90 | // Success. |
jrose@535 | 91 | tty->print_cr("Loaded disassembler from %s", buf); |
jrose@535 | 92 | return true; |
jrose@535 | 93 | } |
jrose@535 | 94 | |
jrose@535 | 95 | |
jrose@535 | 96 | class decode_env { |
jrose@535 | 97 | private: |
jrose@535 | 98 | nmethod* _nm; |
jrose@535 | 99 | CodeBlob* _code; |
jrose@535 | 100 | outputStream* _output; |
jrose@535 | 101 | address _start, _end; |
jrose@535 | 102 | |
jrose@535 | 103 | char _option_buf[512]; |
jrose@535 | 104 | char _print_raw; |
jrose@535 | 105 | bool _print_pc; |
jrose@535 | 106 | bool _print_bytes; |
jrose@535 | 107 | address _cur_insn; |
jrose@535 | 108 | int _total_ticks; |
jrose@535 | 109 | int _bytes_per_line; // arch-specific formatting option |
jrose@535 | 110 | |
jrose@535 | 111 | static bool match(const char* event, const char* tag) { |
jrose@535 | 112 | size_t taglen = strlen(tag); |
jrose@535 | 113 | if (strncmp(event, tag, taglen) != 0) |
jrose@535 | 114 | return false; |
jrose@535 | 115 | char delim = event[taglen]; |
jrose@535 | 116 | return delim == '\0' || delim == ' ' || delim == '/' || delim == '='; |
jrose@535 | 117 | } |
jrose@535 | 118 | |
jrose@535 | 119 | void collect_options(const char* p) { |
jrose@535 | 120 | if (p == NULL || p[0] == '\0') return; |
jrose@535 | 121 | size_t opt_so_far = strlen(_option_buf); |
jrose@535 | 122 | if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf)) return; |
jrose@535 | 123 | char* fillp = &_option_buf[opt_so_far]; |
jrose@535 | 124 | if (opt_so_far > 0) *fillp++ = ','; |
jrose@535 | 125 | strcat(fillp, p); |
jrose@535 | 126 | // replace white space by commas: |
jrose@535 | 127 | char* q = fillp; |
jrose@535 | 128 | while ((q = strpbrk(q, " \t\n")) != NULL) |
jrose@535 | 129 | *q++ = ','; |
jrose@535 | 130 | // Note that multiple PrintAssemblyOptions flags accumulate with \n, |
jrose@535 | 131 | // which we want to be changed to a comma... |
jrose@535 | 132 | } |
jrose@535 | 133 | |
jrose@535 | 134 | void print_insn_labels(); |
jrose@535 | 135 | void print_insn_bytes(address pc0, address pc); |
jrose@535 | 136 | void print_address(address value); |
jrose@535 | 137 | |
jrose@535 | 138 | public: |
jrose@535 | 139 | decode_env(CodeBlob* code, outputStream* output); |
jrose@535 | 140 | |
jrose@535 | 141 | address decode_instructions(address start, address end); |
jrose@535 | 142 | |
jrose@535 | 143 | void start_insn(address pc) { |
jrose@535 | 144 | _cur_insn = pc; |
jrose@535 | 145 | output()->bol(); |
jrose@535 | 146 | print_insn_labels(); |
jrose@535 | 147 | } |
jrose@535 | 148 | |
jrose@535 | 149 | void end_insn(address pc) { |
jrose@535 | 150 | address pc0 = cur_insn(); |
jrose@535 | 151 | outputStream* st = output(); |
jrose@535 | 152 | if (_print_bytes && pc > pc0) |
jrose@535 | 153 | print_insn_bytes(pc0, pc); |
jrose@535 | 154 | if (_nm != NULL) |
jrose@535 | 155 | _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc); |
jrose@535 | 156 | |
jrose@535 | 157 | // Output pc bucket ticks if we have any |
jrose@535 | 158 | if (total_ticks() != 0) { |
jrose@535 | 159 | address bucket_pc = FlatProfiler::bucket_start_for(pc); |
jrose@535 | 160 | if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) { |
jrose@535 | 161 | int bucket_count = FlatProfiler::bucket_count_for(pc0); |
jrose@535 | 162 | if (bucket_count != 0) { |
jrose@535 | 163 | st->bol(); |
jrose@535 | 164 | st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count); |
jrose@535 | 165 | } |
jrose@535 | 166 | } |
jrose@535 | 167 | } |
jrose@535 | 168 | } |
jrose@535 | 169 | |
jrose@535 | 170 | address handle_event(const char* event, address arg); |
jrose@535 | 171 | |
jrose@535 | 172 | outputStream* output() { return _output; } |
jrose@535 | 173 | address cur_insn() { return _cur_insn; } |
jrose@535 | 174 | int total_ticks() { return _total_ticks; } |
jrose@535 | 175 | void set_total_ticks(int n) { _total_ticks = n; } |
jrose@535 | 176 | const char* options() { return _option_buf; } |
jrose@535 | 177 | }; |
jrose@535 | 178 | |
jrose@535 | 179 | decode_env::decode_env(CodeBlob* code, outputStream* output) { |
jrose@535 | 180 | memset(this, 0, sizeof(*this)); |
jrose@535 | 181 | _output = output ? output : tty; |
jrose@535 | 182 | _code = code; |
jrose@535 | 183 | if (code != NULL && code->is_nmethod()) |
jrose@535 | 184 | _nm = (nmethod*) code; |
jrose@535 | 185 | |
jrose@535 | 186 | // by default, output pc but not bytes: |
jrose@535 | 187 | _print_pc = true; |
jrose@535 | 188 | _print_bytes = false; |
jrose@535 | 189 | _bytes_per_line = Disassembler::pd_instruction_alignment(); |
jrose@535 | 190 | |
jrose@535 | 191 | // parse the global option string: |
jrose@535 | 192 | collect_options(Disassembler::pd_cpu_opts()); |
jrose@535 | 193 | collect_options(PrintAssemblyOptions); |
jrose@535 | 194 | |
jrose@535 | 195 | if (strstr(options(), "hsdis-")) { |
jrose@535 | 196 | if (strstr(options(), "hsdis-print-raw")) |
jrose@535 | 197 | _print_raw = (strstr(options(), "xml") ? 2 : 1); |
jrose@535 | 198 | if (strstr(options(), "hsdis-print-pc")) |
jrose@535 | 199 | _print_pc = !_print_pc; |
jrose@535 | 200 | if (strstr(options(), "hsdis-print-bytes")) |
jrose@535 | 201 | _print_bytes = !_print_bytes; |
jrose@535 | 202 | } |
jrose@535 | 203 | if (strstr(options(), "help")) { |
jrose@535 | 204 | tty->print_cr("PrintAssemblyOptions help:"); |
jrose@535 | 205 | tty->print_cr(" hsdis-print-raw test plugin by requesting raw output"); |
jrose@535 | 206 | tty->print_cr(" hsdis-print-raw-xml test plugin by requesting raw xml"); |
jrose@535 | 207 | tty->print_cr(" hsdis-print-pc turn off PC printing (on by default)"); |
jrose@535 | 208 | tty->print_cr(" hsdis-print-bytes turn on instruction byte output"); |
jrose@535 | 209 | tty->print_cr("combined options: %s", options()); |
jrose@535 | 210 | } |
jrose@535 | 211 | } |
jrose@535 | 212 | |
jrose@535 | 213 | address decode_env::handle_event(const char* event, address arg) { |
jrose@535 | 214 | if (match(event, "insn")) { |
jrose@535 | 215 | start_insn(arg); |
jrose@535 | 216 | } else if (match(event, "/insn")) { |
jrose@535 | 217 | end_insn(arg); |
jrose@535 | 218 | } else if (match(event, "addr")) { |
jrose@535 | 219 | if (arg != NULL) { |
jrose@535 | 220 | print_address(arg); |
jrose@535 | 221 | return arg; |
jrose@535 | 222 | } |
jrose@535 | 223 | } else if (match(event, "mach")) { |
jrose@535 | 224 | output()->print_cr("[Disassembling for mach='%s']", arg); |
jrose@535 | 225 | } else if (match(event, "format bytes-per-line")) { |
jrose@535 | 226 | _bytes_per_line = (int) (intptr_t) arg; |
jrose@535 | 227 | } else { |
jrose@535 | 228 | // ignore unrecognized markup |
jrose@535 | 229 | } |
jrose@535 | 230 | return NULL; |
jrose@535 | 231 | } |
jrose@535 | 232 | |
jrose@535 | 233 | // called by the disassembler to print out jump targets and data addresses |
jrose@535 | 234 | void decode_env::print_address(address adr) { |
jrose@535 | 235 | outputStream* st = _output; |
jrose@535 | 236 | |
jrose@535 | 237 | if (adr == NULL) { |
jrose@535 | 238 | st->print("NULL"); |
jrose@535 | 239 | return; |
jrose@535 | 240 | } |
jrose@535 | 241 | |
jrose@535 | 242 | int small_num = (int)(intptr_t)adr; |
jrose@535 | 243 | if ((intptr_t)adr == (intptr_t)small_num |
jrose@535 | 244 | && -1 <= small_num && small_num <= 9) { |
jrose@535 | 245 | st->print("%d", small_num); |
jrose@535 | 246 | return; |
jrose@535 | 247 | } |
jrose@535 | 248 | |
jrose@535 | 249 | if (Universe::is_fully_initialized()) { |
jrose@535 | 250 | if (StubRoutines::contains(adr)) { |
jrose@535 | 251 | StubCodeDesc* desc = StubCodeDesc::desc_for(adr); |
jrose@535 | 252 | if (desc == NULL) |
jrose@535 | 253 | desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset); |
jrose@535 | 254 | if (desc != NULL) { |
jrose@535 | 255 | st->print("Stub::%s", desc->name()); |
jrose@535 | 256 | if (desc->begin() != adr) |
jrose@535 | 257 | st->print("%+d 0x%p",adr - desc->begin(), adr); |
jrose@535 | 258 | else if (WizardMode) st->print(" " INTPTR_FORMAT, adr); |
jrose@535 | 259 | return; |
jrose@535 | 260 | } |
jrose@535 | 261 | st->print("Stub::<unknown> " INTPTR_FORMAT, adr); |
jrose@535 | 262 | return; |
jrose@535 | 263 | } |
jrose@535 | 264 | |
jrose@535 | 265 | BarrierSet* bs = Universe::heap()->barrier_set(); |
jrose@535 | 266 | if (bs->kind() == BarrierSet::CardTableModRef && |
jrose@535 | 267 | adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) { |
jrose@535 | 268 | st->print("word_map_base"); |
jrose@535 | 269 | if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr); |
jrose@535 | 270 | return; |
jrose@535 | 271 | } |
jrose@535 | 272 | |
jrose@535 | 273 | oop obj; |
jrose@535 | 274 | if (_nm != NULL |
jrose@535 | 275 | && (obj = _nm->embeddedOop_at(cur_insn())) != NULL |
jrose@535 | 276 | && (address) obj == adr) { |
jrose@535 | 277 | obj->print_value_on(st); |
jrose@535 | 278 | return; |
jrose@535 | 279 | } |
jrose@535 | 280 | } |
jrose@535 | 281 | |
jrose@535 | 282 | // Fall through to a simple numeral. |
jrose@535 | 283 | st->print(INTPTR_FORMAT, (intptr_t)adr); |
jrose@535 | 284 | } |
jrose@535 | 285 | |
jrose@535 | 286 | void decode_env::print_insn_labels() { |
jrose@535 | 287 | address p = cur_insn(); |
jrose@535 | 288 | outputStream* st = output(); |
jrose@535 | 289 | nmethod* nm = _nm; |
jrose@535 | 290 | if (nm != NULL) { |
jrose@535 | 291 | if (p == nm->entry_point()) st->print_cr("[Entry Point]"); |
jrose@535 | 292 | if (p == nm->verified_entry_point()) st->print_cr("[Verified Entry Point]"); |
jrose@535 | 293 | if (p == nm->exception_begin()) st->print_cr("[Exception Handler]"); |
jrose@535 | 294 | if (p == nm->stub_begin()) st->print_cr("[Stub Code]"); |
jrose@535 | 295 | if (p == nm->consts_begin()) st->print_cr("[Constants]"); |
jrose@535 | 296 | } |
jrose@535 | 297 | CodeBlob* cb = _code; |
jrose@535 | 298 | if (cb != NULL) { |
jrose@535 | 299 | cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin())); |
jrose@535 | 300 | } |
jrose@535 | 301 | if (_print_pc) { |
jrose@535 | 302 | st->print(" " INTPTR_FORMAT ": ", (intptr_t) p); |
jrose@535 | 303 | } |
jrose@535 | 304 | } |
jrose@535 | 305 | |
jrose@535 | 306 | void decode_env::print_insn_bytes(address pc, address pc_limit) { |
jrose@535 | 307 | outputStream* st = output(); |
jrose@535 | 308 | size_t incr = 1; |
jrose@535 | 309 | size_t perline = _bytes_per_line; |
jrose@535 | 310 | if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int) |
jrose@535 | 311 | && !((uintptr_t)pc % sizeof(int)) |
jrose@535 | 312 | && !((uintptr_t)pc_limit % sizeof(int))) { |
jrose@535 | 313 | incr = sizeof(int); |
jrose@535 | 314 | if (perline % incr) perline += incr - (perline % incr); |
jrose@535 | 315 | } |
jrose@535 | 316 | while (pc < pc_limit) { |
jrose@535 | 317 | // tab to the desired column: |
jrose@535 | 318 | st->move_to(COMMENT_COLUMN); |
jrose@535 | 319 | address pc0 = pc; |
jrose@535 | 320 | address pc1 = pc + perline; |
jrose@535 | 321 | if (pc1 > pc_limit) pc1 = pc_limit; |
jrose@535 | 322 | for (; pc < pc1; pc += incr) { |
jrose@535 | 323 | if (pc == pc0) |
jrose@535 | 324 | st->print(BYTES_COMMENT); |
jrose@535 | 325 | else if ((uint)(pc - pc0) % sizeof(int) == 0) |
jrose@535 | 326 | st->print(" "); // put out a space on word boundaries |
jrose@535 | 327 | if (incr == sizeof(int)) |
jrose@535 | 328 | st->print("%08lx", *(int*)pc); |
jrose@535 | 329 | else st->print("%02x", (*pc)&0xFF); |
jrose@535 | 330 | } |
jrose@535 | 331 | st->cr(); |
jrose@535 | 332 | } |
jrose@535 | 333 | } |
jrose@535 | 334 | |
jrose@535 | 335 | |
jrose@535 | 336 | static void* event_to_env(void* env_pv, const char* event, void* arg) { |
jrose@535 | 337 | decode_env* env = (decode_env*) env_pv; |
jrose@535 | 338 | return env->handle_event(event, (address) arg); |
jrose@535 | 339 | } |
jrose@535 | 340 | |
jrose@535 | 341 | static int printf_to_env(void* env_pv, const char* format, ...) { |
jrose@535 | 342 | decode_env* env = (decode_env*) env_pv; |
jrose@535 | 343 | outputStream* st = env->output(); |
jrose@535 | 344 | size_t flen = strlen(format); |
jrose@535 | 345 | const char* raw = NULL; |
jrose@535 | 346 | if (flen == 0) return 0; |
jrose@535 | 347 | if (flen == 1 && format[0] == '\n') { st->bol(); return 1; } |
jrose@535 | 348 | if (flen < 2 || |
jrose@535 | 349 | strchr(format, '%') == NULL) { |
jrose@535 | 350 | raw = format; |
jrose@535 | 351 | } else if (format[0] == '%' && format[1] == '%' && |
jrose@535 | 352 | strchr(format+2, '%') == NULL) { |
jrose@535 | 353 | // happens a lot on machines with names like %foo |
jrose@535 | 354 | flen--; |
jrose@535 | 355 | raw = format+1; |
jrose@535 | 356 | } |
jrose@535 | 357 | if (raw != NULL) { |
jrose@535 | 358 | st->print_raw(raw, (int) flen); |
jrose@535 | 359 | return (int) flen; |
jrose@535 | 360 | } |
jrose@535 | 361 | va_list ap; |
jrose@535 | 362 | va_start(ap, format); |
jrose@535 | 363 | julong cnt0 = st->count(); |
jrose@535 | 364 | st->vprint(format, ap); |
jrose@535 | 365 | julong cnt1 = st->count(); |
jrose@535 | 366 | va_end(ap); |
jrose@535 | 367 | return (int)(cnt1 - cnt0); |
jrose@535 | 368 | } |
jrose@535 | 369 | |
jrose@535 | 370 | address decode_env::decode_instructions(address start, address end) { |
jrose@535 | 371 | _start = start; _end = end; |
jrose@535 | 372 | |
jrose@535 | 373 | assert((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment() == 0), "misaligned insn addr"); |
jrose@535 | 374 | |
jrose@535 | 375 | const int show_bytes = false; // for disassembler debugging |
jrose@535 | 376 | |
jrose@535 | 377 | //_version = Disassembler::pd_cpu_version(); |
jrose@535 | 378 | |
jrose@535 | 379 | if (!Disassembler::can_decode()) { |
jrose@535 | 380 | return NULL; |
jrose@535 | 381 | } |
jrose@535 | 382 | |
jrose@535 | 383 | // decode a series of instructions and return the end of the last instruction |
jrose@535 | 384 | |
jrose@535 | 385 | if (_print_raw) { |
jrose@535 | 386 | // Print whatever the library wants to print, w/o fancy callbacks. |
jrose@535 | 387 | // This is mainly for debugging the library itself. |
jrose@535 | 388 | FILE* out = stdout; |
jrose@535 | 389 | FILE* xmlout = (_print_raw > 1 ? out : NULL); |
jrose@535 | 390 | return (address) |
jrose@535 | 391 | (*Disassembler::_decode_instructions)(start, end, |
jrose@535 | 392 | NULL, (void*) xmlout, |
jrose@535 | 393 | NULL, (void*) out, |
jrose@535 | 394 | options()); |
jrose@535 | 395 | } |
jrose@535 | 396 | |
jrose@535 | 397 | return (address) |
jrose@535 | 398 | (*Disassembler::_decode_instructions)(start, end, |
jrose@535 | 399 | &event_to_env, (void*) this, |
jrose@535 | 400 | &printf_to_env, (void*) this, |
jrose@535 | 401 | options()); |
jrose@535 | 402 | } |
jrose@535 | 403 | |
jrose@535 | 404 | |
jrose@535 | 405 | void Disassembler::decode(CodeBlob* cb, outputStream* st) { |
jrose@535 | 406 | if (!load_library()) return; |
jrose@535 | 407 | decode_env env(cb, st); |
jrose@535 | 408 | env.output()->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb); |
jrose@535 | 409 | env.decode_instructions(cb->instructions_begin(), cb->instructions_end()); |
jrose@535 | 410 | } |
jrose@535 | 411 | |
jrose@535 | 412 | |
jrose@535 | 413 | void Disassembler::decode(address start, address end, outputStream* st) { |
jrose@535 | 414 | if (!load_library()) return; |
jrose@535 | 415 | decode_env env(CodeCache::find_blob_unsafe(start), st); |
jrose@535 | 416 | env.decode_instructions(start, end); |
jrose@535 | 417 | } |
jrose@535 | 418 | |
jrose@535 | 419 | void Disassembler::decode(nmethod* nm, outputStream* st) { |
jrose@535 | 420 | if (!load_library()) return; |
jrose@535 | 421 | decode_env env(nm, st); |
jrose@535 | 422 | env.output()->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm); |
jrose@535 | 423 | env.output()->print_cr("Code:"); |
jrose@535 | 424 | |
jrose@535 | 425 | unsigned char* p = nm->instructions_begin(); |
jrose@535 | 426 | unsigned char* end = nm->instructions_end(); |
jrose@535 | 427 | |
jrose@535 | 428 | // If there has been profiling, print the buckets. |
jrose@535 | 429 | if (FlatProfiler::bucket_start_for(p) != NULL) { |
jrose@535 | 430 | unsigned char* p1 = p; |
jrose@535 | 431 | int total_bucket_count = 0; |
jrose@535 | 432 | while (p1 < end) { |
jrose@535 | 433 | unsigned char* p0 = p1; |
jrose@535 | 434 | p1 += pd_instruction_alignment(); |
jrose@535 | 435 | address bucket_pc = FlatProfiler::bucket_start_for(p1); |
jrose@535 | 436 | if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1) |
jrose@535 | 437 | total_bucket_count += FlatProfiler::bucket_count_for(p0); |
jrose@535 | 438 | } |
jrose@535 | 439 | env.set_total_ticks(total_bucket_count); |
jrose@535 | 440 | } |
jrose@535 | 441 | |
jrose@535 | 442 | env.decode_instructions(p, end); |
jrose@535 | 443 | } |