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