annotate src/cpu/x86/vm/disassembler_x86.cpp @ 71:3d62cb85208d

6662967: Optimize I2D conversion on new x86 Summary: Use CVTDQ2PS and CVTDQ2PD for integer values conversions to float and double values on new AMD cpu. Reviewed-by: sgoldman, never
author kvn
date Wed, 19 Mar 2008 15:33:25 -0700
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_x86.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 void* Disassembler::_library = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 Disassembler::decode_func Disassembler::_decode_instruction = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 bool Disassembler::load_library() {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 if (_library == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 char buf[1024];
a61af66fc99e Initial load
duke
parents:
diff changeset
36 char ebuf[1024];
a61af66fc99e Initial load
duke
parents:
diff changeset
37 sprintf(buf, "disassembler%s", os::dll_file_extension());
a61af66fc99e Initial load
duke
parents:
diff changeset
38 _library = hpi::dll_load(buf, ebuf, sizeof ebuf);
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (_library != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 tty->print_cr("Loaded disassembler");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _decode_instruction = CAST_TO_FN_PTR(Disassembler::decode_func, hpi::dll_lookup(_library, "decode_instruction"));
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44 return (_library != NULL) && (_decode_instruction != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 class x86_env : public DisassemblerEnv {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 nmethod* code;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 outputStream* output;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 x86_env(nmethod* rcode, outputStream* routput) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 code = rcode;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 output = routput;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void print_label(intptr_t value);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 void print_raw(char* str) { output->print_raw(str); }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void print(char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 char* string_for_offset(intptr_t value);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 char* string_for_constant(unsigned char* pc, intptr_t value, int is_decimal);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 };
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void x86_env::print_label(intptr_t value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (!Universe::is_fully_initialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 output->print(INTPTR_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 address adr = (address) value;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (StubRoutines::contains(adr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 const char * desc_name = "unknown stub";
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (desc != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 desc_name = desc->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 output->print("Stub::%s", desc_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (WizardMode) output->print(" " INTPTR_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 output->print(INTPTR_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void x86_env::print(char* format, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 va_list ap;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 va_start(ap, format);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 output->vprint(format, ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 va_end(ap);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 char* x86_env::string_for_offset(intptr_t value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 stringStream st;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (!Universe::is_fully_initialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 st.print(INTX_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return st.as_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 BarrierSet* bs = Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 BarrierSet::Name bsn = bs->kind();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (bs->kind() == BarrierSet::CardTableModRef &&
a61af66fc99e Initial load
duke
parents:
diff changeset
99 (jbyte*) value == ((CardTableModRefBS*)(bs))->byte_map_base) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 st.print("word_map_base");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 st.print(INTX_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return st.as_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 char* x86_env::string_for_constant(unsigned char* pc, intptr_t value, int is_decimal) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 stringStream st;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 oop obj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (code && ((obj = code->embeddedOop_at(pc)) != NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 obj->print_value_on(&st);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (is_decimal == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 st.print(INTX_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 st.print(INTPTR_FORMAT, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return st.as_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 address Disassembler::decode_instruction(address start, DisassemblerEnv* env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return ((decode_func) _decode_instruction)(start, env);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 st = st ? st : tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 st->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 decode(cb->instructions_begin(), cb->instructions_end(), st);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void Disassembler::decode(u_char* begin, u_char* end, outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 st = st ? st : tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 const int show_bytes = false; // for disassembler debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (!load_library()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 st->print_cr("Could not load disassembler");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 x86_env env(NULL, st);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 unsigned char* p = (unsigned char*) begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 CodeBlob* cb = CodeCache::find_blob_unsafe(begin);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 while (p < (unsigned char*) end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (cb != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin()));
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 unsigned char* p0 = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 st->print(" " INTPTR_FORMAT ": ", p);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 p = decode_instruction(p, &env);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (show_bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 st->print("\t\t\t");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 while (p0 < p) st->print("%x ", *p0++);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void Disassembler::decode(nmethod* nm, outputStream* st) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 st = st ? st : tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 st->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 st->print("Code:");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if (!load_library()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 st->print_cr("Could not load disassembler");
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 x86_env env(nm, st);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 unsigned char* p = nm->instructions_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 unsigned char* end = nm->instructions_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 while (p < end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (p == nm->entry_point()) st->print_cr("[Entry Point]");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (p == nm->verified_entry_point()) st->print_cr("[Verified Entry Point]");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (p == nm->exception_begin()) st->print_cr("[Exception Handler]");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (p == nm->stub_begin()) st->print_cr("[Stub Code]");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (p == nm->consts_begin()) st->print_cr("[Constants]");
a61af66fc99e Initial load
duke
parents:
diff changeset
186 nm->print_block_comment(st, (intptr_t)(p - nm->instructions_begin()));
a61af66fc99e Initial load
duke
parents:
diff changeset
187 unsigned char* p0 = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 st->print(" " INTPTR_FORMAT ": ", p);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 p = decode_instruction(p, &env);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 nm->print_code_comment_on(st, 40, p0, p);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Output pc bucket ticks if we have any
a61af66fc99e Initial load
duke
parents:
diff changeset
193 address bucket_pc = FlatProfiler::bucket_start_for(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int bucket_count = FlatProfiler::bucket_count_for(bucket_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 tty->print_cr("[%d]", bucket_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 #endif // PRODUCT