0
|
1 /*
|
|
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 # include "incls/_precompiled.incl"
|
|
26 # include "incls/_disassembler_sparc.cpp.incl"
|
|
27
|
|
28 #ifndef PRODUCT
|
|
29
|
|
30 #define SPARC_VERSION (VM_Version::v9_instructions_work()? \
|
|
31 (VM_Version::v8_instructions_work()? "" : "9") : "8")
|
|
32
|
|
33 // This routine is in the shared library:
|
|
34 typedef unsigned char* print_insn_sparc_t(unsigned char* start, DisassemblerEnv* env,
|
|
35 const char* sparc_version);
|
|
36
|
|
37 void* Disassembler::_library = NULL;
|
|
38 dll_func Disassembler::_print_insn_sparc = NULL;
|
|
39
|
|
40 bool Disassembler::load_library() {
|
|
41 if (_library == NULL) {
|
|
42 char buf[1024];
|
|
43 char ebuf[1024];
|
|
44 sprintf(buf, "disassembler%s", os::dll_file_extension());
|
|
45 _library = hpi::dll_load(buf, ebuf, sizeof ebuf);
|
|
46 if (_library != NULL) {
|
|
47 tty->print_cr("Loaded disassembler");
|
|
48 _print_insn_sparc = CAST_TO_FN_PTR(dll_func, hpi::dll_lookup(_library, "print_insn_sparc"));
|
|
49 }
|
|
50 }
|
|
51 return (_library != NULL) && (_print_insn_sparc != NULL);
|
|
52 }
|
|
53
|
|
54
|
|
55 class sparc_env : public DisassemblerEnv {
|
|
56 private:
|
|
57 nmethod* code;
|
|
58 outputStream* output;
|
|
59 const char* version;
|
|
60
|
|
61 static void print_address(address value, outputStream* st);
|
|
62
|
|
63 public:
|
|
64 sparc_env(nmethod* rcode, outputStream* routput) {
|
|
65 code = rcode;
|
|
66 output = routput;
|
|
67 version = SPARC_VERSION;
|
|
68 }
|
|
69 const char* sparc_version() { return version; }
|
|
70 void print_label(intptr_t value);
|
|
71 void print_raw(char* str) { output->print_raw(str); }
|
|
72 void print(char* format, ...);
|
|
73 char* string_for_offset(intptr_t value);
|
|
74 char* string_for_constant(unsigned char* pc, intptr_t value, int is_decimal);
|
|
75 };
|
|
76
|
|
77
|
|
78 void sparc_env::print_address(address adr, outputStream* st) {
|
|
79 if (!Universe::is_fully_initialized()) {
|
|
80 st->print(INTPTR_FORMAT, (intptr_t)adr);
|
|
81 return;
|
|
82 }
|
|
83 if (StubRoutines::contains(adr)) {
|
|
84 StubCodeDesc *desc = StubCodeDesc::desc_for(adr);
|
|
85 if (desc == NULL)
|
|
86 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
|
|
87 if (desc == NULL)
|
|
88 st->print("Unknown stub at " INTPTR_FORMAT, adr);
|
|
89 else {
|
|
90 st->print("Stub::%s", desc->name());
|
|
91 if (desc->begin() != adr)
|
|
92 st->print("%+d 0x%p",adr - desc->begin(), adr);
|
|
93 else if (WizardMode) st->print(" " INTPTR_FORMAT, adr);
|
|
94 }
|
|
95 } else {
|
|
96 BarrierSet* bs = Universe::heap()->barrier_set();
|
|
97 if (bs->kind() == BarrierSet::CardTableModRef &&
|
|
98 adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) {
|
|
99 st->print("word_map_base");
|
|
100 if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
|
|
101 } else {
|
|
102 st->print(INTPTR_FORMAT, (intptr_t)adr);
|
|
103 }
|
|
104 }
|
|
105 }
|
|
106
|
|
107
|
|
108 // called by the disassembler to print out jump addresses
|
|
109 void sparc_env::print_label(intptr_t value) {
|
|
110 print_address((address) value, output);
|
|
111 }
|
|
112
|
|
113 void sparc_env::print(char* format, ...) {
|
|
114 va_list ap;
|
|
115 va_start(ap, format);
|
|
116 output->vprint(format, ap);
|
|
117 va_end(ap);
|
|
118 }
|
|
119
|
|
120 char* sparc_env::string_for_offset(intptr_t value) {
|
|
121 stringStream st;
|
|
122 print_address((address) value, &st);
|
|
123 return st.as_string();
|
|
124 }
|
|
125
|
|
126 char* sparc_env::string_for_constant(unsigned char* pc, intptr_t value, int is_decimal) {
|
|
127 stringStream st;
|
|
128 oop obj;
|
|
129 if (code && (obj = code->embeddedOop_at(pc)) != NULL) {
|
|
130 obj->print_value_on(&st);
|
|
131 } else
|
|
132 {
|
|
133 print_address((address) value, &st);
|
|
134 }
|
|
135 return st.as_string();
|
|
136 }
|
|
137
|
|
138
|
|
139 address Disassembler::decode_instruction(address start, DisassemblerEnv* env) {
|
|
140 const char* version = ((sparc_env*)env)->sparc_version();
|
|
141 return ((print_insn_sparc_t*) _print_insn_sparc)(start, env, version);
|
|
142 }
|
|
143
|
|
144
|
|
145 const int show_bytes = false; // for disassembler debugging
|
|
146
|
|
147
|
|
148 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
|
|
149 st = st ? st : tty;
|
|
150 st->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
|
|
151 decode(cb->instructions_begin(), cb->instructions_end(), st);
|
|
152 }
|
|
153
|
|
154
|
|
155 void Disassembler::decode(u_char* begin, u_char* end, outputStream* st) {
|
|
156 assert ((((intptr_t)begin | (intptr_t)end) % sizeof(int) == 0), "misaligned insn addr");
|
|
157 st = st ? st : tty;
|
|
158 if (!load_library()) {
|
|
159 st->print_cr("Could not load disassembler");
|
|
160 return;
|
|
161 }
|
|
162 sparc_env env(NULL, st);
|
|
163 unsigned char* p = (unsigned char*) begin;
|
|
164 CodeBlob* cb = CodeCache::find_blob_unsafe(begin);
|
|
165 while (p < (unsigned char*) end && p) {
|
|
166 if (cb != NULL) {
|
|
167 cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin()));
|
|
168 }
|
|
169
|
|
170 unsigned char* p0 = p;
|
|
171 st->print(INTPTR_FORMAT ": ", p);
|
|
172 p = decode_instruction(p, &env);
|
|
173 if (show_bytes && p) {
|
|
174 st->print("\t\t\t");
|
|
175 while (p0 < p) { st->print("%08lx ", *(int*)p0); p0 += sizeof(int); }
|
|
176 }
|
|
177 st->cr();
|
|
178 }
|
|
179 }
|
|
180
|
|
181
|
|
182 void Disassembler::decode(nmethod* nm, outputStream* st) {
|
|
183 st = st ? st : tty;
|
|
184
|
|
185 st->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm);
|
|
186 st->print("Code:");
|
|
187 st->cr();
|
|
188
|
|
189 if (!load_library()) {
|
|
190 st->print_cr("Could not load disassembler");
|
|
191 return;
|
|
192 }
|
|
193 sparc_env env(nm, st);
|
|
194 unsigned char* p = nm->instructions_begin();
|
|
195 unsigned char* end = nm->instructions_end();
|
|
196 assert ((((intptr_t)p | (intptr_t)end) % sizeof(int) == 0), "misaligned insn addr");
|
|
197
|
|
198 unsigned char *p1 = p;
|
|
199 int total_bucket_count = 0;
|
|
200 while (p1 < end && p1) {
|
|
201 unsigned char *p0 = p1;
|
|
202 ++p1;
|
|
203 address bucket_pc = FlatProfiler::bucket_start_for(p1);
|
|
204 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
|
|
205 total_bucket_count += FlatProfiler::bucket_count_for(p0);
|
|
206 }
|
|
207
|
|
208 while (p < end && p) {
|
|
209 if (p == nm->entry_point()) st->print_cr("[Entry Point]");
|
|
210 if (p == nm->verified_entry_point()) st->print_cr("[Verified Entry Point]");
|
|
211 if (p == nm->exception_begin()) st->print_cr("[Exception Handler]");
|
|
212 if (p == nm->stub_begin()) st->print_cr("[Stub Code]");
|
|
213 if (p == nm->consts_begin()) st->print_cr("[Constants]");
|
|
214 nm->print_block_comment(st, (intptr_t)(p - nm->instructions_begin()));
|
|
215 unsigned char* p0 = p;
|
|
216 st->print(" " INTPTR_FORMAT ": ", p);
|
|
217 p = decode_instruction(p, &env);
|
|
218 nm->print_code_comment_on(st, 40, p0, p);
|
|
219 st->cr();
|
|
220 // Output pc bucket ticks if we have any
|
|
221 address bucket_pc = FlatProfiler::bucket_start_for(p);
|
|
222 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p) {
|
|
223 int bucket_count = FlatProfiler::bucket_count_for(p0);
|
|
224 tty->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_bucket_count, bucket_count);
|
|
225 tty->cr();
|
|
226 }
|
|
227 }
|
|
228 }
|
|
229
|
|
230 #endif // PRODUCT
|