duke@435: /* coleenp@4643: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "interpreter/bytecodeHistogram.hpp" stefank@2314: #include "interpreter/bytecodeTracer.hpp" stefank@2314: #include "interpreter/bytecodes.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/interpreterRuntime.hpp" stefank@2314: #include "memory/resourceArea.hpp" coleenp@4037: #include "oops/methodData.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: #include "runtime/mutexLocker.hpp" stefank@2314: #include "runtime/timer.hpp" duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: // Standard closure for BytecodeTracer: prints the current bytecode duke@435: // and its attributes using bytecode-specific information. duke@435: duke@435: class BytecodePrinter: public BytecodeClosure { duke@435: private: duke@435: // %%% This field is not GC-ed, and so can contain garbage duke@435: // between critical sections. Use only pointer-comparison duke@435: // operations on the pointer, except within a critical section. duke@435: // (Also, ensure that occasional false positives are benign.) coleenp@4037: Method* _current_method; duke@435: bool _is_wide; jrose@1920: Bytecodes::Code _code; duke@435: address _next_pc; // current decoding position duke@435: duke@435: void align() { _next_pc = (address)round_to((intptr_t)_next_pc, sizeof(jint)); } duke@435: int get_byte() { return *(jbyte*) _next_pc++; } // signed duke@435: short get_short() { short i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } duke@435: int get_int() { int i=Bytes::get_Java_u4(_next_pc); _next_pc+=4; return i; } duke@435: jrose@1920: int get_index_u1() { return *(address)_next_pc++; } jrose@1920: int get_index_u2() { int i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } coleenp@4037: int get_index_u1_cpcache() { return get_index_u1() + ConstantPool::CPCACHE_INDEX_TAG; } coleenp@4037: int get_index_u2_cpcache() { int i=Bytes::get_native_u2(_next_pc); _next_pc+=2; return i + ConstantPool::CPCACHE_INDEX_TAG; } jrose@1920: int get_index_u4() { int i=Bytes::get_native_u4(_next_pc); _next_pc+=4; return i; } jrose@1920: int get_index_special() { return (is_wide()) ? get_index_u2() : get_index_u1(); } coleenp@4037: Method* method() { return _current_method; } duke@435: bool is_wide() { return _is_wide; } jrose@1920: Bytecodes::Code raw_code() { return Bytecodes::Code(_code); } duke@435: duke@435: jrose@1920: bool check_index(int i, int& cp_index, outputStream* st = tty); coleenp@4037: bool check_cp_cache_index(int i, int& cp_index, outputStream* st = tty); coleenp@4037: bool check_obj_index(int i, int& cp_index, outputStream* st = tty); coleenp@4037: bool check_invokedynamic_index(int i, int& cp_index, outputStream* st = tty); duke@435: void print_constant(int i, outputStream* st = tty); jrose@1161: void print_field_or_method(int i, outputStream* st = tty); jrose@1957: void print_field_or_method(int orig_i, int i, outputStream* st = tty); jrose@1920: void print_attributes(int bci, outputStream* st = tty); duke@435: void bytecode_epilog(int bci, outputStream* st = tty); duke@435: duke@435: public: duke@435: BytecodePrinter() { duke@435: _is_wide = false; jrose@1920: _code = Bytecodes::_illegal; duke@435: } duke@435: duke@435: // This method is called while executing the raw bytecodes, so none of duke@435: // the adjustments that BytecodeStream performs applies. duke@435: void trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { duke@435: ResourceMark rm; duke@435: if (_current_method != method()) { duke@435: // Note 1: This code will not work as expected with true MT/MP. duke@435: // Need an explicit lock or a different solution. duke@435: // It is possible for this block to be skipped, if a garbage duke@435: // _current_method pointer happens to have the same bits as duke@435: // the incoming method. We could lose a line of trace output. duke@435: // This is acceptable in a debug-only feature. duke@435: st->cr(); never@3156: st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id()); duke@435: method->print_name(st); duke@435: st->cr(); duke@435: _current_method = method(); duke@435: } duke@435: Bytecodes::Code code; duke@435: if (is_wide()) { duke@435: // bcp wasn't advanced if previous bytecode was _wide. never@2462: code = Bytecodes::code_at(method(), bcp+1); duke@435: } else { never@2462: code = Bytecodes::code_at(method(), bcp); duke@435: } jrose@1920: _code = code; jrose@1920: int bci = bcp - method->code_base(); never@3156: st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id()); duke@435: if (Verbose) { duke@435: st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s", duke@435: BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code)); duke@435: } else { duke@435: st->print("%8d %4d %s", duke@435: BytecodeCounter::counter_value(), bci, Bytecodes::name(code)); duke@435: } duke@435: _next_pc = is_wide() ? bcp+2 : bcp+1; jrose@1920: print_attributes(bci); duke@435: // Set is_wide for the next one, since the caller of this doesn't skip duke@435: // the next bytecode. duke@435: _is_wide = (code == Bytecodes::_wide); jrose@1920: _code = Bytecodes::_illegal; duke@435: } duke@435: coleenp@4037: // Used for Method*::print_codes(). The input bcp comes from duke@435: // BytecodeStream, which will skip wide bytecodes. duke@435: void trace(methodHandle method, address bcp, outputStream* st) { duke@435: _current_method = method(); duke@435: ResourceMark rm; never@2462: Bytecodes::Code code = Bytecodes::code_at(method(), bcp); duke@435: // Set is_wide duke@435: _is_wide = (code == Bytecodes::_wide); duke@435: if (is_wide()) { never@2462: code = Bytecodes::code_at(method(), bcp+1); duke@435: } jrose@1920: _code = code; duke@435: int bci = bcp - method->code_base(); duke@435: // Print bytecode index and name duke@435: if (is_wide()) { duke@435: st->print("%d %s_w", bci, Bytecodes::name(code)); duke@435: } else { duke@435: st->print("%d %s", bci, Bytecodes::name(code)); duke@435: } duke@435: _next_pc = is_wide() ? bcp+2 : bcp+1; jrose@1920: print_attributes(bci, st); duke@435: bytecode_epilog(bci, st); duke@435: } duke@435: }; duke@435: duke@435: duke@435: // Implementation of BytecodeTracer duke@435: duke@435: // %%% This set_closure thing seems overly general, given that duke@435: // nobody uses it. Also, if BytecodePrinter weren't hidden coleenp@4037: // then Method* could use instances of it directly and it duke@435: // would be easier to remove races on _current_method and bcp. duke@435: // Since this is not product functionality, we can defer cleanup. duke@435: duke@435: BytecodeClosure* BytecodeTracer::_closure = NULL; duke@435: duke@435: static BytecodePrinter std_closure; duke@435: BytecodeClosure* BytecodeTracer::std_closure() { duke@435: return &::std_closure; duke@435: } duke@435: duke@435: duke@435: void BytecodeTracer::trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { duke@435: if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) { duke@435: ttyLocker ttyl; // 5065316: keep the following output coherent duke@435: // The ttyLocker also prevents races between two threads duke@435: // trying to use the single instance of BytecodePrinter. duke@435: // Using the ttyLocker prevents the system from coming to coleenp@4037: // a safepoint within this code, which is sensitive to Method* duke@435: // movement. duke@435: // duke@435: // There used to be a leaf mutex here, but the ttyLocker will duke@435: // work just as well, as long as the printing operations never block. duke@435: // duke@435: // We put the locker on the static trace method, not the duke@435: // virtual one, because the clients of this module go through duke@435: // the static method. duke@435: _closure->trace(method, bcp, tos, tos2, st); duke@435: } duke@435: } duke@435: duke@435: void BytecodeTracer::trace(methodHandle method, address bcp, outputStream* st) { duke@435: ttyLocker ttyl; // 5065316: keep the following output coherent duke@435: _closure->trace(method, bcp, st); duke@435: } duke@435: coleenp@2497: void print_symbol(Symbol* sym, outputStream* st) { jrose@1957: char buf[40]; jrose@1957: int len = sym->utf8_length(); jrose@1957: if (len >= (int)sizeof(buf)) { jrose@1957: st->print_cr(" %s...[%d]", sym->as_C_string(buf, sizeof(buf)), len); jrose@1957: } else { jrose@1957: st->print(" "); jrose@1957: sym->print_on(st); st->cr(); jrose@1957: } jrose@1957: } jrose@1957: duke@435: void print_oop(oop value, outputStream* st) { duke@435: if (value == NULL) { duke@435: st->print_cr(" NULL"); jrose@1957: } else if (java_lang_String::is_instance(value)) { never@2920: char buf[40]; never@2920: int len = java_lang_String::utf8_length(value); never@2920: java_lang_String::as_utf8_string(value, buf, sizeof(buf)); never@2920: if (len >= (int)sizeof(buf)) { never@2920: st->print_cr(" %s...[%d]", buf, len); never@2920: } else { never@2920: st->print_cr(" %s", buf); never@2920: } jrose@1957: } else { hseigel@5784: st->print_cr(" " PTR_FORMAT, (void *)value); duke@435: } duke@435: } duke@435: jrose@1920: bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@4037: int ilimit = constants->length(); coleenp@4037: Bytecodes::Code code = raw_code(); coleenp@4037: coleenp@4037: ConstantPoolCache* cache = NULL; coleenp@4037: if (Bytecodes::uses_cp_cache(code)) { coleenp@4037: bool okay = true; coleenp@4037: switch (code) { coleenp@4037: case Bytecodes::_fast_aldc: coleenp@4037: case Bytecodes::_fast_aldc_w: coleenp@4037: okay = check_obj_index(i, cp_index, st); coleenp@4037: break; coleenp@4037: case Bytecodes::_invokedynamic: coleenp@4037: okay = check_invokedynamic_index(i, cp_index, st); coleenp@4037: break; coleenp@4037: default: coleenp@4037: okay = check_cp_cache_index(i, cp_index, st); coleenp@4037: break; coleenp@4037: } coleenp@4037: if (!okay) return false; coleenp@4037: } coleenp@4037: coleenp@4037: coleenp@4037: // check cp index coleenp@4037: if (cp_index >= 0 && cp_index < ilimit) { coleenp@4037: if (WizardMode) st->print(" cp[%d]", cp_index); coleenp@4037: return true; coleenp@4037: } coleenp@4037: coleenp@4037: st->print_cr(" CP[%d] not in CP", cp_index); coleenp@4037: return false; coleenp@4037: } coleenp@4037: coleenp@4037: bool BytecodePrinter::check_cp_cache_index(int i, int& cp_index, outputStream* st) { coleenp@4037: ConstantPool* constants = method()->constants(); jrose@1161: int ilimit = constants->length(), climit = 0; jrose@1920: Bytecodes::Code code = raw_code(); jrose@1161: coleenp@4037: ConstantPoolCache* cache = constants->cache(); coleenp@4037: // If rewriter hasn't run, the index is the cp_index coleenp@4037: if (cache == NULL) { jrose@1161: cp_index = i; jrose@1161: return true; jrose@1161: } coleenp@4037: //climit = cache->length(); // %%% private! coleenp@4037: size_t size = cache->size() * HeapWordSize; coleenp@4037: size -= sizeof(ConstantPoolCache); coleenp@4037: size /= sizeof(ConstantPoolCacheEntry); coleenp@4037: climit = (int) size; jrose@1161: jrose@1920: #ifdef ASSERT jrose@1920: { coleenp@4037: const int CPCACHE_INDEX_TAG = ConstantPool::CPCACHE_INDEX_TAG; jrose@1920: if (i >= CPCACHE_INDEX_TAG && i < climit + CPCACHE_INDEX_TAG) { jrose@1920: i -= CPCACHE_INDEX_TAG; jrose@1920: } else { jrose@1920: st->print_cr(" CP[%d] missing bias?", i); jrose@1920: return false; jrose@1920: } jrose@1920: } jrose@1920: #endif //ASSERT jrose@1161: if (i >= 0 && i < climit) { coleenp@4037: cp_index = cache->entry_at(i)->constant_pool_index(); coleenp@4037: } else { coleenp@4037: st->print_cr(" not in CP[*]?", i); jrose@1161: return false; jrose@1161: } coleenp@4037: return true; jrose@1161: } coleenp@4037: coleenp@4037: coleenp@4037: bool BytecodePrinter::check_obj_index(int i, int& cp_index, outputStream* st) { coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@4037: i -= ConstantPool::CPCACHE_INDEX_TAG; coleenp@4037: coleenp@4037: if (i >= 0 && i < constants->resolved_references()->length()) { coleenp@4037: cp_index = constants->object_to_cp_index(i); coleenp@4037: return true; coleenp@4037: } else { coleenp@4037: st->print_cr(" not in OBJ[*]?", i); jrose@1161: return false; jrose@1161: } coleenp@4037: } coleenp@4037: coleenp@4037: coleenp@4037: bool BytecodePrinter::check_invokedynamic_index(int i, int& cp_index, outputStream* st) { coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@4037: assert(ConstantPool::is_invokedynamic_index(i), "not secondary index?"); coleenp@4037: i = ConstantPool::decode_invokedynamic_index(i) + ConstantPool::CPCACHE_INDEX_TAG; coleenp@4037: coleenp@4037: return check_cp_cache_index(i, cp_index, st); coleenp@4037: } jrose@1161: duke@435: void BytecodePrinter::print_constant(int i, outputStream* st) { jrose@1161: int orig_i = i; jrose@1920: if (!check_index(orig_i, i, st)) return; jrose@1161: coleenp@4037: ConstantPool* constants = method()->constants(); duke@435: constantTag tag = constants->tag_at(i); duke@435: duke@435: if (tag.is_int()) { duke@435: st->print_cr(" " INT32_FORMAT, constants->int_at(i)); duke@435: } else if (tag.is_long()) { duke@435: st->print_cr(" " INT64_FORMAT, constants->long_at(i)); duke@435: } else if (tag.is_float()) { duke@435: st->print_cr(" %f", constants->float_at(i)); duke@435: } else if (tag.is_double()) { duke@435: st->print_cr(" %f", constants->double_at(i)); duke@435: } else if (tag.is_string()) { jrose@1957: const char* string = constants->string_at_noresolve(i); jrose@1957: st->print_cr(" %s", string); duke@435: } else if (tag.is_klass()) { coleenp@4037: st->print_cr(" %s", constants->resolved_klass_at(i)->external_name()); duke@435: } else if (tag.is_unresolved_klass()) { duke@435: st->print_cr(" ", i); jrose@1957: } else if (tag.is_method_type()) { jrose@1957: int i2 = constants->method_type_index_at(i); jrose@1957: st->print(" %d", i2); coleenp@2497: print_symbol(constants->symbol_at(i2), st); jrose@1957: } else if (tag.is_method_handle()) { jrose@1957: int kind = constants->method_handle_ref_kind_at(i); jrose@1957: int i2 = constants->method_handle_index_at(i); jrose@1957: st->print(" ", kind, i2); jrose@1957: print_field_or_method(-i, i2, st); jrose@1161: } else { jrose@1161: st->print_cr(" bad tag=%d at %d", tag.value(), i); jrose@1161: } jrose@1161: } jrose@1161: jrose@1161: void BytecodePrinter::print_field_or_method(int i, outputStream* st) { jrose@1161: int orig_i = i; jrose@1920: if (!check_index(orig_i, i, st)) return; jrose@1957: print_field_or_method(orig_i, i, st); jrose@1957: } jrose@1161: jrose@1957: void BytecodePrinter::print_field_or_method(int orig_i, int i, outputStream* st) { coleenp@4037: ConstantPool* constants = method()->constants(); jrose@1161: constantTag tag = constants->tag_at(i); jrose@1161: jrose@2015: bool has_klass = true; jrose@1494: jrose@1161: switch (tag.value()) { jrose@1161: case JVM_CONSTANT_InterfaceMethodref: jrose@1161: case JVM_CONSTANT_Methodref: jrose@1161: case JVM_CONSTANT_Fieldref: jrose@2015: break; jrose@1494: case JVM_CONSTANT_NameAndType: jrose@2015: case JVM_CONSTANT_InvokeDynamic: jrose@2015: has_klass = false; jrose@1161: break; jrose@1161: default: jrose@1161: st->print_cr(" bad tag=%d at %d", tag.value(), i); jrose@1161: return; jrose@1161: } jrose@1161: coleenp@2497: Symbol* name = constants->uncached_name_ref_at(i); coleenp@2497: Symbol* signature = constants->uncached_signature_ref_at(i); jrose@1957: const char* sep = (tag.is_field() ? "/" : ""); jrose@2015: if (has_klass) { coleenp@2497: Symbol* klass = constants->klass_name_at(constants->uncached_klass_ref_index_at(i)); jrose@2015: st->print_cr(" %d <%s.%s%s%s> ", i, klass->as_C_string(), name->as_C_string(), sep, signature->as_C_string()); jrose@2015: } else { jrose@2015: if (tag.is_invoke_dynamic()) { jrose@2015: int bsm = constants->invoke_dynamic_bootstrap_method_ref_index_at(i); jrose@2015: st->print(" bsm=%d", bsm); jrose@2015: } jrose@2015: st->print_cr(" %d <%s%s%s>", i, name->as_C_string(), sep, signature->as_C_string()); jrose@2015: } duke@435: } duke@435: duke@435: jrose@1920: void BytecodePrinter::print_attributes(int bci, outputStream* st) { duke@435: // Show attributes of pre-rewritten codes jrose@1920: Bytecodes::Code code = Bytecodes::java_code(raw_code()); duke@435: // If the code doesn't have any fields there's nothing to print. duke@435: // note this is ==1 because the tableswitch and lookupswitch are duke@435: // zero size (for some reason) and we want to print stuff out for them. duke@435: if (Bytecodes::length_for(code) == 1) { duke@435: st->cr(); duke@435: return; duke@435: } duke@435: duke@435: switch(code) { duke@435: // Java specific bytecodes only matter. duke@435: case Bytecodes::_bipush: duke@435: st->print_cr(" " INT32_FORMAT, get_byte()); duke@435: break; duke@435: case Bytecodes::_sipush: duke@435: st->print_cr(" " INT32_FORMAT, get_short()); duke@435: break; duke@435: case Bytecodes::_ldc: jrose@1957: if (Bytecodes::uses_cp_cache(raw_code())) { jrose@1957: print_constant(get_index_u1_cpcache(), st); jrose@1957: } else { jrose@1957: print_constant(get_index_u1(), st); jrose@1957: } duke@435: break; duke@435: duke@435: case Bytecodes::_ldc_w: duke@435: case Bytecodes::_ldc2_w: jrose@1957: if (Bytecodes::uses_cp_cache(raw_code())) { jrose@1957: print_constant(get_index_u2_cpcache(), st); jrose@1957: } else { jrose@1957: print_constant(get_index_u2(), st); jrose@1957: } duke@435: break; duke@435: duke@435: case Bytecodes::_iload: duke@435: case Bytecodes::_lload: duke@435: case Bytecodes::_fload: duke@435: case Bytecodes::_dload: duke@435: case Bytecodes::_aload: duke@435: case Bytecodes::_istore: duke@435: case Bytecodes::_lstore: duke@435: case Bytecodes::_fstore: duke@435: case Bytecodes::_dstore: duke@435: case Bytecodes::_astore: duke@435: st->print_cr(" #%d", get_index_special()); duke@435: break; duke@435: duke@435: case Bytecodes::_iinc: duke@435: { int index = get_index_special(); duke@435: jint offset = is_wide() ? get_short(): get_byte(); duke@435: st->print_cr(" #%d " INT32_FORMAT, index, offset); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_newarray: { jrose@1920: BasicType atype = (BasicType)get_index_u1(); duke@435: const char* str = type2name(atype); duke@435: if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) { duke@435: assert(false, "Unidentified basic type"); duke@435: } duke@435: st->print_cr(" %s", str); duke@435: } duke@435: break; duke@435: case Bytecodes::_anewarray: { jrose@1920: int klass_index = get_index_u2(); coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@2497: Symbol* name = constants->klass_name_at(klass_index); duke@435: st->print_cr(" %s ", name->as_C_string()); duke@435: } duke@435: break; duke@435: case Bytecodes::_multianewarray: { jrose@1920: int klass_index = get_index_u2(); jrose@1920: int nof_dims = get_index_u1(); coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@2497: Symbol* name = constants->klass_name_at(klass_index); duke@435: st->print_cr(" %s %d", name->as_C_string(), nof_dims); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_ifeq: duke@435: case Bytecodes::_ifnull: duke@435: case Bytecodes::_iflt: duke@435: case Bytecodes::_ifle: duke@435: case Bytecodes::_ifne: duke@435: case Bytecodes::_ifnonnull: duke@435: case Bytecodes::_ifgt: duke@435: case Bytecodes::_ifge: duke@435: case Bytecodes::_if_icmpeq: duke@435: case Bytecodes::_if_icmpne: duke@435: case Bytecodes::_if_icmplt: duke@435: case Bytecodes::_if_icmpgt: duke@435: case Bytecodes::_if_icmple: duke@435: case Bytecodes::_if_icmpge: duke@435: case Bytecodes::_if_acmpeq: duke@435: case Bytecodes::_if_acmpne: duke@435: case Bytecodes::_goto: duke@435: case Bytecodes::_jsr: duke@435: st->print_cr(" %d", bci + get_short()); duke@435: break; duke@435: duke@435: case Bytecodes::_goto_w: duke@435: case Bytecodes::_jsr_w: duke@435: st->print_cr(" %d", bci + get_int()); duke@435: break; duke@435: duke@435: case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break; duke@435: duke@435: case Bytecodes::_tableswitch: duke@435: { align(); duke@435: int default_dest = bci + get_int(); duke@435: int lo = get_int(); duke@435: int hi = get_int(); duke@435: int len = hi - lo + 1; duke@435: jint* dest = NEW_RESOURCE_ARRAY(jint, len); duke@435: for (int i = 0; i < len; i++) { duke@435: dest[i] = bci + get_int(); duke@435: } duke@435: st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ", duke@435: default_dest, lo, hi); duke@435: int first = true; duke@435: for (int ll = lo; ll <= hi; ll++, first = false) { duke@435: int idx = ll - lo; duke@435: const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" : duke@435: ", %d:" INT32_FORMAT " (delta: %d)"; duke@435: st->print(format, ll, dest[idx], dest[idx]-bci); duke@435: } duke@435: st->cr(); duke@435: } duke@435: break; duke@435: case Bytecodes::_lookupswitch: duke@435: { align(); duke@435: int default_dest = bci + get_int(); duke@435: int len = get_int(); duke@435: jint* key = NEW_RESOURCE_ARRAY(jint, len); duke@435: jint* dest = NEW_RESOURCE_ARRAY(jint, len); duke@435: for (int i = 0; i < len; i++) { duke@435: key [i] = get_int(); duke@435: dest[i] = bci + get_int(); duke@435: }; duke@435: st->print(" %d %d ", default_dest, len); duke@435: bool first = true; duke@435: for (int ll = 0; ll < len; ll++, first = false) { duke@435: const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT : duke@435: ", " INT32_FORMAT ":" INT32_FORMAT ; duke@435: st->print(format, key[ll], dest[ll]); duke@435: } duke@435: st->cr(); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_putstatic: duke@435: case Bytecodes::_getstatic: duke@435: case Bytecodes::_putfield: jrose@1161: case Bytecodes::_getfield: jrose@1920: print_field_or_method(get_index_u2_cpcache(), st); duke@435: break; duke@435: duke@435: case Bytecodes::_invokevirtual: duke@435: case Bytecodes::_invokespecial: duke@435: case Bytecodes::_invokestatic: jrose@1920: print_field_or_method(get_index_u2_cpcache(), st); duke@435: break; duke@435: duke@435: case Bytecodes::_invokeinterface: jrose@1920: { int i = get_index_u2_cpcache(); jrose@1920: int n = get_index_u1(); jrose@1920: get_byte(); // ignore zero byte jrose@1161: print_field_or_method(i, st); duke@435: } duke@435: break; duke@435: jrose@1161: case Bytecodes::_invokedynamic: jrose@1920: print_field_or_method(get_index_u4(), st); jrose@1161: break; jrose@1161: duke@435: case Bytecodes::_new: duke@435: case Bytecodes::_checkcast: duke@435: case Bytecodes::_instanceof: jrose@1920: { int i = get_index_u2(); coleenp@4037: ConstantPool* constants = method()->constants(); coleenp@2497: Symbol* name = constants->klass_name_at(i); duke@435: st->print_cr(" %d <%s>", i, name->as_C_string()); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_wide: duke@435: // length is zero not one, but printed with no more info. duke@435: break; duke@435: duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void BytecodePrinter::bytecode_epilog(int bci, outputStream* st) { coleenp@4037: MethodData* mdo = method()->method_data(); duke@435: if (mdo != NULL) { duke@435: ProfileData* data = mdo->bci_to_data(bci); duke@435: if (data != NULL) { duke@435: st->print(" %d", mdo->dp_to_di(data->dp())); duke@435: st->fill_to(6); duke@435: data->print_data_on(st); duke@435: } duke@435: } duke@435: } duke@435: #endif // PRODUCT