src/share/vm/interpreter/bytecodeTracer.cpp

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 4643
f16e75e0cf11
child 6377
b8413a9cbb84
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

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

mercurial