hotspot/src/share/vm/ci/ciStreams.hpp
author jrose
Tue, 21 Apr 2009 23:21:04 -0700
changeset 2570 ecc7862946d4
parent 1 489c9b5090e2
child 3261 c7d5aae8d3f7
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 1999-2005 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
// ciBytecodeStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// The class is used to iterate over the bytecodes of a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// It hides the details of constant pool structure/access by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// providing accessors for constant pool items.  It returns only pure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Java bytecodes; VM-internal _fast bytecodes are translated back to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// their original form during iteration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class ciBytecodeStream : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 // Handling for the weird bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  Bytecodes::Code wide();       // Handle wide bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  Bytecodes::Code table(Bytecodes::Code); // Handle complicated inline table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static Bytecodes::Code check_java(Bytecodes::Code c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    return c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  ciMethod* _method;           // the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  ciInstanceKlass* _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  address _bc_start;            // Start of current bytecode for table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  address _was_wide;            // Address past last wide bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  jint* _table_base;            // Aligned start of last table or switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  address _start;                  // Start of bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  address _end;                    // Past end of bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  address _pc;                     // Current PC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  Bytecodes::Code _bc;             // Current bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  void reset( address base, unsigned int size ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _bc_start =_was_wide = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    _start = _pc = base; _end = base + size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // End-Of-Bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static Bytecodes::Code EOBC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    return Bytecodes::_illegal;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  ciBytecodeStream(ciMethod* m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    reset_to_method(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  ciBytecodeStream() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    reset_to_method(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  ciMethod* method() const { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void reset_to_method(ciMethod* m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _method = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    if (m == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      _holder = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      reset(NULL, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      _holder = m->holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      reset(m->code(), m->code_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  void reset_to_bci( int bci );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Force the iterator to report a certain bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  void force_bci(int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void set_max_bci( int max ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    _end = _start + max;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    94
  address cur_bcp() const       { return _bc_start; }  // Returns bcp to current instruction
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  int next_bci() const          { return _pc -_start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  int cur_bci() const           { return _bc_start - _start; }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    97
  int instruction_size() const  { return _pc - _bc_start; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  Bytecodes::Code cur_bc() const{ return check_java(_bc); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  Bytecodes::Code next_bc()     { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Return current ByteCode and increment PC to next bytecode, skipping all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // intermediate constants.  Returns EOBC at end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Expected usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  //     while( (bc = iter.next()) != EOBC() ) { ... }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Bytecodes::Code next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    _bc_start = _pc;                        // Capture start of bc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if( _pc >= _end ) return EOBC();        // End-Of-Bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // Fetch Java bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // All rewritten bytecodes maintain the size of original bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    _bc = Bytecodes::java_code((Bytecodes::Code)*_pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    int csize = Bytecodes::length_for(_bc); // Expected size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if( _bc == Bytecodes::_wide ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      _bc=wide();                           // Handle wide bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    } else if( csize == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      _bc=table(_bc);                       // Handle inline tables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      _pc += csize;                         // Bump PC past bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return check_java(_bc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   125
  bool is_wide() const { return ( _pc == _was_wide ); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Get a byte index following this bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // If prefixed with a wide bytecode, get a wide index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  int get_index() const {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   130
    assert_index_size(is_wide() ? 2 : 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    return (_pc == _was_wide)   // was widened?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      ? Bytes::get_Java_u2(_bc_start+2) // yes, return wide index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      : _bc_start[1];           // no, return narrow index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   136
  // Get 2-byte index (getfield/putstatic/etc)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   137
  int get_index_big() const {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   138
    assert_index_size(2);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   139
    return Bytes::get_Java_u2(_bc_start+1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   142
  // Get 2-byte index (or 4-byte, for invokedynamic)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   143
  int get_index_int() const {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   144
    return has_giant_index() ? get_index_giant() : get_index_big();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   145
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   146
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   147
  // Get 4-byte index, for invokedynamic.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   148
  int get_index_giant() const {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   149
    assert_index_size(4);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   150
    return Bytes::get_native_u4(_bc_start+1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   151
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   152
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   153
  bool has_giant_index() const { return (cur_bc() == Bytecodes::_invokedynamic); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // Get dimensions byte (multinewarray)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  int get_dimensions() const { return *(unsigned char*)(_pc-1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Sign-extended index byte/short, no widening
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  int get_byte() const { return (int8_t)(_pc[-1]); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  int get_short() const { return (int16_t)Bytes::get_Java_u2(_pc-2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  int get_long() const  { return (int32_t)Bytes::get_Java_u4(_pc-4); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Get a byte signed constant for "iinc".  Invalid for other bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // If prefixed with a wide bytecode, get a wide constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  int get_iinc_con() const {return (_pc==_was_wide) ? get_short() :get_byte();}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // 2-byte branch offset from current pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  int get_dest( ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    assert( Bytecodes::length_at(_bc_start) == sizeof(jshort)+1,  "get_dest called with bad bytecode" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    return _bc_start-_start + (short)Bytes::get_Java_u2(_pc-2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // 2-byte branch offset from next pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  int next_get_dest( ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    address next_bc_start = _pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    assert( _pc < _end, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    Bytecodes::Code next_bc = (Bytecodes::Code)*_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    assert( next_bc != Bytecodes::_wide, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    int next_csize = Bytecodes::length_for(next_bc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    assert( next_csize != 0, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    assert( next_bc <= Bytecodes::_jsr_w, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    address next_pc = _pc + next_csize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    assert( Bytecodes::length_at(next_bc_start) == sizeof(jshort)+1,  "next_get_dest called with bad bytecode" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    return next_bc_start-_start + (short)Bytes::get_Java_u2(next_pc-2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // 4-byte branch offset from current pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  int get_far_dest( ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    assert( Bytecodes::length_at(_bc_start) == sizeof(jint)+1, "dest4 called with bad bytecode" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    return _bc_start-_start + (int)Bytes::get_Java_u4(_pc-4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // For a lookup or switch table, return target destination
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  int get_int_table( int index ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    return Bytes::get_Java_u4((address)&_table_base[index]); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // For tableswitch - get length of offset part
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  int get_tableswitch_length()  { return get_int_table(2)-get_int_table(1)+1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  int get_dest_table( int index ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    return cur_bci() + get_int_table(index); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // --- Constant pool access ---
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  int get_constant_index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  int get_field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  int get_method_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // If this bytecode is a new, newarray, multianewarray, instanceof,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // or checkcast, get the referenced klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  ciKlass* get_klass(bool& will_link);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  int get_klass_index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // If this bytecode is one of the ldc variants, get the referenced
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  ciConstant get_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // True if the ldc variant points to an unresolved string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  bool is_unresolved_string() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // True if the ldc variant points to an unresolved klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  bool is_unresolved_klass() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // If this bytecode is one of get_field, get_static, put_field,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // or put_static, get the referenced field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  ciField* get_field(bool& will_link);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  ciInstanceKlass* get_declared_field_holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  int      get_field_holder_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  int      get_field_signature_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // If this is a method invocation bytecode, get the invoked method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  ciMethod* get_method(bool& will_link);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  ciKlass*  get_declared_method_holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  int       get_method_holder_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  int       get_method_signature_index();
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   234
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   235
 private:
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   236
  void assert_index_size(int required_size) const {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   237
#ifdef ASSERT
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   238
    int isize = instruction_size() - (is_wide() ? 1 : 0) - 1;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   239
    if (isize == 2 &&  cur_bc() == Bytecodes::_iinc)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   240
      isize = 1;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   241
    else if (isize <= 2)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   242
      ;                         // no change
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   243
    else if (has_giant_index())
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   244
      isize = 4;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   245
    else
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   246
      isize = 2;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   247
    assert(isize = required_size, "wrong index size");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   248
#endif
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   249
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
// ciSignatureStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
// The class is used to iterate over the elements of a method signature.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
class ciSignatureStream : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  ciSignature* _sig;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  int    _pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  ciSignatureStream(ciSignature* signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    _sig = signature;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  bool at_return_type() { return _pos == _sig->count(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  bool is_done() { return _pos > _sig->count(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  void next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    if (_pos <= _sig->count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      _pos++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  ciType* type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    if (at_return_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      return _sig->return_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      return _sig->type_at(_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
// ciExceptionHandlerStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
// The class is used to iterate over the exception handlers of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
// a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
class ciExceptionHandlerStream : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // The method whose handlers we are traversing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  ciMethod* _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // Our current position in the list of handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  int        _pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  int        _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  ciInstanceKlass*  _exception_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  int        _bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  bool       _is_exact;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  ciExceptionHandlerStream(ciMethod* method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // Force loading of method code and handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    _method->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    _end = _method->_handler_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    _exception_klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    _bci    = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    _is_exact = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  ciExceptionHandlerStream(ciMethod* method, int bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
                           ciInstanceKlass* exception_klass = NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
                           bool is_exact = false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // Force loading of method code and handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    _method->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    _pos = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    _end = _method->_handler_count + 1; // include the rethrow handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    _exception_klass = (exception_klass != NULL && exception_klass->is_loaded()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
                          ? exception_klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                          : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    _bci = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    assert(_bci >= 0, "bci out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    _is_exact = is_exact;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  // These methods are currently implemented in an odd way.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // Count the number of handlers the iterator has ever produced
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // or will ever produce.  Do not include the final rethrow handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // That is, a trivial exception handler stream will have a count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // of zero and produce just the rethrow handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  int count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // Count the number of handlers this stream will produce from now on.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // Include the current handler, and the final rethrow handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  // The remaining count will be zero iff is_done() is true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  int count_remaining();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  bool is_done() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    return (_pos >= _end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  void next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    _pos++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    if (_bci != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      // We are not iterating over all handlers...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      while (!is_done()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
        ciExceptionHandler* handler = _method->_exception_handlers[_pos];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        if (handler->is_in_range(_bci)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
          if (handler->is_catch_all()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
            // Found final active catch block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
            _end = _pos+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
          } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
            // We cannot do any type analysis here.  Must conservatively assume
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
            // catch block is reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
          } else if (_exception_klass->is_subtype_of(handler->catch_klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
            // This catch clause will definitely catch the exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
            // Final candidate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
            _end = _pos+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
          } else if (!_is_exact &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                     handler->catch_klass()->is_subtype_of(_exception_klass)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
            // This catch block may be reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
            return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        // The catch block was not pertinent.  Go on.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        _pos++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      // This is an iteration over all handlers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  ciExceptionHandler* handler() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    return _method->_exception_handlers[_pos];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
};