src/share/vm/interpreter/bytecodeTracer.cpp

Thu, 17 Mar 2011 18:29:18 -0700

author
jrose
date
Thu, 17 Mar 2011 18:29:18 -0700
changeset 2641
d2134498fd3f
parent 2497
3582bf76420e
child 2742
ed69575596ac
permissions
-rw-r--r--

7011865: JSR 292 CTW fails: !THREAD->is_Compiler_thread() failed: Can not load classes with the Compiler thre
Reviewed-by: kvn, never

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

mercurial