author | jrose |
Wed, 09 Jun 2010 18:50:45 -0700 | |
changeset 5882 | 6b2aecc4f7d8 |
parent 5702 | 201c5cde25bb |
child 6062 | bab93afe9df7 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5702 | 2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
#include "incls/_precompiled.incl" |
|
26 |
#include "incls/_bytecodeTracer.cpp.incl" |
|
27 |
||
28 |
||
29 |
#ifndef PRODUCT |
|
30 |
||
31 |
// Standard closure for BytecodeTracer: prints the current bytecode |
|
32 |
// and its attributes using bytecode-specific information. |
|
33 |
||
34 |
class BytecodePrinter: public BytecodeClosure { |
|
35 |
private: |
|
36 |
// %%% This field is not GC-ed, and so can contain garbage |
|
37 |
// between critical sections. Use only pointer-comparison |
|
38 |
// operations on the pointer, except within a critical section. |
|
39 |
// (Also, ensure that occasional false positives are benign.) |
|
40 |
methodOop _current_method; |
|
41 |
bool _is_wide; |
|
5688 | 42 |
Bytecodes::Code _code; |
1 | 43 |
address _next_pc; // current decoding position |
44 |
||
45 |
void align() { _next_pc = (address)round_to((intptr_t)_next_pc, sizeof(jint)); } |
|
46 |
int get_byte() { return *(jbyte*) _next_pc++; } // signed |
|
47 |
short get_short() { short i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } |
|
48 |
int get_int() { int i=Bytes::get_Java_u4(_next_pc); _next_pc+=4; return i; } |
|
49 |
||
5688 | 50 |
int get_index_u1() { return *(address)_next_pc++; } |
51 |
int get_index_u2() { int i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } |
|
5882 | 52 |
int get_index_u1_cpcache() { return get_index_u1() + constantPoolOopDesc::CPCACHE_INDEX_TAG; } |
5688 | 53 |
int get_index_u2_cpcache() { int i=Bytes::get_native_u2(_next_pc); _next_pc+=2; return i + constantPoolOopDesc::CPCACHE_INDEX_TAG; } |
54 |
int get_index_u4() { int i=Bytes::get_native_u4(_next_pc); _next_pc+=4; return i; } |
|
55 |
int get_index_special() { return (is_wide()) ? get_index_u2() : get_index_u1(); } |
|
1 | 56 |
methodOop method() { return _current_method; } |
57 |
bool is_wide() { return _is_wide; } |
|
5688 | 58 |
Bytecodes::Code raw_code() { return Bytecodes::Code(_code); } |
1 | 59 |
|
60 |
||
5688 | 61 |
bool check_index(int i, int& cp_index, outputStream* st = tty); |
1 | 62 |
void print_constant(int i, outputStream* st = tty); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
63 |
void print_field_or_method(int i, outputStream* st = tty); |
5882 | 64 |
void print_field_or_method(int orig_i, int i, outputStream* st = tty); |
5688 | 65 |
void print_attributes(int bci, outputStream* st = tty); |
1 | 66 |
void bytecode_epilog(int bci, outputStream* st = tty); |
67 |
||
68 |
public: |
|
69 |
BytecodePrinter() { |
|
70 |
_is_wide = false; |
|
5688 | 71 |
_code = Bytecodes::_illegal; |
1 | 72 |
} |
73 |
||
74 |
// This method is called while executing the raw bytecodes, so none of |
|
75 |
// the adjustments that BytecodeStream performs applies. |
|
76 |
void trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { |
|
77 |
ResourceMark rm; |
|
78 |
if (_current_method != method()) { |
|
79 |
// Note 1: This code will not work as expected with true MT/MP. |
|
80 |
// Need an explicit lock or a different solution. |
|
81 |
// It is possible for this block to be skipped, if a garbage |
|
82 |
// _current_method pointer happens to have the same bits as |
|
83 |
// the incoming method. We could lose a line of trace output. |
|
84 |
// This is acceptable in a debug-only feature. |
|
85 |
st->cr(); |
|
86 |
st->print("[%d] ", (int) Thread::current()->osthread()->thread_id()); |
|
87 |
method->print_name(st); |
|
88 |
st->cr(); |
|
89 |
_current_method = method(); |
|
90 |
} |
|
91 |
Bytecodes::Code code; |
|
92 |
if (is_wide()) { |
|
93 |
// bcp wasn't advanced if previous bytecode was _wide. |
|
94 |
code = Bytecodes::code_at(bcp+1); |
|
95 |
} else { |
|
96 |
code = Bytecodes::code_at(bcp); |
|
97 |
} |
|
5688 | 98 |
_code = code; |
99 |
int bci = bcp - method->code_base(); |
|
1 | 100 |
st->print("[%d] ", (int) Thread::current()->osthread()->thread_id()); |
101 |
if (Verbose) { |
|
102 |
st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s", |
|
103 |
BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code)); |
|
104 |
} else { |
|
105 |
st->print("%8d %4d %s", |
|
106 |
BytecodeCounter::counter_value(), bci, Bytecodes::name(code)); |
|
107 |
} |
|
108 |
_next_pc = is_wide() ? bcp+2 : bcp+1; |
|
5688 | 109 |
print_attributes(bci); |
1 | 110 |
// Set is_wide for the next one, since the caller of this doesn't skip |
111 |
// the next bytecode. |
|
112 |
_is_wide = (code == Bytecodes::_wide); |
|
5688 | 113 |
_code = Bytecodes::_illegal; |
1 | 114 |
} |
115 |
||
116 |
// Used for methodOop::print_codes(). The input bcp comes from |
|
117 |
// BytecodeStream, which will skip wide bytecodes. |
|
118 |
void trace(methodHandle method, address bcp, outputStream* st) { |
|
119 |
_current_method = method(); |
|
120 |
ResourceMark rm; |
|
121 |
Bytecodes::Code code = Bytecodes::code_at(bcp); |
|
122 |
// Set is_wide |
|
123 |
_is_wide = (code == Bytecodes::_wide); |
|
124 |
if (is_wide()) { |
|
125 |
code = Bytecodes::code_at(bcp+1); |
|
126 |
} |
|
5688 | 127 |
_code = code; |
1 | 128 |
int bci = bcp - method->code_base(); |
129 |
// Print bytecode index and name |
|
130 |
if (is_wide()) { |
|
131 |
st->print("%d %s_w", bci, Bytecodes::name(code)); |
|
132 |
} else { |
|
133 |
st->print("%d %s", bci, Bytecodes::name(code)); |
|
134 |
} |
|
135 |
_next_pc = is_wide() ? bcp+2 : bcp+1; |
|
5688 | 136 |
print_attributes(bci, st); |
1 | 137 |
bytecode_epilog(bci, st); |
138 |
} |
|
139 |
}; |
|
140 |
||
141 |
||
142 |
// Implementation of BytecodeTracer |
|
143 |
||
144 |
// %%% This set_closure thing seems overly general, given that |
|
145 |
// nobody uses it. Also, if BytecodePrinter weren't hidden |
|
146 |
// then methodOop could use instances of it directly and it |
|
147 |
// would be easier to remove races on _current_method and bcp. |
|
148 |
// Since this is not product functionality, we can defer cleanup. |
|
149 |
||
150 |
BytecodeClosure* BytecodeTracer::_closure = NULL; |
|
151 |
||
152 |
static BytecodePrinter std_closure; |
|
153 |
BytecodeClosure* BytecodeTracer::std_closure() { |
|
154 |
return &::std_closure; |
|
155 |
} |
|
156 |
||
157 |
||
158 |
void BytecodeTracer::trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { |
|
159 |
if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) { |
|
160 |
ttyLocker ttyl; // 5065316: keep the following output coherent |
|
161 |
// The ttyLocker also prevents races between two threads |
|
162 |
// trying to use the single instance of BytecodePrinter. |
|
163 |
// Using the ttyLocker prevents the system from coming to |
|
164 |
// a safepoint within this code, which is sensitive to methodOop |
|
165 |
// movement. |
|
166 |
// |
|
167 |
// There used to be a leaf mutex here, but the ttyLocker will |
|
168 |
// work just as well, as long as the printing operations never block. |
|
169 |
// |
|
170 |
// We put the locker on the static trace method, not the |
|
171 |
// virtual one, because the clients of this module go through |
|
172 |
// the static method. |
|
173 |
_closure->trace(method, bcp, tos, tos2, st); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
void BytecodeTracer::trace(methodHandle method, address bcp, outputStream* st) { |
|
178 |
ttyLocker ttyl; // 5065316: keep the following output coherent |
|
179 |
_closure->trace(method, bcp, st); |
|
180 |
} |
|
181 |
||
5882 | 182 |
void print_symbol(symbolOop sym, outputStream* st) { |
183 |
char buf[40]; |
|
184 |
int len = sym->utf8_length(); |
|
185 |
if (len >= (int)sizeof(buf)) { |
|
186 |
st->print_cr(" %s...[%d]", sym->as_C_string(buf, sizeof(buf)), len); |
|
187 |
} else { |
|
188 |
st->print(" "); |
|
189 |
sym->print_on(st); st->cr(); |
|
190 |
} |
|
191 |
} |
|
192 |
||
1 | 193 |
void print_oop(oop value, outputStream* st) { |
194 |
if (value == NULL) { |
|
195 |
st->print_cr(" NULL"); |
|
5882 | 196 |
} else if (java_lang_String::is_instance(value)) { |
1 | 197 |
EXCEPTION_MARK; |
198 |
Handle h_value (THREAD, value); |
|
199 |
symbolHandle sym = java_lang_String::as_symbol(h_value, CATCH); |
|
5882 | 200 |
print_symbol(sym(), st); |
201 |
} else if (value->is_symbol()) { |
|
202 |
print_symbol(symbolOop(value), st); |
|
203 |
} else { |
|
204 |
st->print_cr(" " PTR_FORMAT, (intptr_t) value); |
|
1 | 205 |
} |
206 |
} |
|
207 |
||
5688 | 208 |
bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
209 |
constantPoolOop constants = method()->constants(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
210 |
int ilimit = constants->length(), climit = 0; |
5688 | 211 |
Bytecodes::Code code = raw_code(); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
212 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
213 |
constantPoolCacheOop cache = NULL; |
5688 | 214 |
if (Bytecodes::uses_cp_cache(code)) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
215 |
cache = constants->cache(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
216 |
if (cache != NULL) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
217 |
//climit = cache->length(); // %%% private! |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
218 |
size_t size = cache->size() * HeapWordSize; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
219 |
size -= sizeof(constantPoolCacheOopDesc); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
220 |
size /= sizeof(ConstantPoolCacheEntry); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
221 |
climit = (int) size; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
222 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
223 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
224 |
|
5688 | 225 |
if (cache != NULL && constantPoolCacheOopDesc::is_secondary_index(i)) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
226 |
i = constantPoolCacheOopDesc::decode_secondary_index(i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
227 |
st->print(" secondary cache[%d] of", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
228 |
if (i >= 0 && i < climit) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
229 |
if (!cache->entry_at(i)->is_secondary_entry()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
230 |
st->print_cr(" not secondary entry?", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
231 |
return false; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
232 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
233 |
i = cache->entry_at(i)->main_entry_index(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
234 |
goto check_cache_index; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
235 |
} else { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
236 |
st->print_cr(" not in cache[*]?", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
237 |
return false; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
238 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
239 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
240 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
241 |
if (cache != NULL) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
242 |
goto check_cache_index; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
243 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
244 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
245 |
check_cp_index: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
246 |
if (i >= 0 && i < ilimit) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
247 |
if (WizardMode) st->print(" cp[%d]", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
248 |
cp_index = i; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
249 |
return true; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
250 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
251 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
252 |
st->print_cr(" CP[%d] not in CP", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
253 |
return false; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
254 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
255 |
check_cache_index: |
5688 | 256 |
#ifdef ASSERT |
257 |
{ |
|
258 |
const int CPCACHE_INDEX_TAG = constantPoolOopDesc::CPCACHE_INDEX_TAG; |
|
259 |
if (i >= CPCACHE_INDEX_TAG && i < climit + CPCACHE_INDEX_TAG) { |
|
260 |
i -= CPCACHE_INDEX_TAG; |
|
261 |
} else { |
|
262 |
st->print_cr(" CP[%d] missing bias?", i); |
|
263 |
return false; |
|
264 |
} |
|
265 |
} |
|
266 |
#endif //ASSERT |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
267 |
if (i >= 0 && i < climit) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
268 |
if (cache->entry_at(i)->is_secondary_entry()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
269 |
st->print_cr(" secondary entry?"); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
270 |
return false; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
271 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
272 |
i = cache->entry_at(i)->constant_pool_index(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
273 |
goto check_cp_index; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
274 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
275 |
st->print_cr(" not in CP[*]?", i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
276 |
return false; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
277 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
278 |
|
1 | 279 |
void BytecodePrinter::print_constant(int i, outputStream* st) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
280 |
int orig_i = i; |
5688 | 281 |
if (!check_index(orig_i, i, st)) return; |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
282 |
|
1 | 283 |
constantPoolOop constants = method()->constants(); |
284 |
constantTag tag = constants->tag_at(i); |
|
285 |
||
286 |
if (tag.is_int()) { |
|
287 |
st->print_cr(" " INT32_FORMAT, constants->int_at(i)); |
|
288 |
} else if (tag.is_long()) { |
|
289 |
st->print_cr(" " INT64_FORMAT, constants->long_at(i)); |
|
290 |
} else if (tag.is_float()) { |
|
291 |
st->print_cr(" %f", constants->float_at(i)); |
|
292 |
} else if (tag.is_double()) { |
|
293 |
st->print_cr(" %f", constants->double_at(i)); |
|
294 |
} else if (tag.is_string()) { |
|
5882 | 295 |
oop string = constants->pseudo_string_at(i); |
1 | 296 |
print_oop(string, st); |
297 |
} else if (tag.is_unresolved_string()) { |
|
5882 | 298 |
const char* string = constants->string_at_noresolve(i); |
299 |
st->print_cr(" %s", string); |
|
1 | 300 |
} else if (tag.is_klass()) { |
301 |
st->print_cr(" %s", constants->resolved_klass_at(i)->klass_part()->external_name()); |
|
302 |
} else if (tag.is_unresolved_klass()) { |
|
303 |
st->print_cr(" <unresolved klass at %d>", i); |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
304 |
} else if (tag.is_object()) { |
5882 | 305 |
st->print(" <Object>"); |
306 |
print_oop(constants->object_at(i), st); |
|
307 |
} else if (tag.is_method_type()) { |
|
308 |
int i2 = constants->method_type_index_at(i); |
|
309 |
st->print(" <MethodType> %d", i2); |
|
310 |
print_oop(constants->symbol_at(i2), st); |
|
311 |
} else if (tag.is_method_handle()) { |
|
312 |
int kind = constants->method_handle_ref_kind_at(i); |
|
313 |
int i2 = constants->method_handle_index_at(i); |
|
314 |
st->print(" <MethodHandle of kind %d>", kind, i2); |
|
315 |
print_field_or_method(-i, i2, st); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
316 |
} else { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
317 |
st->print_cr(" bad tag=%d at %d", tag.value(), i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
318 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
319 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
320 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
321 |
void BytecodePrinter::print_field_or_method(int i, outputStream* st) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
322 |
int orig_i = i; |
5688 | 323 |
if (!check_index(orig_i, i, st)) return; |
5882 | 324 |
print_field_or_method(orig_i, i, st); |
325 |
} |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
326 |
|
5882 | 327 |
void BytecodePrinter::print_field_or_method(int orig_i, int i, outputStream* st) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
328 |
constantPoolOop constants = method()->constants(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
329 |
constantTag tag = constants->tag_at(i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
330 |
|
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
331 |
int nt_index = -1; |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
332 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
333 |
switch (tag.value()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
334 |
case JVM_CONSTANT_InterfaceMethodref: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
335 |
case JVM_CONSTANT_Methodref: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
336 |
case JVM_CONSTANT_Fieldref: |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
337 |
case JVM_CONSTANT_NameAndType: |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
338 |
break; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
339 |
default: |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
340 |
st->print_cr(" bad tag=%d at %d", tag.value(), i); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
341 |
return; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
342 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
343 |
|
5882 | 344 |
symbolOop klass = constants->klass_name_at(constants->uncached_klass_ref_index_at(i)); |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
345 |
symbolOop name = constants->uncached_name_ref_at(i); |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
346 |
symbolOop signature = constants->uncached_signature_ref_at(i); |
5882 | 347 |
const char* sep = (tag.is_field() ? "/" : ""); |
348 |
st->print_cr(" %d <%s.%s%s%s> ", i, klass->as_C_string(), name->as_C_string(), sep, signature->as_C_string()); |
|
1 | 349 |
} |
350 |
||
351 |
||
5688 | 352 |
void BytecodePrinter::print_attributes(int bci, outputStream* st) { |
1 | 353 |
// Show attributes of pre-rewritten codes |
5688 | 354 |
Bytecodes::Code code = Bytecodes::java_code(raw_code()); |
1 | 355 |
// If the code doesn't have any fields there's nothing to print. |
356 |
// note this is ==1 because the tableswitch and lookupswitch are |
|
357 |
// zero size (for some reason) and we want to print stuff out for them. |
|
358 |
if (Bytecodes::length_for(code) == 1) { |
|
359 |
st->cr(); |
|
360 |
return; |
|
361 |
} |
|
362 |
||
363 |
switch(code) { |
|
364 |
// Java specific bytecodes only matter. |
|
365 |
case Bytecodes::_bipush: |
|
366 |
st->print_cr(" " INT32_FORMAT, get_byte()); |
|
367 |
break; |
|
368 |
case Bytecodes::_sipush: |
|
369 |
st->print_cr(" " INT32_FORMAT, get_short()); |
|
370 |
break; |
|
371 |
case Bytecodes::_ldc: |
|
5882 | 372 |
if (Bytecodes::uses_cp_cache(raw_code())) { |
373 |
print_constant(get_index_u1_cpcache(), st); |
|
374 |
} else { |
|
375 |
print_constant(get_index_u1(), st); |
|
376 |
} |
|
1 | 377 |
break; |
378 |
||
379 |
case Bytecodes::_ldc_w: |
|
380 |
case Bytecodes::_ldc2_w: |
|
5882 | 381 |
if (Bytecodes::uses_cp_cache(raw_code())) { |
382 |
print_constant(get_index_u2_cpcache(), st); |
|
383 |
} else { |
|
384 |
print_constant(get_index_u2(), st); |
|
385 |
} |
|
1 | 386 |
break; |
387 |
||
388 |
case Bytecodes::_iload: |
|
389 |
case Bytecodes::_lload: |
|
390 |
case Bytecodes::_fload: |
|
391 |
case Bytecodes::_dload: |
|
392 |
case Bytecodes::_aload: |
|
393 |
case Bytecodes::_istore: |
|
394 |
case Bytecodes::_lstore: |
|
395 |
case Bytecodes::_fstore: |
|
396 |
case Bytecodes::_dstore: |
|
397 |
case Bytecodes::_astore: |
|
398 |
st->print_cr(" #%d", get_index_special()); |
|
399 |
break; |
|
400 |
||
401 |
case Bytecodes::_iinc: |
|
402 |
{ int index = get_index_special(); |
|
403 |
jint offset = is_wide() ? get_short(): get_byte(); |
|
404 |
st->print_cr(" #%d " INT32_FORMAT, index, offset); |
|
405 |
} |
|
406 |
break; |
|
407 |
||
408 |
case Bytecodes::_newarray: { |
|
5688 | 409 |
BasicType atype = (BasicType)get_index_u1(); |
1 | 410 |
const char* str = type2name(atype); |
411 |
if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) { |
|
412 |
assert(false, "Unidentified basic type"); |
|
413 |
} |
|
414 |
st->print_cr(" %s", str); |
|
415 |
} |
|
416 |
break; |
|
417 |
case Bytecodes::_anewarray: { |
|
5688 | 418 |
int klass_index = get_index_u2(); |
1 | 419 |
constantPoolOop constants = method()->constants(); |
420 |
symbolOop name = constants->klass_name_at(klass_index); |
|
421 |
st->print_cr(" %s ", name->as_C_string()); |
|
422 |
} |
|
423 |
break; |
|
424 |
case Bytecodes::_multianewarray: { |
|
5688 | 425 |
int klass_index = get_index_u2(); |
426 |
int nof_dims = get_index_u1(); |
|
1 | 427 |
constantPoolOop constants = method()->constants(); |
428 |
symbolOop name = constants->klass_name_at(klass_index); |
|
429 |
st->print_cr(" %s %d", name->as_C_string(), nof_dims); |
|
430 |
} |
|
431 |
break; |
|
432 |
||
433 |
case Bytecodes::_ifeq: |
|
434 |
case Bytecodes::_ifnull: |
|
435 |
case Bytecodes::_iflt: |
|
436 |
case Bytecodes::_ifle: |
|
437 |
case Bytecodes::_ifne: |
|
438 |
case Bytecodes::_ifnonnull: |
|
439 |
case Bytecodes::_ifgt: |
|
440 |
case Bytecodes::_ifge: |
|
441 |
case Bytecodes::_if_icmpeq: |
|
442 |
case Bytecodes::_if_icmpne: |
|
443 |
case Bytecodes::_if_icmplt: |
|
444 |
case Bytecodes::_if_icmpgt: |
|
445 |
case Bytecodes::_if_icmple: |
|
446 |
case Bytecodes::_if_icmpge: |
|
447 |
case Bytecodes::_if_acmpeq: |
|
448 |
case Bytecodes::_if_acmpne: |
|
449 |
case Bytecodes::_goto: |
|
450 |
case Bytecodes::_jsr: |
|
451 |
st->print_cr(" %d", bci + get_short()); |
|
452 |
break; |
|
453 |
||
454 |
case Bytecodes::_goto_w: |
|
455 |
case Bytecodes::_jsr_w: |
|
456 |
st->print_cr(" %d", bci + get_int()); |
|
457 |
break; |
|
458 |
||
459 |
case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break; |
|
460 |
||
461 |
case Bytecodes::_tableswitch: |
|
462 |
{ align(); |
|
463 |
int default_dest = bci + get_int(); |
|
464 |
int lo = get_int(); |
|
465 |
int hi = get_int(); |
|
466 |
int len = hi - lo + 1; |
|
467 |
jint* dest = NEW_RESOURCE_ARRAY(jint, len); |
|
468 |
for (int i = 0; i < len; i++) { |
|
469 |
dest[i] = bci + get_int(); |
|
470 |
} |
|
471 |
st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ", |
|
472 |
default_dest, lo, hi); |
|
473 |
int first = true; |
|
474 |
for (int ll = lo; ll <= hi; ll++, first = false) { |
|
475 |
int idx = ll - lo; |
|
476 |
const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" : |
|
477 |
", %d:" INT32_FORMAT " (delta: %d)"; |
|
478 |
st->print(format, ll, dest[idx], dest[idx]-bci); |
|
479 |
} |
|
480 |
st->cr(); |
|
481 |
} |
|
482 |
break; |
|
483 |
case Bytecodes::_lookupswitch: |
|
484 |
{ align(); |
|
485 |
int default_dest = bci + get_int(); |
|
486 |
int len = get_int(); |
|
487 |
jint* key = NEW_RESOURCE_ARRAY(jint, len); |
|
488 |
jint* dest = NEW_RESOURCE_ARRAY(jint, len); |
|
489 |
for (int i = 0; i < len; i++) { |
|
490 |
key [i] = get_int(); |
|
491 |
dest[i] = bci + get_int(); |
|
492 |
}; |
|
493 |
st->print(" %d %d ", default_dest, len); |
|
494 |
bool first = true; |
|
495 |
for (int ll = 0; ll < len; ll++, first = false) { |
|
496 |
const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT : |
|
497 |
", " INT32_FORMAT ":" INT32_FORMAT ; |
|
498 |
st->print(format, key[ll], dest[ll]); |
|
499 |
} |
|
500 |
st->cr(); |
|
501 |
} |
|
502 |
break; |
|
503 |
||
504 |
case Bytecodes::_putstatic: |
|
505 |
case Bytecodes::_getstatic: |
|
506 |
case Bytecodes::_putfield: |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
507 |
case Bytecodes::_getfield: |
5688 | 508 |
print_field_or_method(get_index_u2_cpcache(), st); |
1 | 509 |
break; |
510 |
||
511 |
case Bytecodes::_invokevirtual: |
|
512 |
case Bytecodes::_invokespecial: |
|
513 |
case Bytecodes::_invokestatic: |
|
5688 | 514 |
print_field_or_method(get_index_u2_cpcache(), st); |
1 | 515 |
break; |
516 |
||
517 |
case Bytecodes::_invokeinterface: |
|
5688 | 518 |
{ int i = get_index_u2_cpcache(); |
519 |
int n = get_index_u1(); |
|
520 |
get_byte(); // ignore zero byte |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
521 |
print_field_or_method(i, st); |
1 | 522 |
} |
523 |
break; |
|
524 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
525 |
case Bytecodes::_invokedynamic: |
5688 | 526 |
print_field_or_method(get_index_u4(), st); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
527 |
break; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
528 |
|
1 | 529 |
case Bytecodes::_new: |
530 |
case Bytecodes::_checkcast: |
|
531 |
case Bytecodes::_instanceof: |
|
5688 | 532 |
{ int i = get_index_u2(); |
1 | 533 |
constantPoolOop constants = method()->constants(); |
534 |
symbolOop name = constants->klass_name_at(i); |
|
535 |
st->print_cr(" %d <%s>", i, name->as_C_string()); |
|
536 |
} |
|
537 |
break; |
|
538 |
||
539 |
case Bytecodes::_wide: |
|
540 |
// length is zero not one, but printed with no more info. |
|
541 |
break; |
|
542 |
||
543 |
default: |
|
544 |
ShouldNotReachHere(); |
|
545 |
break; |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
||
550 |
void BytecodePrinter::bytecode_epilog(int bci, outputStream* st) { |
|
551 |
methodDataOop mdo = method()->method_data(); |
|
552 |
if (mdo != NULL) { |
|
553 |
ProfileData* data = mdo->bci_to_data(bci); |
|
554 |
if (data != NULL) { |
|
555 |
st->print(" %d", mdo->dp_to_di(data->dp())); |
|
556 |
st->fill_to(6); |
|
557 |
data->print_data_on(st); |
|
558 |
} |
|
559 |
} |
|
560 |
} |
|
561 |
#endif // PRODUCT |