1.1 --- a/src/cpu/x86/vm/disassembler_x86.cpp Wed Apr 09 10:38:30 2008 -0400 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,201 +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_x86.cpp.incl" 1.30 - 1.31 -#ifndef PRODUCT 1.32 - 1.33 -void* Disassembler::_library = NULL; 1.34 -Disassembler::decode_func Disassembler::_decode_instruction = NULL; 1.35 - 1.36 -bool Disassembler::load_library() { 1.37 - if (_library == NULL) { 1.38 - char buf[1024]; 1.39 - char ebuf[1024]; 1.40 - sprintf(buf, "disassembler%s", os::dll_file_extension()); 1.41 - _library = hpi::dll_load(buf, ebuf, sizeof ebuf); 1.42 - if (_library != NULL) { 1.43 - tty->print_cr("Loaded disassembler"); 1.44 - _decode_instruction = CAST_TO_FN_PTR(Disassembler::decode_func, hpi::dll_lookup(_library, "decode_instruction")); 1.45 - } 1.46 - } 1.47 - return (_library != NULL) && (_decode_instruction != NULL); 1.48 -} 1.49 - 1.50 -class x86_env : public DisassemblerEnv { 1.51 - private: 1.52 - nmethod* code; 1.53 - outputStream* output; 1.54 - public: 1.55 - x86_env(nmethod* rcode, outputStream* routput) { 1.56 - code = rcode; 1.57 - output = routput; 1.58 - } 1.59 - void print_label(intptr_t value); 1.60 - void print_raw(char* str) { output->print_raw(str); } 1.61 - void print(char* format, ...); 1.62 - char* string_for_offset(intptr_t value); 1.63 - char* string_for_constant(unsigned char* pc, intptr_t value, int is_decimal); 1.64 -}; 1.65 - 1.66 - 1.67 -void x86_env::print_label(intptr_t value) { 1.68 - if (!Universe::is_fully_initialized()) { 1.69 - output->print(INTPTR_FORMAT, value); 1.70 - return; 1.71 - } 1.72 - address adr = (address) value; 1.73 - if (StubRoutines::contains(adr)) { 1.74 - StubCodeDesc* desc = StubCodeDesc::desc_for(adr); 1.75 - const char * desc_name = "unknown stub"; 1.76 - if (desc != NULL) { 1.77 - desc_name = desc->name(); 1.78 - } 1.79 - output->print("Stub::%s", desc_name); 1.80 - if (WizardMode) output->print(" " INTPTR_FORMAT, value); 1.81 - } else { 1.82 - output->print(INTPTR_FORMAT, value); 1.83 - } 1.84 -} 1.85 - 1.86 -void x86_env::print(char* format, ...) { 1.87 - va_list ap; 1.88 - va_start(ap, format); 1.89 - output->vprint(format, ap); 1.90 - va_end(ap); 1.91 -} 1.92 - 1.93 -char* x86_env::string_for_offset(intptr_t value) { 1.94 - stringStream st; 1.95 - if (!Universe::is_fully_initialized()) { 1.96 - st.print(INTX_FORMAT, value); 1.97 - return st.as_string(); 1.98 - } 1.99 - BarrierSet* bs = Universe::heap()->barrier_set(); 1.100 - BarrierSet::Name bsn = bs->kind(); 1.101 - if (bs->kind() == BarrierSet::CardTableModRef && 1.102 - (jbyte*) value == ((CardTableModRefBS*)(bs))->byte_map_base) { 1.103 - st.print("word_map_base"); 1.104 - } else { 1.105 - st.print(INTX_FORMAT, value); 1.106 - } 1.107 - return st.as_string(); 1.108 -} 1.109 - 1.110 -char* x86_env::string_for_constant(unsigned char* pc, intptr_t value, int is_decimal) { 1.111 - stringStream st; 1.112 - oop obj = NULL; 1.113 - if (code && ((obj = code->embeddedOop_at(pc)) != NULL)) { 1.114 - obj->print_value_on(&st); 1.115 - } else { 1.116 - if (is_decimal == 1) { 1.117 - st.print(INTX_FORMAT, value); 1.118 - } else { 1.119 - st.print(INTPTR_FORMAT, value); 1.120 - } 1.121 - } 1.122 - return st.as_string(); 1.123 -} 1.124 - 1.125 - 1.126 - 1.127 -address Disassembler::decode_instruction(address start, DisassemblerEnv* env) { 1.128 - return ((decode_func) _decode_instruction)(start, env); 1.129 -} 1.130 - 1.131 - 1.132 -void Disassembler::decode(CodeBlob* cb, outputStream* st) { 1.133 - st = st ? st : tty; 1.134 - st->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb); 1.135 - decode(cb->instructions_begin(), cb->instructions_end(), st); 1.136 -} 1.137 - 1.138 - 1.139 -void Disassembler::decode(u_char* begin, u_char* end, outputStream* st) { 1.140 - st = st ? st : tty; 1.141 - 1.142 - const int show_bytes = false; // for disassembler debugging 1.143 - 1.144 - if (!load_library()) { 1.145 - st->print_cr("Could not load disassembler"); 1.146 - return; 1.147 - } 1.148 - 1.149 - x86_env env(NULL, st); 1.150 - unsigned char* p = (unsigned char*) begin; 1.151 - CodeBlob* cb = CodeCache::find_blob_unsafe(begin); 1.152 - while (p < (unsigned char*) end) { 1.153 - if (cb != NULL) { 1.154 - cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin())); 1.155 - } 1.156 - 1.157 - unsigned char* p0 = p; 1.158 - st->print(" " INTPTR_FORMAT ": ", p); 1.159 - p = decode_instruction(p, &env); 1.160 - if (show_bytes) { 1.161 - st->print("\t\t\t"); 1.162 - while (p0 < p) st->print("%x ", *p0++); 1.163 - } 1.164 - st->cr(); 1.165 - } 1.166 -} 1.167 - 1.168 - 1.169 -void Disassembler::decode(nmethod* nm, outputStream* st) { 1.170 - st = st ? st : tty; 1.171 - 1.172 - st->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm); 1.173 - st->print("Code:"); 1.174 - st->cr(); 1.175 - 1.176 - if (!load_library()) { 1.177 - st->print_cr("Could not load disassembler"); 1.178 - return; 1.179 - } 1.180 - x86_env env(nm, st); 1.181 - unsigned char* p = nm->instructions_begin(); 1.182 - unsigned char* end = nm->instructions_end(); 1.183 - while (p < end) { 1.184 - if (p == nm->entry_point()) st->print_cr("[Entry Point]"); 1.185 - if (p == nm->verified_entry_point()) st->print_cr("[Verified Entry Point]"); 1.186 - if (p == nm->exception_begin()) st->print_cr("[Exception Handler]"); 1.187 - if (p == nm->stub_begin()) st->print_cr("[Stub Code]"); 1.188 - if (p == nm->consts_begin()) st->print_cr("[Constants]"); 1.189 - nm->print_block_comment(st, (intptr_t)(p - nm->instructions_begin())); 1.190 - unsigned char* p0 = p; 1.191 - st->print(" " INTPTR_FORMAT ": ", p); 1.192 - p = decode_instruction(p, &env); 1.193 - nm->print_code_comment_on(st, 40, p0, p); 1.194 - st->cr(); 1.195 - // Output pc bucket ticks if we have any 1.196 - address bucket_pc = FlatProfiler::bucket_start_for(p); 1.197 - if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p) { 1.198 - int bucket_count = FlatProfiler::bucket_count_for(bucket_pc); 1.199 - tty->print_cr("[%d]", bucket_count); 1.200 - } 1.201 - } 1.202 -} 1.203 - 1.204 -#endif // PRODUCT