Mercurial > hg > graal-compiler
annotate src/share/vm/interpreter/bytecodeTracer.cpp @ 1662:e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
Reviewed-by: kvn
author | jrose |
---|---|
date | Fri, 16 Jul 2010 18:14:19 -0700 |
parents | 083fde3b838e |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1579 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
21 * questions. |
0 | 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; | |
1565 | 42 Bytecodes::Code _code; |
0 | 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 | |
1565 | 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; } | |
1602 | 52 int get_index_u1_cpcache() { return get_index_u1() + constantPoolOopDesc::CPCACHE_INDEX_TAG; } |
1565 | 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(); } | |
0 | 56 methodOop method() { return _current_method; } |
57 bool is_wide() { return _is_wide; } | |
1565 | 58 Bytecodes::Code raw_code() { return Bytecodes::Code(_code); } |
0 | 59 |
60 | |
1565 | 61 bool check_index(int i, int& cp_index, outputStream* st = tty); |
0 | 62 void print_constant(int i, outputStream* st = tty); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
63 void print_field_or_method(int i, outputStream* st = tty); |
1602 | 64 void print_field_or_method(int orig_i, int i, outputStream* st = tty); |
1565 | 65 void print_attributes(int bci, outputStream* st = tty); |
0 | 66 void bytecode_epilog(int bci, outputStream* st = tty); |
67 | |
68 public: | |
69 BytecodePrinter() { | |
70 _is_wide = false; | |
1565 | 71 _code = Bytecodes::_illegal; |
0 | 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 } | |
1565 | 98 _code = code; |
99 int bci = bcp - method->code_base(); | |
0 | 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; | |
1565 | 109 print_attributes(bci); |
0 | 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); | |
1565 | 113 _code = Bytecodes::_illegal; |
0 | 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 } | |
1565 | 127 _code = code; |
0 | 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; | |
1565 | 136 print_attributes(bci, st); |
0 | 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 | |
1602 | 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 | |
0 | 193 void print_oop(oop value, outputStream* st) { |
194 if (value == NULL) { | |
195 st->print_cr(" NULL"); | |
1602 | 196 } else if (java_lang_String::is_instance(value)) { |
0 | 197 EXCEPTION_MARK; |
198 Handle h_value (THREAD, value); | |
199 symbolHandle sym = java_lang_String::as_symbol(h_value, CATCH); | |
1602 | 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); | |
0 | 205 } |
206 } | |
207 | |
1565 | 208 bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
209 constantPoolOop constants = method()->constants(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
210 int ilimit = constants->length(), climit = 0; |
1565 | 211 Bytecodes::Code code = raw_code(); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
212 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
213 constantPoolCacheOop cache = NULL; |
1565 | 214 if (Bytecodes::uses_cp_cache(code)) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
215 cache = constants->cache(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
216 if (cache != NULL) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
217 //climit = cache->length(); // %%% private! |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
218 size_t size = cache->size() * HeapWordSize; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
219 size -= sizeof(constantPoolCacheOopDesc); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
220 size /= sizeof(ConstantPoolCacheEntry); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
221 climit = (int) size; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
222 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
223 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
224 |
1565 | 225 if (cache != NULL && constantPoolCacheOopDesc::is_secondary_index(i)) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
226 i = constantPoolCacheOopDesc::decode_secondary_index(i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
227 st->print(" secondary cache[%d] of", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
228 if (i >= 0 && i < climit) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
229 if (!cache->entry_at(i)->is_secondary_entry()) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
230 st->print_cr(" not secondary entry?", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
231 return false; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
232 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
233 i = cache->entry_at(i)->main_entry_index(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
234 goto check_cache_index; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
235 } else { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
236 st->print_cr(" not in cache[*]?", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
237 return false; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
238 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
239 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
240 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
241 if (cache != NULL) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
242 goto check_cache_index; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
243 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
244 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
245 check_cp_index: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
246 if (i >= 0 && i < ilimit) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
247 if (WizardMode) st->print(" cp[%d]", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
248 cp_index = i; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
249 return true; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
250 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
251 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
252 st->print_cr(" CP[%d] not in CP", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
253 return false; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
254 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
255 check_cache_index: |
1565 | 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 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
267 if (i >= 0 && i < climit) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
268 if (cache->entry_at(i)->is_secondary_entry()) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
269 st->print_cr(" secondary entry?"); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
270 return false; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
271 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
272 i = cache->entry_at(i)->constant_pool_index(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
273 goto check_cp_index; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
274 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
275 st->print_cr(" not in CP[*]?", i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
276 return false; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
277 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
278 |
0 | 279 void BytecodePrinter::print_constant(int i, outputStream* st) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
280 int orig_i = i; |
1565 | 281 if (!check_index(orig_i, i, st)) return; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
282 |
0 | 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()) { | |
1602 | 295 oop string = constants->pseudo_string_at(i); |
0 | 296 print_oop(string, st); |
297 } else if (tag.is_unresolved_string()) { | |
1602 | 298 const char* string = constants->string_at_noresolve(i); |
299 st->print_cr(" %s", string); | |
0 | 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); | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
304 } else if (tag.is_object()) { |
1602 | 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); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
316 } else { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
317 st->print_cr(" bad tag=%d at %d", tag.value(), i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
318 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
319 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
320 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
321 void BytecodePrinter::print_field_or_method(int i, outputStream* st) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
322 int orig_i = i; |
1565 | 323 if (!check_index(orig_i, i, st)) return; |
1602 | 324 print_field_or_method(orig_i, i, st); |
325 } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
326 |
1602 | 327 void BytecodePrinter::print_field_or_method(int orig_i, int i, outputStream* st) { |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
328 constantPoolOop constants = method()->constants(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
329 constantTag tag = constants->tag_at(i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
330 |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
331 bool has_klass = true; |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
844
diff
changeset
|
332 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
333 switch (tag.value()) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
334 case JVM_CONSTANT_InterfaceMethodref: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
335 case JVM_CONSTANT_Methodref: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
336 case JVM_CONSTANT_Fieldref: |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
337 break; |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
844
diff
changeset
|
338 case JVM_CONSTANT_NameAndType: |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
339 case JVM_CONSTANT_InvokeDynamic: |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
340 has_klass = false; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
341 break; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
342 default: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
343 st->print_cr(" bad tag=%d at %d", tag.value(), i); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
344 return; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
345 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
346 |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
844
diff
changeset
|
347 symbolOop name = constants->uncached_name_ref_at(i); |
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
844
diff
changeset
|
348 symbolOop signature = constants->uncached_signature_ref_at(i); |
1602 | 349 const char* sep = (tag.is_field() ? "/" : ""); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
350 if (has_klass) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
351 symbolOop klass = constants->klass_name_at(constants->uncached_klass_ref_index_at(i)); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
352 st->print_cr(" %d <%s.%s%s%s> ", i, klass->as_C_string(), name->as_C_string(), sep, signature->as_C_string()); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
353 } else { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
354 if (tag.is_invoke_dynamic()) { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
355 int bsm = constants->invoke_dynamic_bootstrap_method_ref_index_at(i); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
356 st->print(" bsm=%d", bsm); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
357 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
358 st->print_cr(" %d <%s%s%s>", i, name->as_C_string(), sep, signature->as_C_string()); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1602
diff
changeset
|
359 } |
0 | 360 } |
361 | |
362 | |
1565 | 363 void BytecodePrinter::print_attributes(int bci, outputStream* st) { |
0 | 364 // Show attributes of pre-rewritten codes |
1565 | 365 Bytecodes::Code code = Bytecodes::java_code(raw_code()); |
0 | 366 // If the code doesn't have any fields there's nothing to print. |
367 // note this is ==1 because the tableswitch and lookupswitch are | |
368 // zero size (for some reason) and we want to print stuff out for them. | |
369 if (Bytecodes::length_for(code) == 1) { | |
370 st->cr(); | |
371 return; | |
372 } | |
373 | |
374 switch(code) { | |
375 // Java specific bytecodes only matter. | |
376 case Bytecodes::_bipush: | |
377 st->print_cr(" " INT32_FORMAT, get_byte()); | |
378 break; | |
379 case Bytecodes::_sipush: | |
380 st->print_cr(" " INT32_FORMAT, get_short()); | |
381 break; | |
382 case Bytecodes::_ldc: | |
1602 | 383 if (Bytecodes::uses_cp_cache(raw_code())) { |
384 print_constant(get_index_u1_cpcache(), st); | |
385 } else { | |
386 print_constant(get_index_u1(), st); | |
387 } | |
0 | 388 break; |
389 | |
390 case Bytecodes::_ldc_w: | |
391 case Bytecodes::_ldc2_w: | |
1602 | 392 if (Bytecodes::uses_cp_cache(raw_code())) { |
393 print_constant(get_index_u2_cpcache(), st); | |
394 } else { | |
395 print_constant(get_index_u2(), st); | |
396 } | |
0 | 397 break; |
398 | |
399 case Bytecodes::_iload: | |
400 case Bytecodes::_lload: | |
401 case Bytecodes::_fload: | |
402 case Bytecodes::_dload: | |
403 case Bytecodes::_aload: | |
404 case Bytecodes::_istore: | |
405 case Bytecodes::_lstore: | |
406 case Bytecodes::_fstore: | |
407 case Bytecodes::_dstore: | |
408 case Bytecodes::_astore: | |
409 st->print_cr(" #%d", get_index_special()); | |
410 break; | |
411 | |
412 case Bytecodes::_iinc: | |
413 { int index = get_index_special(); | |
414 jint offset = is_wide() ? get_short(): get_byte(); | |
415 st->print_cr(" #%d " INT32_FORMAT, index, offset); | |
416 } | |
417 break; | |
418 | |
419 case Bytecodes::_newarray: { | |
1565 | 420 BasicType atype = (BasicType)get_index_u1(); |
0 | 421 const char* str = type2name(atype); |
422 if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) { | |
423 assert(false, "Unidentified basic type"); | |
424 } | |
425 st->print_cr(" %s", str); | |
426 } | |
427 break; | |
428 case Bytecodes::_anewarray: { | |
1565 | 429 int klass_index = get_index_u2(); |
0 | 430 constantPoolOop constants = method()->constants(); |
431 symbolOop name = constants->klass_name_at(klass_index); | |
432 st->print_cr(" %s ", name->as_C_string()); | |
433 } | |
434 break; | |
435 case Bytecodes::_multianewarray: { | |
1565 | 436 int klass_index = get_index_u2(); |
437 int nof_dims = get_index_u1(); | |
0 | 438 constantPoolOop constants = method()->constants(); |
439 symbolOop name = constants->klass_name_at(klass_index); | |
440 st->print_cr(" %s %d", name->as_C_string(), nof_dims); | |
441 } | |
442 break; | |
443 | |
444 case Bytecodes::_ifeq: | |
445 case Bytecodes::_ifnull: | |
446 case Bytecodes::_iflt: | |
447 case Bytecodes::_ifle: | |
448 case Bytecodes::_ifne: | |
449 case Bytecodes::_ifnonnull: | |
450 case Bytecodes::_ifgt: | |
451 case Bytecodes::_ifge: | |
452 case Bytecodes::_if_icmpeq: | |
453 case Bytecodes::_if_icmpne: | |
454 case Bytecodes::_if_icmplt: | |
455 case Bytecodes::_if_icmpgt: | |
456 case Bytecodes::_if_icmple: | |
457 case Bytecodes::_if_icmpge: | |
458 case Bytecodes::_if_acmpeq: | |
459 case Bytecodes::_if_acmpne: | |
460 case Bytecodes::_goto: | |
461 case Bytecodes::_jsr: | |
462 st->print_cr(" %d", bci + get_short()); | |
463 break; | |
464 | |
465 case Bytecodes::_goto_w: | |
466 case Bytecodes::_jsr_w: | |
467 st->print_cr(" %d", bci + get_int()); | |
468 break; | |
469 | |
470 case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break; | |
471 | |
472 case Bytecodes::_tableswitch: | |
473 { align(); | |
474 int default_dest = bci + get_int(); | |
475 int lo = get_int(); | |
476 int hi = get_int(); | |
477 int len = hi - lo + 1; | |
478 jint* dest = NEW_RESOURCE_ARRAY(jint, len); | |
479 for (int i = 0; i < len; i++) { | |
480 dest[i] = bci + get_int(); | |
481 } | |
482 st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ", | |
483 default_dest, lo, hi); | |
484 int first = true; | |
485 for (int ll = lo; ll <= hi; ll++, first = false) { | |
486 int idx = ll - lo; | |
487 const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" : | |
488 ", %d:" INT32_FORMAT " (delta: %d)"; | |
489 st->print(format, ll, dest[idx], dest[idx]-bci); | |
490 } | |
491 st->cr(); | |
492 } | |
493 break; | |
494 case Bytecodes::_lookupswitch: | |
495 { align(); | |
496 int default_dest = bci + get_int(); | |
497 int len = get_int(); | |
498 jint* key = NEW_RESOURCE_ARRAY(jint, len); | |
499 jint* dest = NEW_RESOURCE_ARRAY(jint, len); | |
500 for (int i = 0; i < len; i++) { | |
501 key [i] = get_int(); | |
502 dest[i] = bci + get_int(); | |
503 }; | |
504 st->print(" %d %d ", default_dest, len); | |
505 bool first = true; | |
506 for (int ll = 0; ll < len; ll++, first = false) { | |
507 const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT : | |
508 ", " INT32_FORMAT ":" INT32_FORMAT ; | |
509 st->print(format, key[ll], dest[ll]); | |
510 } | |
511 st->cr(); | |
512 } | |
513 break; | |
514 | |
515 case Bytecodes::_putstatic: | |
516 case Bytecodes::_getstatic: | |
517 case Bytecodes::_putfield: | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
518 case Bytecodes::_getfield: |
1565 | 519 print_field_or_method(get_index_u2_cpcache(), st); |
0 | 520 break; |
521 | |
522 case Bytecodes::_invokevirtual: | |
523 case Bytecodes::_invokespecial: | |
524 case Bytecodes::_invokestatic: | |
1565 | 525 print_field_or_method(get_index_u2_cpcache(), st); |
0 | 526 break; |
527 | |
528 case Bytecodes::_invokeinterface: | |
1565 | 529 { int i = get_index_u2_cpcache(); |
530 int n = get_index_u1(); | |
531 get_byte(); // ignore zero byte | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
532 print_field_or_method(i, st); |
0 | 533 } |
534 break; | |
535 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
536 case Bytecodes::_invokedynamic: |
1565 | 537 print_field_or_method(get_index_u4(), st); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
538 break; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
539 |
0 | 540 case Bytecodes::_new: |
541 case Bytecodes::_checkcast: | |
542 case Bytecodes::_instanceof: | |
1565 | 543 { int i = get_index_u2(); |
0 | 544 constantPoolOop constants = method()->constants(); |
545 symbolOop name = constants->klass_name_at(i); | |
546 st->print_cr(" %d <%s>", i, name->as_C_string()); | |
547 } | |
548 break; | |
549 | |
550 case Bytecodes::_wide: | |
551 // length is zero not one, but printed with no more info. | |
552 break; | |
553 | |
554 default: | |
555 ShouldNotReachHere(); | |
556 break; | |
557 } | |
558 } | |
559 | |
560 | |
561 void BytecodePrinter::bytecode_epilog(int bci, outputStream* st) { | |
562 methodDataOop mdo = method()->method_data(); | |
563 if (mdo != NULL) { | |
564 ProfileData* data = mdo->bci_to_data(bci); | |
565 if (data != NULL) { | |
566 st->print(" %d", mdo->dp_to_di(data->dp())); | |
567 st->fill_to(6); | |
568 data->print_data_on(st); | |
569 } | |
570 } | |
571 } | |
572 #endif // PRODUCT |