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