src/share/vm/compiler/disassembler.cpp

Tue, 25 Aug 2020 13:30:02 +0200

author
rkennke
date
Tue, 25 Aug 2020 13:30:02 +0200
changeset 10000
4b0aa85a9565
parent 9920
3a3803a0c789
child 10003
a0eb08e2db5a
permissions
-rw-r--r--

8222079: Don't use memset to initialize fields decode_env constructor in disassembler.cpp
Reviewed-by: zgu, andrew

jrose@535 1 /*
drchase@6680 2 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
jrose@535 22 *
jrose@535 23 */
jrose@535 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/javaClasses.hpp"
stefank@2314 27 #include "code/codeCache.hpp"
stefank@2314 28 #include "compiler/disassembler.hpp"
stefank@2314 29 #include "gc_interface/collectedHeap.hpp"
stefank@2314 30 #include "memory/cardTableModRefBS.hpp"
stefank@2314 31 #include "runtime/fprofiler.hpp"
stefank@2314 32 #include "runtime/handles.inline.hpp"
stefank@2314 33 #include "runtime/stubCodeGenerator.hpp"
stefank@2314 34 #include "runtime/stubRoutines.hpp"
stefank@2314 35 #ifdef TARGET_ARCH_x86
stefank@2314 36 # include "depChecker_x86.hpp"
stefank@2314 37 #endif
stefank@2314 38 #ifdef TARGET_ARCH_sparc
stefank@2314 39 # include "depChecker_sparc.hpp"
stefank@2314 40 #endif
stefank@2314 41 #ifdef TARGET_ARCH_zero
stefank@2314 42 # include "depChecker_zero.hpp"
stefank@2314 43 #endif
bobv@2508 44 #ifdef TARGET_ARCH_arm
bobv@2508 45 # include "depChecker_arm.hpp"
bobv@2508 46 #endif
bobv@2508 47 #ifdef TARGET_ARCH_ppc
bobv@2508 48 # include "depChecker_ppc.hpp"
bobv@2508 49 #endif
stefank@2314 50 #ifdef SHARK
stefank@2314 51 #include "shark/sharkEntry.hpp"
stefank@2314 52 #endif
jrose@535 53
drchase@6680 54 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 55
jrose@535 56 void* Disassembler::_library = NULL;
jrose@535 57 bool Disassembler::_tried_to_load_library = false;
jrose@535 58
jrose@535 59 // This routine is in the shared library:
minqi@4244 60 Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
jrose@535 61 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
jrose@535 62
kevinw@9327 63 static const char hsdis_library_name[] = "hsdis-" HOTSPOT_LIB_ARCH;
minqi@4244 64 static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
minqi@4244 65 static const char decode_instructions_name[] = "decode_instructions";
minqi@4244 66 static bool use_new_version = true;
jrose@535 67 #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/
jrose@535 68 #define BYTES_COMMENT ";..." /* funky byte display comment */
jrose@535 69
jrose@535 70 bool Disassembler::load_library() {
minqi@4244 71 if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
jrose@535 72 // Already succeeded.
jrose@535 73 return true;
jrose@535 74 }
jrose@535 75 if (_tried_to_load_library) {
jrose@535 76 // Do not try twice.
jrose@535 77 // To force retry in debugger: assign _tried_to_load_library=0
jrose@535 78 return false;
jrose@535 79 }
jrose@535 80 // Try to load it.
jrose@535 81 char ebuf[1024];
jrose@535 82 char buf[JVM_MAXPATHLEN];
jrose@535 83 os::jvm_path(buf, sizeof(buf));
jrose@535 84 int jvm_offset = -1;
never@2991 85 int lib_offset = -1;
jrose@535 86 {
jrose@535 87 // Match "jvm[^/]*" in jvm_path.
jrose@535 88 const char* base = buf;
jrose@535 89 const char* p = strrchr(buf, '/');
never@2991 90 if (p != NULL) lib_offset = p - base + 1;
jrose@535 91 p = strstr(p ? p : base, "jvm");
jrose@535 92 if (p != NULL) jvm_offset = p - base;
jrose@535 93 }
never@2991 94 // Find the disassembler shared library.
never@2991 95 // Search for several paths derived from libjvm, in this order:
never@2991 96 // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so (for compatibility)
never@2991 97 // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
never@2991 98 // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
never@2991 99 // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
jrose@535 100 if (jvm_offset >= 0) {
never@2991 101 // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
jrose@535 102 strcpy(&buf[jvm_offset], hsdis_library_name);
jrose@535 103 strcat(&buf[jvm_offset], os::dll_file_extension());
ikrylov@2322 104 _library = os::dll_load(buf, ebuf, sizeof ebuf);
never@2991 105 if (_library == NULL) {
never@2991 106 // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
never@2991 107 strcpy(&buf[lib_offset], hsdis_library_name);
never@2991 108 strcat(&buf[lib_offset], os::dll_file_extension());
never@2991 109 _library = os::dll_load(buf, ebuf, sizeof ebuf);
never@2991 110 }
never@2991 111 if (_library == NULL) {
never@2991 112 // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
never@2991 113 buf[lib_offset - 1] = '\0';
never@2991 114 const char* p = strrchr(buf, '/');
never@2991 115 if (p != NULL) {
never@2991 116 lib_offset = p - buf + 1;
never@2991 117 strcpy(&buf[lib_offset], hsdis_library_name);
never@2991 118 strcat(&buf[lib_offset], os::dll_file_extension());
never@2991 119 _library = os::dll_load(buf, ebuf, sizeof ebuf);
never@2991 120 }
never@2991 121 }
jrose@535 122 }
jrose@535 123 if (_library == NULL) {
never@2991 124 // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
jrose@535 125 strcpy(&buf[0], hsdis_library_name);
jrose@535 126 strcat(&buf[0], os::dll_file_extension());
ikrylov@2322 127 _library = os::dll_load(buf, ebuf, sizeof ebuf);
jrose@535 128 }
jrose@535 129 if (_library != NULL) {
minqi@4244 130 _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
minqi@4244 131 os::dll_lookup(_library, decode_instructions_virtual_name));
minqi@4244 132 }
minqi@4244 133 if (_decode_instructions_virtual == NULL) {
minqi@4244 134 // could not spot in new version, try old version
jrose@535 135 _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
ikrylov@2322 136 os::dll_lookup(_library, decode_instructions_name));
minqi@4244 137 use_new_version = false;
minqi@4244 138 } else {
minqi@4244 139 use_new_version = true;
jrose@535 140 }
jrose@535 141 _tried_to_load_library = true;
minqi@4244 142 if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) {
jrose@535 143 tty->print_cr("Could not load %s; %s; %s", buf,
jrose@535 144 ((_library != NULL)
jrose@535 145 ? "entry point is missing"
jrose@535 146 : (WizardMode || PrintMiscellaneous)
jrose@535 147 ? (const char*)ebuf
jrose@535 148 : "library not loadable"),
jrose@535 149 "PrintAssembly is disabled");
jrose@535 150 return false;
jrose@535 151 }
jrose@535 152
jrose@535 153 // Success.
jrose@535 154 tty->print_cr("Loaded disassembler from %s", buf);
jrose@535 155 return true;
jrose@535 156 }
jrose@535 157
jrose@535 158
jrose@535 159 class decode_env {
jrose@535 160 private:
jrose@535 161 nmethod* _nm;
jrose@535 162 CodeBlob* _code;
roland@4767 163 CodeStrings _strings;
jrose@535 164 outputStream* _output;
jrose@535 165 address _start, _end;
jrose@535 166
jrose@535 167 char _option_buf[512];
jrose@535 168 char _print_raw;
jrose@535 169 bool _print_pc;
jrose@535 170 bool _print_bytes;
jrose@535 171 address _cur_insn;
jrose@535 172 int _total_ticks;
jrose@535 173 int _bytes_per_line; // arch-specific formatting option
jrose@535 174
jrose@535 175 static bool match(const char* event, const char* tag) {
jrose@535 176 size_t taglen = strlen(tag);
jrose@535 177 if (strncmp(event, tag, taglen) != 0)
jrose@535 178 return false;
jrose@535 179 char delim = event[taglen];
jrose@535 180 return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
jrose@535 181 }
jrose@535 182
jrose@535 183 void collect_options(const char* p) {
jrose@535 184 if (p == NULL || p[0] == '\0') return;
jrose@535 185 size_t opt_so_far = strlen(_option_buf);
jrose@535 186 if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf)) return;
jrose@535 187 char* fillp = &_option_buf[opt_so_far];
jrose@535 188 if (opt_so_far > 0) *fillp++ = ',';
jrose@535 189 strcat(fillp, p);
jrose@535 190 // replace white space by commas:
jrose@535 191 char* q = fillp;
jrose@535 192 while ((q = strpbrk(q, " \t\n")) != NULL)
jrose@535 193 *q++ = ',';
jrose@535 194 // Note that multiple PrintAssemblyOptions flags accumulate with \n,
jrose@535 195 // which we want to be changed to a comma...
jrose@535 196 }
jrose@535 197
jrose@535 198 void print_insn_labels();
jrose@535 199 void print_insn_bytes(address pc0, address pc);
jrose@535 200 void print_address(address value);
jrose@535 201
jrose@535 202 public:
roland@4767 203 decode_env(CodeBlob* code, outputStream* output, CodeStrings c = CodeStrings());
jrose@535 204
jrose@535 205 address decode_instructions(address start, address end);
jrose@535 206
jrose@535 207 void start_insn(address pc) {
jrose@535 208 _cur_insn = pc;
jrose@535 209 output()->bol();
jrose@535 210 print_insn_labels();
jrose@535 211 }
jrose@535 212
jrose@535 213 void end_insn(address pc) {
jrose@535 214 address pc0 = cur_insn();
jrose@535 215 outputStream* st = output();
jrose@535 216 if (_print_bytes && pc > pc0)
jrose@535 217 print_insn_bytes(pc0, pc);
jrose@1590 218 if (_nm != NULL) {
jrose@535 219 _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
jrose@1590 220 // this calls reloc_string_for which calls oop::print_value_on
jrose@1590 221 }
jrose@535 222
jrose@535 223 // Output pc bucket ticks if we have any
jrose@535 224 if (total_ticks() != 0) {
jrose@535 225 address bucket_pc = FlatProfiler::bucket_start_for(pc);
jrose@535 226 if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) {
jrose@535 227 int bucket_count = FlatProfiler::bucket_count_for(pc0);
jrose@535 228 if (bucket_count != 0) {
jrose@535 229 st->bol();
jrose@535 230 st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count);
jrose@535 231 }
jrose@535 232 }
jrose@535 233 }
minqi@4093 234 // follow each complete insn by a nice newline
minqi@4093 235 st->cr();
jrose@535 236 }
jrose@535 237
jrose@535 238 address handle_event(const char* event, address arg);
jrose@535 239
jrose@535 240 outputStream* output() { return _output; }
jrose@535 241 address cur_insn() { return _cur_insn; }
jrose@535 242 int total_ticks() { return _total_ticks; }
jrose@535 243 void set_total_ticks(int n) { _total_ticks = n; }
jrose@535 244 const char* options() { return _option_buf; }
jrose@535 245 };
jrose@535 246
rkennke@10000 247 decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) :
rkennke@10000 248 _nm((code != NULL && code->is_nmethod()) ? (nmethod*)code : NULL),
rkennke@10000 249 _code(code),
rkennke@10000 250 _strings(),
rkennke@10000 251 _output(output ? output : tty),
rkennke@10000 252 _start(NULL),
rkennke@10000 253 _end(NULL),
rkennke@10000 254 _option_buf(),
rkennke@10000 255 _print_raw(0),
rkennke@10000 256 // by default, output pc but not bytes:
rkennke@10000 257 _print_pc(true),
rkennke@10000 258 _print_bytes(false),
rkennke@10000 259 _cur_insn(NULL),
rkennke@10000 260 _total_ticks(0),
rkennke@10000 261 _bytes_per_line(Disassembler::pd_instruction_alignment())
rkennke@10000 262 {
rkennke@10000 263 memset(_option_buf, 0, sizeof(_option_buf));
drchase@7149 264 _strings.copy(c);
jrose@535 265
jrose@535 266 // parse the global option string:
jrose@535 267 collect_options(Disassembler::pd_cpu_opts());
jrose@535 268 collect_options(PrintAssemblyOptions);
jrose@535 269
jrose@535 270 if (strstr(options(), "hsdis-")) {
jrose@535 271 if (strstr(options(), "hsdis-print-raw"))
jrose@535 272 _print_raw = (strstr(options(), "xml") ? 2 : 1);
jrose@535 273 if (strstr(options(), "hsdis-print-pc"))
jrose@535 274 _print_pc = !_print_pc;
jrose@535 275 if (strstr(options(), "hsdis-print-bytes"))
jrose@535 276 _print_bytes = !_print_bytes;
jrose@535 277 }
jrose@535 278 if (strstr(options(), "help")) {
jrose@535 279 tty->print_cr("PrintAssemblyOptions help:");
jrose@535 280 tty->print_cr(" hsdis-print-raw test plugin by requesting raw output");
jrose@535 281 tty->print_cr(" hsdis-print-raw-xml test plugin by requesting raw xml");
jrose@535 282 tty->print_cr(" hsdis-print-pc turn off PC printing (on by default)");
jrose@535 283 tty->print_cr(" hsdis-print-bytes turn on instruction byte output");
jrose@535 284 tty->print_cr("combined options: %s", options());
jrose@535 285 }
jrose@535 286 }
jrose@535 287
jrose@535 288 address decode_env::handle_event(const char* event, address arg) {
jrose@535 289 if (match(event, "insn")) {
jrose@535 290 start_insn(arg);
jrose@535 291 } else if (match(event, "/insn")) {
jrose@535 292 end_insn(arg);
jrose@535 293 } else if (match(event, "addr")) {
jrose@535 294 if (arg != NULL) {
jrose@535 295 print_address(arg);
jrose@535 296 return arg;
jrose@535 297 }
jrose@535 298 } else if (match(event, "mach")) {
never@2991 299 static char buffer[32] = { 0, };
never@2991 300 if (strcmp(buffer, (const char*)arg) != 0 ||
never@2991 301 strlen((const char*)arg) > sizeof(buffer) - 1) {
never@2991 302 // Only print this when the mach changes
never@2991 303 strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
aph@9920 304 buffer[sizeof(buffer) - 1] = '\0';
never@2991 305 output()->print_cr("[Disassembling for mach='%s']", arg);
never@2991 306 }
jrose@535 307 } else if (match(event, "format bytes-per-line")) {
jrose@535 308 _bytes_per_line = (int) (intptr_t) arg;
jrose@535 309 } else {
jrose@535 310 // ignore unrecognized markup
jrose@535 311 }
jrose@535 312 return NULL;
jrose@535 313 }
jrose@535 314
jrose@535 315 // called by the disassembler to print out jump targets and data addresses
jrose@535 316 void decode_env::print_address(address adr) {
jrose@535 317 outputStream* st = _output;
jrose@535 318
jrose@535 319 if (adr == NULL) {
jrose@535 320 st->print("NULL");
jrose@535 321 return;
jrose@535 322 }
jrose@535 323
jrose@535 324 int small_num = (int)(intptr_t)adr;
jrose@535 325 if ((intptr_t)adr == (intptr_t)small_num
jrose@535 326 && -1 <= small_num && small_num <= 9) {
jrose@535 327 st->print("%d", small_num);
jrose@535 328 return;
jrose@535 329 }
jrose@535 330
jrose@535 331 if (Universe::is_fully_initialized()) {
jrose@535 332 if (StubRoutines::contains(adr)) {
jrose@535 333 StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
jrose@535 334 if (desc == NULL)
jrose@535 335 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
jrose@535 336 if (desc != NULL) {
jrose@535 337 st->print("Stub::%s", desc->name());
jrose@535 338 if (desc->begin() != adr)
jrose@535 339 st->print("%+d 0x%p",adr - desc->begin(), adr);
never@2895 340 else if (WizardMode) st->print(" " PTR_FORMAT, adr);
jrose@535 341 return;
jrose@535 342 }
never@2895 343 st->print("Stub::<unknown> " PTR_FORMAT, adr);
jrose@535 344 return;
jrose@535 345 }
jrose@535 346
jrose@535 347 BarrierSet* bs = Universe::heap()->barrier_set();
jrose@535 348 if (bs->kind() == BarrierSet::CardTableModRef &&
jrose@535 349 adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) {
jrose@535 350 st->print("word_map_base");
jrose@535 351 if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
jrose@535 352 return;
jrose@535 353 }
jrose@535 354
jrose@535 355 oop obj;
jrose@535 356 if (_nm != NULL
jrose@535 357 && (obj = _nm->embeddedOop_at(cur_insn())) != NULL
jrose@1590 358 && (address) obj == adr
jrose@1590 359 && Universe::heap()->is_in(obj)
jrose@1590 360 && Universe::heap()->is_in(obj->klass())) {
jrose@1590 361 julong c = st->count();
jrose@535 362 obj->print_value_on(st);
jrose@1590 363 if (st->count() == c) {
jrose@1590 364 // No output. (Can happen in product builds.)
hseigel@4278 365 st->print("(a %s)", obj->klass()->external_name());
jrose@1590 366 }
jrose@535 367 return;
jrose@535 368 }
jrose@535 369 }
jrose@535 370
never@2895 371 // Fall through to a simple (hexadecimal) numeral.
never@2895 372 st->print(PTR_FORMAT, adr);
jrose@535 373 }
jrose@535 374
jrose@535 375 void decode_env::print_insn_labels() {
jrose@535 376 address p = cur_insn();
jrose@535 377 outputStream* st = output();
jrose@535 378 CodeBlob* cb = _code;
jrose@535 379 if (cb != NULL) {
jrose@1590 380 cb->print_block_comment(st, p);
jrose@535 381 }
roland@4767 382 _strings.print_block_comment(st, (intptr_t)(p - _start));
jrose@535 383 if (_print_pc) {
never@2895 384 st->print(" " PTR_FORMAT ": ", p);
jrose@535 385 }
jrose@535 386 }
jrose@535 387
jrose@535 388 void decode_env::print_insn_bytes(address pc, address pc_limit) {
jrose@535 389 outputStream* st = output();
jrose@535 390 size_t incr = 1;
jrose@535 391 size_t perline = _bytes_per_line;
jrose@535 392 if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
jrose@535 393 && !((uintptr_t)pc % sizeof(int))
jrose@535 394 && !((uintptr_t)pc_limit % sizeof(int))) {
jrose@535 395 incr = sizeof(int);
jrose@535 396 if (perline % incr) perline += incr - (perline % incr);
jrose@535 397 }
jrose@535 398 while (pc < pc_limit) {
jrose@535 399 // tab to the desired column:
jrose@535 400 st->move_to(COMMENT_COLUMN);
jrose@535 401 address pc0 = pc;
jrose@535 402 address pc1 = pc + perline;
jrose@535 403 if (pc1 > pc_limit) pc1 = pc_limit;
jrose@535 404 for (; pc < pc1; pc += incr) {
jrose@535 405 if (pc == pc0)
jrose@535 406 st->print(BYTES_COMMENT);
jrose@535 407 else if ((uint)(pc - pc0) % sizeof(int) == 0)
jrose@535 408 st->print(" "); // put out a space on word boundaries
jrose@535 409 if (incr == sizeof(int))
jrose@535 410 st->print("%08lx", *(int*)pc);
jrose@535 411 else st->print("%02x", (*pc)&0xFF);
jrose@535 412 }
jrose@535 413 st->cr();
jrose@535 414 }
jrose@535 415 }
jrose@535 416
jrose@535 417
jrose@535 418 static void* event_to_env(void* env_pv, const char* event, void* arg) {
jrose@535 419 decode_env* env = (decode_env*) env_pv;
jrose@535 420 return env->handle_event(event, (address) arg);
jrose@535 421 }
jrose@535 422
drchase@6680 423 ATTRIBUTE_PRINTF(2, 3)
jrose@535 424 static int printf_to_env(void* env_pv, const char* format, ...) {
jrose@535 425 decode_env* env = (decode_env*) env_pv;
jrose@535 426 outputStream* st = env->output();
jrose@535 427 size_t flen = strlen(format);
jrose@535 428 const char* raw = NULL;
jrose@535 429 if (flen == 0) return 0;
jrose@535 430 if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
jrose@535 431 if (flen < 2 ||
jrose@535 432 strchr(format, '%') == NULL) {
jrose@535 433 raw = format;
jrose@535 434 } else if (format[0] == '%' && format[1] == '%' &&
jrose@535 435 strchr(format+2, '%') == NULL) {
jrose@535 436 // happens a lot on machines with names like %foo
jrose@535 437 flen--;
jrose@535 438 raw = format+1;
jrose@535 439 }
jrose@535 440 if (raw != NULL) {
jrose@535 441 st->print_raw(raw, (int) flen);
jrose@535 442 return (int) flen;
jrose@535 443 }
jrose@535 444 va_list ap;
jrose@535 445 va_start(ap, format);
jrose@535 446 julong cnt0 = st->count();
jrose@535 447 st->vprint(format, ap);
jrose@535 448 julong cnt1 = st->count();
jrose@535 449 va_end(ap);
jrose@535 450 return (int)(cnt1 - cnt0);
jrose@535 451 }
jrose@535 452
jrose@535 453 address decode_env::decode_instructions(address start, address end) {
jrose@535 454 _start = start; _end = end;
jrose@535 455
bobv@2036 456 assert(((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment()) == 0), "misaligned insn addr");
jrose@535 457
jrose@535 458 const int show_bytes = false; // for disassembler debugging
jrose@535 459
jrose@535 460 //_version = Disassembler::pd_cpu_version();
jrose@535 461
jrose@535 462 if (!Disassembler::can_decode()) {
jrose@535 463 return NULL;
jrose@535 464 }
jrose@535 465
jrose@535 466 // decode a series of instructions and return the end of the last instruction
jrose@535 467
jrose@535 468 if (_print_raw) {
jrose@535 469 // Print whatever the library wants to print, w/o fancy callbacks.
jrose@535 470 // This is mainly for debugging the library itself.
jrose@535 471 FILE* out = stdout;
jrose@535 472 FILE* xmlout = (_print_raw > 1 ? out : NULL);
minqi@4244 473 return use_new_version ?
minqi@4244 474 (address)
minqi@4244 475 (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
minqi@4244 476 start, end - start,
minqi@4244 477 NULL, (void*) xmlout,
minqi@4244 478 NULL, (void*) out,
minqi@4244 479 options(), 0/*nice new line*/)
minqi@4244 480 :
minqi@4244 481 (address)
minqi@4244 482 (*Disassembler::_decode_instructions)(start, end,
jrose@535 483 NULL, (void*) xmlout,
jrose@535 484 NULL, (void*) out,
jrose@535 485 options());
jrose@535 486 }
jrose@535 487
minqi@4244 488 return use_new_version ?
minqi@4244 489 (address)
minqi@4244 490 (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
minqi@4244 491 start, end - start,
minqi@4244 492 &event_to_env, (void*) this,
minqi@4244 493 &printf_to_env, (void*) this,
minqi@4244 494 options(), 0/*nice new line*/)
minqi@4244 495 :
minqi@4244 496 (address)
minqi@4244 497 (*Disassembler::_decode_instructions)(start, end,
jrose@535 498 &event_to_env, (void*) this,
jrose@535 499 &printf_to_env, (void*) this,
jrose@535 500 options());
jrose@535 501 }
jrose@535 502
jrose@535 503
jrose@535 504 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
jrose@535 505 if (!load_library()) return;
jrose@535 506 decode_env env(cb, st);
never@2895 507 env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb);
twisti@2103 508 env.decode_instructions(cb->code_begin(), cb->code_end());
jrose@535 509 }
jrose@535 510
roland@4767 511 void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) {
jrose@535 512 if (!load_library()) return;
kvn@4107 513 decode_env env(CodeCache::find_blob_unsafe(start), st, c);
jrose@535 514 env.decode_instructions(start, end);
jrose@535 515 }
jrose@535 516
jrose@535 517 void Disassembler::decode(nmethod* nm, outputStream* st) {
jrose@535 518 if (!load_library()) return;
jrose@535 519 decode_env env(nm, st);
never@2895 520 env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm);
jrose@535 521 env.output()->print_cr("Code:");
jrose@535 522
twisti@2047 523 #ifdef SHARK
twisti@2103 524 SharkEntry* entry = (SharkEntry *) nm->code_begin();
twisti@2103 525 unsigned char* p = entry->code_start();
twisti@2047 526 unsigned char* end = entry->code_limit();
twisti@2047 527 #else
twisti@2103 528 unsigned char* p = nm->code_begin();
twisti@2103 529 unsigned char* end = nm->code_end();
twisti@2047 530 #endif // SHARK
jrose@535 531
jrose@535 532 // If there has been profiling, print the buckets.
jrose@535 533 if (FlatProfiler::bucket_start_for(p) != NULL) {
jrose@535 534 unsigned char* p1 = p;
jrose@535 535 int total_bucket_count = 0;
jrose@535 536 while (p1 < end) {
jrose@535 537 unsigned char* p0 = p1;
jrose@535 538 p1 += pd_instruction_alignment();
jrose@535 539 address bucket_pc = FlatProfiler::bucket_start_for(p1);
jrose@535 540 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
jrose@535 541 total_bucket_count += FlatProfiler::bucket_count_for(p0);
jrose@535 542 }
jrose@535 543 env.set_total_ticks(total_bucket_count);
jrose@535 544 }
jrose@535 545
twisti@2350 546 // Print constant table.
twisti@2350 547 if (nm->consts_size() > 0) {
twisti@2350 548 nm->print_nmethod_labels(env.output(), nm->consts_begin());
twisti@2350 549 int offset = 0;
twisti@2350 550 for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
twisti@2350 551 if ((offset % 8) == 0) {
never@2895 552 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p, offset, *((int32_t*) p), *((int64_t*) p));
twisti@2350 553 } else {
never@2895 554 env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p, offset, *((int32_t*) p));
twisti@2350 555 }
twisti@2350 556 }
twisti@2350 557 }
twisti@2350 558
jrose@535 559 env.decode_instructions(p, end);
jrose@535 560 }

mercurial