src/share/vm/compiler/disassembler.cpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/compiler/disassembler.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,553 @@
     1.4 +/*
     1.5 + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/javaClasses.hpp"
    1.30 +#include "code/codeCache.hpp"
    1.31 +#include "compiler/disassembler.hpp"
    1.32 +#include "gc_interface/collectedHeap.hpp"
    1.33 +#include "memory/cardTableModRefBS.hpp"
    1.34 +#include "runtime/fprofiler.hpp"
    1.35 +#include "runtime/handles.inline.hpp"
    1.36 +#include "runtime/stubCodeGenerator.hpp"
    1.37 +#include "runtime/stubRoutines.hpp"
    1.38 +#ifdef TARGET_ARCH_x86
    1.39 +# include "depChecker_x86.hpp"
    1.40 +#endif
    1.41 +#ifdef TARGET_ARCH_sparc
    1.42 +# include "depChecker_sparc.hpp"
    1.43 +#endif
    1.44 +#ifdef TARGET_ARCH_zero
    1.45 +# include "depChecker_zero.hpp"
    1.46 +#endif
    1.47 +#ifdef TARGET_ARCH_arm
    1.48 +# include "depChecker_arm.hpp"
    1.49 +#endif
    1.50 +#ifdef TARGET_ARCH_ppc
    1.51 +# include "depChecker_ppc.hpp"
    1.52 +#endif
    1.53 +#ifdef SHARK
    1.54 +#include "shark/sharkEntry.hpp"
    1.55 +#endif
    1.56 +
    1.57 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    1.58 +
    1.59 +void*       Disassembler::_library               = NULL;
    1.60 +bool        Disassembler::_tried_to_load_library = false;
    1.61 +
    1.62 +// This routine is in the shared library:
    1.63 +Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
    1.64 +Disassembler::decode_func Disassembler::_decode_instructions = NULL;
    1.65 +
    1.66 +static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH;
    1.67 +static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
    1.68 +static const char decode_instructions_name[] = "decode_instructions";
    1.69 +static bool use_new_version = true;
    1.70 +#define COMMENT_COLUMN  40 LP64_ONLY(+8) /*could be an option*/
    1.71 +#define BYTES_COMMENT   ";..."  /* funky byte display comment */
    1.72 +
    1.73 +bool Disassembler::load_library() {
    1.74 +  if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
    1.75 +    // Already succeeded.
    1.76 +    return true;
    1.77 +  }
    1.78 +  if (_tried_to_load_library) {
    1.79 +    // Do not try twice.
    1.80 +    // To force retry in debugger: assign _tried_to_load_library=0
    1.81 +    return false;
    1.82 +  }
    1.83 +  // Try to load it.
    1.84 +  char ebuf[1024];
    1.85 +  char buf[JVM_MAXPATHLEN];
    1.86 +  os::jvm_path(buf, sizeof(buf));
    1.87 +  int jvm_offset = -1;
    1.88 +  int lib_offset = -1;
    1.89 +  {
    1.90 +    // Match "jvm[^/]*" in jvm_path.
    1.91 +    const char* base = buf;
    1.92 +    const char* p = strrchr(buf, '/');
    1.93 +    if (p != NULL) lib_offset = p - base + 1;
    1.94 +    p = strstr(p ? p : base, "jvm");
    1.95 +    if (p != NULL)  jvm_offset = p - base;
    1.96 +  }
    1.97 +  // Find the disassembler shared library.
    1.98 +  // Search for several paths derived from libjvm, in this order:
    1.99 +  // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so  (for compatibility)
   1.100 +  // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
   1.101 +  // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
   1.102 +  // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
   1.103 +  if (jvm_offset >= 0) {
   1.104 +    // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
   1.105 +    strcpy(&buf[jvm_offset], hsdis_library_name);
   1.106 +    strcat(&buf[jvm_offset], os::dll_file_extension());
   1.107 +    _library = os::dll_load(buf, ebuf, sizeof ebuf);
   1.108 +    if (_library == NULL) {
   1.109 +      // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so
   1.110 +      strcpy(&buf[lib_offset], hsdis_library_name);
   1.111 +      strcat(&buf[lib_offset], os::dll_file_extension());
   1.112 +      _library = os::dll_load(buf, ebuf, sizeof ebuf);
   1.113 +    }
   1.114 +    if (_library == NULL) {
   1.115 +      // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
   1.116 +      buf[lib_offset - 1] = '\0';
   1.117 +      const char* p = strrchr(buf, '/');
   1.118 +      if (p != NULL) {
   1.119 +        lib_offset = p - buf + 1;
   1.120 +        strcpy(&buf[lib_offset], hsdis_library_name);
   1.121 +        strcat(&buf[lib_offset], os::dll_file_extension());
   1.122 +        _library = os::dll_load(buf, ebuf, sizeof ebuf);
   1.123 +      }
   1.124 +    }
   1.125 +  }
   1.126 +  if (_library == NULL) {
   1.127 +    // 4. hsdis-<arch>.so  (using LD_LIBRARY_PATH)
   1.128 +    strcpy(&buf[0], hsdis_library_name);
   1.129 +    strcat(&buf[0], os::dll_file_extension());
   1.130 +    _library = os::dll_load(buf, ebuf, sizeof ebuf);
   1.131 +  }
   1.132 +  if (_library != NULL) {
   1.133 +    _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
   1.134 +                                          os::dll_lookup(_library, decode_instructions_virtual_name));
   1.135 +  }
   1.136 +  if (_decode_instructions_virtual == NULL) {
   1.137 +    // could not spot in new version, try old version
   1.138 +    _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
   1.139 +                                          os::dll_lookup(_library, decode_instructions_name));
   1.140 +    use_new_version = false;
   1.141 +  } else {
   1.142 +    use_new_version = true;
   1.143 +  }
   1.144 +  _tried_to_load_library = true;
   1.145 +  if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) {
   1.146 +    tty->print_cr("Could not load %s; %s; %s", buf,
   1.147 +                  ((_library != NULL)
   1.148 +                   ? "entry point is missing"
   1.149 +                   : (WizardMode || PrintMiscellaneous)
   1.150 +                   ? (const char*)ebuf
   1.151 +                   : "library not loadable"),
   1.152 +                  "PrintAssembly is disabled");
   1.153 +    return false;
   1.154 +  }
   1.155 +
   1.156 +  // Success.
   1.157 +  tty->print_cr("Loaded disassembler from %s", buf);
   1.158 +  return true;
   1.159 +}
   1.160 +
   1.161 +
   1.162 +class decode_env {
   1.163 + private:
   1.164 +  nmethod*      _nm;
   1.165 +  CodeBlob*     _code;
   1.166 +  CodeStrings   _strings;
   1.167 +  outputStream* _output;
   1.168 +  address       _start, _end;
   1.169 +
   1.170 +  char          _option_buf[512];
   1.171 +  char          _print_raw;
   1.172 +  bool          _print_pc;
   1.173 +  bool          _print_bytes;
   1.174 +  address       _cur_insn;
   1.175 +  int           _total_ticks;
   1.176 +  int           _bytes_per_line; // arch-specific formatting option
   1.177 +
   1.178 +  static bool match(const char* event, const char* tag) {
   1.179 +    size_t taglen = strlen(tag);
   1.180 +    if (strncmp(event, tag, taglen) != 0)
   1.181 +      return false;
   1.182 +    char delim = event[taglen];
   1.183 +    return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
   1.184 +  }
   1.185 +
   1.186 +  void collect_options(const char* p) {
   1.187 +    if (p == NULL || p[0] == '\0')  return;
   1.188 +    size_t opt_so_far = strlen(_option_buf);
   1.189 +    if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf))  return;
   1.190 +    char* fillp = &_option_buf[opt_so_far];
   1.191 +    if (opt_so_far > 0) *fillp++ = ',';
   1.192 +    strcat(fillp, p);
   1.193 +    // replace white space by commas:
   1.194 +    char* q = fillp;
   1.195 +    while ((q = strpbrk(q, " \t\n")) != NULL)
   1.196 +      *q++ = ',';
   1.197 +    // Note that multiple PrintAssemblyOptions flags accumulate with \n,
   1.198 +    // which we want to be changed to a comma...
   1.199 +  }
   1.200 +
   1.201 +  void print_insn_labels();
   1.202 +  void print_insn_bytes(address pc0, address pc);
   1.203 +  void print_address(address value);
   1.204 +
   1.205 + public:
   1.206 +  decode_env(CodeBlob* code, outputStream* output, CodeStrings c = CodeStrings());
   1.207 +
   1.208 +  address decode_instructions(address start, address end);
   1.209 +
   1.210 +  void start_insn(address pc) {
   1.211 +    _cur_insn = pc;
   1.212 +    output()->bol();
   1.213 +    print_insn_labels();
   1.214 +  }
   1.215 +
   1.216 +  void end_insn(address pc) {
   1.217 +    address pc0 = cur_insn();
   1.218 +    outputStream* st = output();
   1.219 +    if (_print_bytes && pc > pc0)
   1.220 +      print_insn_bytes(pc0, pc);
   1.221 +    if (_nm != NULL) {
   1.222 +      _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
   1.223 +      // this calls reloc_string_for which calls oop::print_value_on
   1.224 +    }
   1.225 +
   1.226 +    // Output pc bucket ticks if we have any
   1.227 +    if (total_ticks() != 0) {
   1.228 +      address bucket_pc = FlatProfiler::bucket_start_for(pc);
   1.229 +      if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) {
   1.230 +        int bucket_count = FlatProfiler::bucket_count_for(pc0);
   1.231 +        if (bucket_count != 0) {
   1.232 +          st->bol();
   1.233 +          st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count);
   1.234 +        }
   1.235 +      }
   1.236 +    }
   1.237 +    // follow each complete insn by a nice newline
   1.238 +    st->cr();
   1.239 +  }
   1.240 +
   1.241 +  address handle_event(const char* event, address arg);
   1.242 +
   1.243 +  outputStream* output() { return _output; }
   1.244 +  address cur_insn() { return _cur_insn; }
   1.245 +  int total_ticks() { return _total_ticks; }
   1.246 +  void set_total_ticks(int n) { _total_ticks = n; }
   1.247 +  const char* options() { return _option_buf; }
   1.248 +};
   1.249 +
   1.250 +decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c) {
   1.251 +  memset(this, 0, sizeof(*this));
   1.252 +  _output = output ? output : tty;
   1.253 +  _code = code;
   1.254 +  if (code != NULL && code->is_nmethod())
   1.255 +    _nm = (nmethod*) code;
   1.256 +  _strings.assign(c);
   1.257 +
   1.258 +  // by default, output pc but not bytes:
   1.259 +  _print_pc       = true;
   1.260 +  _print_bytes    = false;
   1.261 +  _bytes_per_line = Disassembler::pd_instruction_alignment();
   1.262 +
   1.263 +  // parse the global option string:
   1.264 +  collect_options(Disassembler::pd_cpu_opts());
   1.265 +  collect_options(PrintAssemblyOptions);
   1.266 +
   1.267 +  if (strstr(options(), "hsdis-")) {
   1.268 +    if (strstr(options(), "hsdis-print-raw"))
   1.269 +      _print_raw = (strstr(options(), "xml") ? 2 : 1);
   1.270 +    if (strstr(options(), "hsdis-print-pc"))
   1.271 +      _print_pc = !_print_pc;
   1.272 +    if (strstr(options(), "hsdis-print-bytes"))
   1.273 +      _print_bytes = !_print_bytes;
   1.274 +  }
   1.275 +  if (strstr(options(), "help")) {
   1.276 +    tty->print_cr("PrintAssemblyOptions help:");
   1.277 +    tty->print_cr("  hsdis-print-raw       test plugin by requesting raw output");
   1.278 +    tty->print_cr("  hsdis-print-raw-xml   test plugin by requesting raw xml");
   1.279 +    tty->print_cr("  hsdis-print-pc        turn off PC printing (on by default)");
   1.280 +    tty->print_cr("  hsdis-print-bytes     turn on instruction byte output");
   1.281 +    tty->print_cr("combined options: %s", options());
   1.282 +  }
   1.283 +}
   1.284 +
   1.285 +address decode_env::handle_event(const char* event, address arg) {
   1.286 +  if (match(event, "insn")) {
   1.287 +    start_insn(arg);
   1.288 +  } else if (match(event, "/insn")) {
   1.289 +    end_insn(arg);
   1.290 +  } else if (match(event, "addr")) {
   1.291 +    if (arg != NULL) {
   1.292 +      print_address(arg);
   1.293 +      return arg;
   1.294 +    }
   1.295 +  } else if (match(event, "mach")) {
   1.296 +    static char buffer[32] = { 0, };
   1.297 +    if (strcmp(buffer, (const char*)arg) != 0 ||
   1.298 +        strlen((const char*)arg) > sizeof(buffer) - 1) {
   1.299 +      // Only print this when the mach changes
   1.300 +      strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
   1.301 +      output()->print_cr("[Disassembling for mach='%s']", arg);
   1.302 +    }
   1.303 +  } else if (match(event, "format bytes-per-line")) {
   1.304 +    _bytes_per_line = (int) (intptr_t) arg;
   1.305 +  } else {
   1.306 +    // ignore unrecognized markup
   1.307 +  }
   1.308 +  return NULL;
   1.309 +}
   1.310 +
   1.311 +// called by the disassembler to print out jump targets and data addresses
   1.312 +void decode_env::print_address(address adr) {
   1.313 +  outputStream* st = _output;
   1.314 +
   1.315 +  if (adr == NULL) {
   1.316 +    st->print("NULL");
   1.317 +    return;
   1.318 +  }
   1.319 +
   1.320 +  int small_num = (int)(intptr_t)adr;
   1.321 +  if ((intptr_t)adr == (intptr_t)small_num
   1.322 +      && -1 <= small_num && small_num <= 9) {
   1.323 +    st->print("%d", small_num);
   1.324 +    return;
   1.325 +  }
   1.326 +
   1.327 +  if (Universe::is_fully_initialized()) {
   1.328 +    if (StubRoutines::contains(adr)) {
   1.329 +      StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
   1.330 +      if (desc == NULL)
   1.331 +        desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
   1.332 +      if (desc != NULL) {
   1.333 +        st->print("Stub::%s", desc->name());
   1.334 +        if (desc->begin() != adr)
   1.335 +          st->print("%+d 0x%p",adr - desc->begin(), adr);
   1.336 +        else if (WizardMode) st->print(" " PTR_FORMAT, adr);
   1.337 +        return;
   1.338 +      }
   1.339 +      st->print("Stub::<unknown> " PTR_FORMAT, adr);
   1.340 +      return;
   1.341 +    }
   1.342 +
   1.343 +    BarrierSet* bs = Universe::heap()->barrier_set();
   1.344 +    if (bs->kind() == BarrierSet::CardTableModRef &&
   1.345 +        adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) {
   1.346 +      st->print("word_map_base");
   1.347 +      if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
   1.348 +      return;
   1.349 +    }
   1.350 +
   1.351 +    oop obj;
   1.352 +    if (_nm != NULL
   1.353 +        && (obj = _nm->embeddedOop_at(cur_insn())) != NULL
   1.354 +        && (address) obj == adr
   1.355 +        && Universe::heap()->is_in(obj)
   1.356 +        && Universe::heap()->is_in(obj->klass())) {
   1.357 +      julong c = st->count();
   1.358 +      obj->print_value_on(st);
   1.359 +      if (st->count() == c) {
   1.360 +        // No output.  (Can happen in product builds.)
   1.361 +        st->print("(a %s)", obj->klass()->external_name());
   1.362 +      }
   1.363 +      return;
   1.364 +    }
   1.365 +  }
   1.366 +
   1.367 +  // Fall through to a simple (hexadecimal) numeral.
   1.368 +  st->print(PTR_FORMAT, adr);
   1.369 +}
   1.370 +
   1.371 +void decode_env::print_insn_labels() {
   1.372 +  address p = cur_insn();
   1.373 +  outputStream* st = output();
   1.374 +  CodeBlob* cb = _code;
   1.375 +  if (cb != NULL) {
   1.376 +    cb->print_block_comment(st, p);
   1.377 +  }
   1.378 +  _strings.print_block_comment(st, (intptr_t)(p - _start));
   1.379 +  if (_print_pc) {
   1.380 +    st->print("  " PTR_FORMAT ": ", p);
   1.381 +  }
   1.382 +}
   1.383 +
   1.384 +void decode_env::print_insn_bytes(address pc, address pc_limit) {
   1.385 +  outputStream* st = output();
   1.386 +  size_t incr = 1;
   1.387 +  size_t perline = _bytes_per_line;
   1.388 +  if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
   1.389 +      && !((uintptr_t)pc % sizeof(int))
   1.390 +      && !((uintptr_t)pc_limit % sizeof(int))) {
   1.391 +    incr = sizeof(int);
   1.392 +    if (perline % incr)  perline += incr - (perline % incr);
   1.393 +  }
   1.394 +  while (pc < pc_limit) {
   1.395 +    // tab to the desired column:
   1.396 +    st->move_to(COMMENT_COLUMN);
   1.397 +    address pc0 = pc;
   1.398 +    address pc1 = pc + perline;
   1.399 +    if (pc1 > pc_limit)  pc1 = pc_limit;
   1.400 +    for (; pc < pc1; pc += incr) {
   1.401 +      if (pc == pc0)
   1.402 +        st->print(BYTES_COMMENT);
   1.403 +      else if ((uint)(pc - pc0) % sizeof(int) == 0)
   1.404 +        st->print(" ");         // put out a space on word boundaries
   1.405 +      if (incr == sizeof(int))
   1.406 +            st->print("%08lx", *(int*)pc);
   1.407 +      else  st->print("%02x",   (*pc)&0xFF);
   1.408 +    }
   1.409 +    st->cr();
   1.410 +  }
   1.411 +}
   1.412 +
   1.413 +
   1.414 +static void* event_to_env(void* env_pv, const char* event, void* arg) {
   1.415 +  decode_env* env = (decode_env*) env_pv;
   1.416 +  return env->handle_event(event, (address) arg);
   1.417 +}
   1.418 +
   1.419 +ATTRIBUTE_PRINTF(2, 3)
   1.420 +static int printf_to_env(void* env_pv, const char* format, ...) {
   1.421 +  decode_env* env = (decode_env*) env_pv;
   1.422 +  outputStream* st = env->output();
   1.423 +  size_t flen = strlen(format);
   1.424 +  const char* raw = NULL;
   1.425 +  if (flen == 0)  return 0;
   1.426 +  if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
   1.427 +  if (flen < 2 ||
   1.428 +      strchr(format, '%') == NULL) {
   1.429 +    raw = format;
   1.430 +  } else if (format[0] == '%' && format[1] == '%' &&
   1.431 +             strchr(format+2, '%') == NULL) {
   1.432 +    // happens a lot on machines with names like %foo
   1.433 +    flen--;
   1.434 +    raw = format+1;
   1.435 +  }
   1.436 +  if (raw != NULL) {
   1.437 +    st->print_raw(raw, (int) flen);
   1.438 +    return (int) flen;
   1.439 +  }
   1.440 +  va_list ap;
   1.441 +  va_start(ap, format);
   1.442 +  julong cnt0 = st->count();
   1.443 +  st->vprint(format, ap);
   1.444 +  julong cnt1 = st->count();
   1.445 +  va_end(ap);
   1.446 +  return (int)(cnt1 - cnt0);
   1.447 +}
   1.448 +
   1.449 +address decode_env::decode_instructions(address start, address end) {
   1.450 +  _start = start; _end = end;
   1.451 +
   1.452 +  assert(((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment()) == 0), "misaligned insn addr");
   1.453 +
   1.454 +  const int show_bytes = false; // for disassembler debugging
   1.455 +
   1.456 +  //_version = Disassembler::pd_cpu_version();
   1.457 +
   1.458 +  if (!Disassembler::can_decode()) {
   1.459 +    return NULL;
   1.460 +  }
   1.461 +
   1.462 +  // decode a series of instructions and return the end of the last instruction
   1.463 +
   1.464 +  if (_print_raw) {
   1.465 +    // Print whatever the library wants to print, w/o fancy callbacks.
   1.466 +    // This is mainly for debugging the library itself.
   1.467 +    FILE* out = stdout;
   1.468 +    FILE* xmlout = (_print_raw > 1 ? out : NULL);
   1.469 +    return use_new_version ?
   1.470 +      (address)
   1.471 +      (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
   1.472 +                                                    start, end - start,
   1.473 +                                                    NULL, (void*) xmlout,
   1.474 +                                                    NULL, (void*) out,
   1.475 +                                                    options(), 0/*nice new line*/)
   1.476 +      :
   1.477 +      (address)
   1.478 +      (*Disassembler::_decode_instructions)(start, end,
   1.479 +                                            NULL, (void*) xmlout,
   1.480 +                                            NULL, (void*) out,
   1.481 +                                            options());
   1.482 +  }
   1.483 +
   1.484 +  return use_new_version ?
   1.485 +    (address)
   1.486 +    (*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
   1.487 +                                                  start, end - start,
   1.488 +                                                  &event_to_env,  (void*) this,
   1.489 +                                                  &printf_to_env, (void*) this,
   1.490 +                                                  options(), 0/*nice new line*/)
   1.491 +    :
   1.492 +    (address)
   1.493 +    (*Disassembler::_decode_instructions)(start, end,
   1.494 +                                          &event_to_env,  (void*) this,
   1.495 +                                          &printf_to_env, (void*) this,
   1.496 +                                          options());
   1.497 +}
   1.498 +
   1.499 +
   1.500 +void Disassembler::decode(CodeBlob* cb, outputStream* st) {
   1.501 +  if (!load_library())  return;
   1.502 +  decode_env env(cb, st);
   1.503 +  env.output()->print_cr("Decoding CodeBlob " PTR_FORMAT, cb);
   1.504 +  env.decode_instructions(cb->code_begin(), cb->code_end());
   1.505 +}
   1.506 +
   1.507 +void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c) {
   1.508 +  if (!load_library())  return;
   1.509 +  decode_env env(CodeCache::find_blob_unsafe(start), st, c);
   1.510 +  env.decode_instructions(start, end);
   1.511 +}
   1.512 +
   1.513 +void Disassembler::decode(nmethod* nm, outputStream* st) {
   1.514 +  if (!load_library())  return;
   1.515 +  decode_env env(nm, st);
   1.516 +  env.output()->print_cr("Decoding compiled method " PTR_FORMAT ":", nm);
   1.517 +  env.output()->print_cr("Code:");
   1.518 +
   1.519 +#ifdef SHARK
   1.520 +  SharkEntry* entry = (SharkEntry *) nm->code_begin();
   1.521 +  unsigned char* p   = entry->code_start();
   1.522 +  unsigned char* end = entry->code_limit();
   1.523 +#else
   1.524 +  unsigned char* p   = nm->code_begin();
   1.525 +  unsigned char* end = nm->code_end();
   1.526 +#endif // SHARK
   1.527 +
   1.528 +  // If there has been profiling, print the buckets.
   1.529 +  if (FlatProfiler::bucket_start_for(p) != NULL) {
   1.530 +    unsigned char* p1 = p;
   1.531 +    int total_bucket_count = 0;
   1.532 +    while (p1 < end) {
   1.533 +      unsigned char* p0 = p1;
   1.534 +      p1 += pd_instruction_alignment();
   1.535 +      address bucket_pc = FlatProfiler::bucket_start_for(p1);
   1.536 +      if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
   1.537 +        total_bucket_count += FlatProfiler::bucket_count_for(p0);
   1.538 +    }
   1.539 +    env.set_total_ticks(total_bucket_count);
   1.540 +  }
   1.541 +
   1.542 +  // Print constant table.
   1.543 +  if (nm->consts_size() > 0) {
   1.544 +    nm->print_nmethod_labels(env.output(), nm->consts_begin());
   1.545 +    int offset = 0;
   1.546 +    for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
   1.547 +      if ((offset % 8) == 0) {
   1.548 +        env.output()->print_cr("  " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT "   " PTR64_FORMAT, p, offset, *((int32_t*) p), *((int64_t*) p));
   1.549 +      } else {
   1.550 +        env.output()->print_cr("  " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT,                    p, offset, *((int32_t*) p));
   1.551 +      }
   1.552 +    }
   1.553 +  }
   1.554 +
   1.555 +  env.decode_instructions(p, end);
   1.556 +}

mercurial