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