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