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