src/cpu/sparc/vm/disassembler_sparc.cpp

changeset 545
a49a647afe9a
parent 528
c6ff24ceec1c
parent 544
9f4457a14b58
child 548
ba764ed4b6f2
     1.1 --- a/src/cpu/sparc/vm/disassembler_sparc.cpp	Thu Apr 10 15:49:16 2008 -0400
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,230 +0,0 @@
     1.4 -/*
     1.5 - * Copyright 1997-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 - * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 - * have any questions.
    1.25 - *
    1.26 - */
    1.27 -
    1.28 -# include "incls/_precompiled.incl"
    1.29 -# include "incls/_disassembler_sparc.cpp.incl"
    1.30 -
    1.31 -#ifndef PRODUCT
    1.32 -
    1.33 -#define SPARC_VERSION (VM_Version::v9_instructions_work()?              \
    1.34 -                        (VM_Version::v8_instructions_work()? "" : "9") : "8")
    1.35 -
    1.36 -// This routine is in the shared library:
    1.37 -typedef unsigned char* print_insn_sparc_t(unsigned char* start, DisassemblerEnv* env,
    1.38 -                                          const char* sparc_version);
    1.39 -
    1.40 -void*    Disassembler::_library          = NULL;
    1.41 -dll_func Disassembler::_print_insn_sparc = NULL;
    1.42 -
    1.43 -bool Disassembler::load_library() {
    1.44 -  if (_library == NULL) {
    1.45 -    char buf[1024];
    1.46 -    char ebuf[1024];
    1.47 -    sprintf(buf, "disassembler%s", os::dll_file_extension());
    1.48 -    _library = hpi::dll_load(buf, ebuf, sizeof ebuf);
    1.49 -    if (_library != NULL) {
    1.50 -      tty->print_cr("Loaded disassembler");
    1.51 -      _print_insn_sparc = CAST_TO_FN_PTR(dll_func, hpi::dll_lookup(_library, "print_insn_sparc"));
    1.52 -    }
    1.53 -  }
    1.54 -  return (_library != NULL) && (_print_insn_sparc != NULL);
    1.55 -}
    1.56 -
    1.57 -
    1.58 -class sparc_env : public DisassemblerEnv {
    1.59 - private:
    1.60 -  nmethod*      code;
    1.61 -  outputStream* output;
    1.62 -  const char*   version;
    1.63 -
    1.64 -  static void print_address(address value, outputStream* st);
    1.65 -
    1.66 - public:
    1.67 -  sparc_env(nmethod* rcode, outputStream* routput) {
    1.68 -    code    = rcode;
    1.69 -    output  = routput;
    1.70 -    version = SPARC_VERSION;
    1.71 -  }
    1.72 -  const char* sparc_version() { return version; }
    1.73 -  void print_label(intptr_t value);
    1.74 -  void print_raw(char* str) { output->print_raw(str); }
    1.75 -  void print(char* format, ...);
    1.76 -  char* string_for_offset(intptr_t value);
    1.77 -  char* string_for_constant(unsigned char* pc, intptr_t value, int is_decimal);
    1.78 -};
    1.79 -
    1.80 -
    1.81 -void sparc_env::print_address(address adr, outputStream* st) {
    1.82 -  if (!Universe::is_fully_initialized()) {
    1.83 -    st->print(INTPTR_FORMAT, (intptr_t)adr);
    1.84 -    return;
    1.85 -  }
    1.86 -  if (StubRoutines::contains(adr)) {
    1.87 -    StubCodeDesc *desc = StubCodeDesc::desc_for(adr);
    1.88 -    if (desc == NULL)
    1.89 -      desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
    1.90 -    if (desc == NULL)
    1.91 -      st->print("Unknown stub at " INTPTR_FORMAT, adr);
    1.92 -    else {
    1.93 -      st->print("Stub::%s", desc->name());
    1.94 -      if (desc->begin() != adr)
    1.95 -        st->print("%+d 0x%p",adr - desc->begin(), adr);
    1.96 -      else if (WizardMode) st->print(" " INTPTR_FORMAT, adr);
    1.97 -    }
    1.98 -  } else {
    1.99 -    BarrierSet* bs = Universe::heap()->barrier_set();
   1.100 -    if (bs->kind() == BarrierSet::CardTableModRef &&
   1.101 -        adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) {
   1.102 -      st->print("word_map_base");
   1.103 -      if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
   1.104 -    } else {
   1.105 -      st->print(INTPTR_FORMAT, (intptr_t)adr);
   1.106 -    }
   1.107 -  }
   1.108 -}
   1.109 -
   1.110 -
   1.111 -// called by the disassembler to print out jump addresses
   1.112 -void sparc_env::print_label(intptr_t value) {
   1.113 -  print_address((address) value, output);
   1.114 -}
   1.115 -
   1.116 -void sparc_env::print(char* format, ...) {
   1.117 -  va_list ap;
   1.118 -  va_start(ap, format);
   1.119 -  output->vprint(format, ap);
   1.120 -  va_end(ap);
   1.121 -}
   1.122 -
   1.123 -char* sparc_env::string_for_offset(intptr_t value) {
   1.124 -  stringStream st;
   1.125 -  print_address((address) value, &st);
   1.126 -  return st.as_string();
   1.127 -}
   1.128 -
   1.129 -char* sparc_env::string_for_constant(unsigned char* pc, intptr_t value, int is_decimal) {
   1.130 -  stringStream st;
   1.131 -  oop obj;
   1.132 -  if (code && (obj = code->embeddedOop_at(pc)) != NULL) {
   1.133 -    obj->print_value_on(&st);
   1.134 -  } else
   1.135 -  {
   1.136 -    print_address((address) value, &st);
   1.137 -  }
   1.138 -  return st.as_string();
   1.139 -}
   1.140 -
   1.141 -
   1.142 -address Disassembler::decode_instruction(address start, DisassemblerEnv* env) {
   1.143 -  const char* version = ((sparc_env*)env)->sparc_version();
   1.144 -  return ((print_insn_sparc_t*) _print_insn_sparc)(start, env, version);
   1.145 -}
   1.146 -
   1.147 -
   1.148 -const int show_bytes = false; // for disassembler debugging
   1.149 -
   1.150 -
   1.151 -void Disassembler::decode(CodeBlob* cb, outputStream* st) {
   1.152 -  st = st ? st : tty;
   1.153 -  st->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
   1.154 -  decode(cb->instructions_begin(), cb->instructions_end(), st);
   1.155 -}
   1.156 -
   1.157 -
   1.158 -void Disassembler::decode(u_char* begin, u_char* end, outputStream* st) {
   1.159 -  assert ((((intptr_t)begin | (intptr_t)end) % sizeof(int) == 0), "misaligned insn addr");
   1.160 -  st = st ? st : tty;
   1.161 -  if (!load_library()) {
   1.162 -    st->print_cr("Could not load disassembler");
   1.163 -    return;
   1.164 -  }
   1.165 -  sparc_env env(NULL, st);
   1.166 -  unsigned char*  p = (unsigned char*) begin;
   1.167 -  CodeBlob* cb = CodeCache::find_blob_unsafe(begin);
   1.168 -  while (p < (unsigned char*) end && p) {
   1.169 -    if (cb != NULL) {
   1.170 -      cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin()));
   1.171 -    }
   1.172 -
   1.173 -    unsigned char* p0 = p;
   1.174 -    st->print(INTPTR_FORMAT ": ", p);
   1.175 -    p = decode_instruction(p, &env);
   1.176 -    if (show_bytes && p) {
   1.177 -      st->print("\t\t\t");
   1.178 -      while (p0 < p) { st->print("%08lx ", *(int*)p0); p0 += sizeof(int); }
   1.179 -    }
   1.180 -    st->cr();
   1.181 -  }
   1.182 -}
   1.183 -
   1.184 -
   1.185 -void Disassembler::decode(nmethod* nm, outputStream* st) {
   1.186 -  st = st ? st : tty;
   1.187 -
   1.188 -  st->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm);
   1.189 -  st->print("Code:");
   1.190 -  st->cr();
   1.191 -
   1.192 -  if (!load_library()) {
   1.193 -    st->print_cr("Could not load disassembler");
   1.194 -    return;
   1.195 -  }
   1.196 -  sparc_env env(nm, st);
   1.197 -  unsigned char* p   = nm->instructions_begin();
   1.198 -  unsigned char* end = nm->instructions_end();
   1.199 -  assert ((((intptr_t)p | (intptr_t)end) % sizeof(int) == 0), "misaligned insn addr");
   1.200 -
   1.201 -  unsigned char *p1 = p;
   1.202 -  int total_bucket_count = 0;
   1.203 -  while (p1 < end && p1) {
   1.204 -    unsigned char *p0 = p1;
   1.205 -    ++p1;
   1.206 -    address bucket_pc = FlatProfiler::bucket_start_for(p1);
   1.207 -    if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
   1.208 -      total_bucket_count += FlatProfiler::bucket_count_for(p0);
   1.209 -  }
   1.210 -
   1.211 -  while (p < end && p) {
   1.212 -    if (p == nm->entry_point())                     st->print_cr("[Entry Point]");
   1.213 -    if (p == nm->verified_entry_point())            st->print_cr("[Verified Entry Point]");
   1.214 -    if (p == nm->exception_begin())                 st->print_cr("[Exception Handler]");
   1.215 -    if (p == nm->stub_begin())                      st->print_cr("[Stub Code]");
   1.216 -    if (p == nm->consts_begin())                    st->print_cr("[Constants]");
   1.217 -    nm->print_block_comment(st, (intptr_t)(p - nm->instructions_begin()));
   1.218 -    unsigned char* p0 = p;
   1.219 -    st->print("  " INTPTR_FORMAT ": ", p);
   1.220 -    p = decode_instruction(p, &env);
   1.221 -    nm->print_code_comment_on(st, 40, p0, p);
   1.222 -    st->cr();
   1.223 -    // Output pc bucket ticks if we have any
   1.224 -    address bucket_pc = FlatProfiler::bucket_start_for(p);
   1.225 -    if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p) {
   1.226 -      int bucket_count = FlatProfiler::bucket_count_for(p0);
   1.227 -      tty->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_bucket_count, bucket_count);
   1.228 -      tty->cr();
   1.229 -    }
   1.230 -  }
   1.231 -}
   1.232 -
   1.233 -#endif // PRODUCT

mercurial