annotate src/cpu/sparc/vm/disassembler_sparc.cpp @ 84:6e085831cad7

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