hotspot/src/share/vm/interpreter/bytecode.hpp
author twisti
Tue, 05 Jan 2010 15:21:25 +0100
changeset 4567 7fc02fbe5c7a
parent 4564 55dfb20908d0
child 5688 9052dc91ea67
child 5547 f4b087cbb361
permissions -rw-r--r--
6893268: additional dynamic language related optimizations in C2 Summary: C2 needs some additional optimizations to be able to handle MethodHandle invokes and invokedynamic instructions at the best performance. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2570
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
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
// Base class for different kinds of abstractions working
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// relative to an objects 'this' pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class ThisRelativeObj VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  int     sign_extend        (int x, int size)   const     { const int s = (BytesPerInt - size)*BitsPerByte; return (x << s) >> s; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Address computation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  address addr_at            (int offset)        const     { return (address)this + offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  address aligned_addr_at    (int offset)        const     { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  int     aligned_offset     (int offset)        const     { return aligned_addr_at(offset) - addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // Java unsigned accessors (using Java spec byte ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  int     java_byte_at       (int offset)        const     { return *(jubyte*)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  int     java_hwrd_at       (int offset)        const     { return java_byte_at(offset) << (1 * BitsPerByte) | java_byte_at(offset + 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  int     java_word_at       (int offset)        const     { return java_hwrd_at(offset) << (2 * BitsPerByte) | java_hwrd_at(offset + 2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // Java signed accessors (using Java spec byte ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  int     java_signed_byte_at(int offset)        const     { return sign_extend(java_byte_at(offset), 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int     java_signed_hwrd_at(int offset)        const     { return sign_extend(java_hwrd_at(offset), 2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  int     java_signed_word_at(int offset)        const     { return             java_word_at(offset)    ; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Fast accessors (using the machine's natural byte ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  int     fast_byte_at       (int offset)        const     { return *(jubyte *)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  int     fast_hwrd_at       (int offset)        const     { return *(jushort*)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  int     fast_word_at       (int offset)        const     { return *(juint  *)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Fast signed accessors (using the machine's natural byte ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  int     fast_signed_byte_at(int offset)        const     { return *(jbyte *)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  int     fast_signed_hwrd_at(int offset)        const     { return *(jshort*)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int     fast_signed_word_at(int offset)        const     { return *(jint  *)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Fast manipulators (using the machine's natural byte ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void    set_fast_byte_at   (int offset, int x) const     { *(jbyte *)addr_at(offset) = (jbyte )x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  void    set_fast_hwrd_at   (int offset, int x) const     { *(jshort*)addr_at(offset) = (jshort)x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void    set_fast_word_at   (int offset, int x) const     { *(jint  *)addr_at(offset) = (jint  )x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// The base class for different kinds of bytecode abstractions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// Provides the primitive operations to manipulate code relative
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// to an objects 'this' pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
class Bytecode: public ThisRelativeObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  u_char byte_at(int offset) const               { return *addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  bool check_must_rewrite() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  address bcp() const                            { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  address next_bcp() const                       { return addr_at(0) + Bytecodes::length_at(bcp()); }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    78
  int instruction_size() const                   { return Bytecodes::length_at(bcp()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  Bytecodes::Code code() const                   { return Bytecodes::code_at(addr_at(0)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  bool must_rewrite() const                      { return Bytecodes::can_rewrite(code()) && check_must_rewrite(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  bool is_active_breakpoint() const              { return Bytecodes::is_active_breakpoint_at(bcp()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    85
  int     one_byte_index() const                 { assert_index_size(1); return byte_at(1); }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    86
  int     two_byte_index() const                 { assert_index_size(2); return (byte_at(1) << 8) + byte_at(2); }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    87
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  int     offset() const                         { return (two_byte_index() << 16) >> 16; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  address destination() const                    { return bcp() + offset(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Attribute modification
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  void    set_code(Bytecodes::Code code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  inline friend Bytecode* Bytecode_at(address bcp);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    96
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    97
 private:
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    98
  void assert_index_size(int required_size) const {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    99
#ifdef ASSERT
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   100
    int isize = instruction_size() - 1;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   101
    if (isize == 2 && code() == Bytecodes::_iinc)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   102
      isize = 1;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   103
    else if (isize <= 2)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   104
      ;                         // no change
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   105
    else if (code() == Bytecodes::_invokedynamic)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   106
      isize = 4;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   107
    else
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   108
      isize = 2;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   109
    assert(isize = required_size, "wrong index size");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   110
#endif
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   111
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
inline Bytecode* Bytecode_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return (Bytecode*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// Abstractions for lookupswitch bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
class LookupswitchPair: ThisRelativeObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  int  _match;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  int  _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  int  match() const                             { return java_signed_word_at(0 * jintSize); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  int  offset() const                            { return java_signed_word_at(1 * jintSize); }
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
class Bytecode_lookupswitch: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void verify() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int  default_offset() const                    { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int  number_of_pairs() const                   { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  LookupswitchPair* pair_at(int i) const         { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                                                   return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
class Bytecode_tableswitch: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  void verify() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  int  default_offset() const                    { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  int  low_key() const                           { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  int  high_key() const                          { return java_signed_word_at(aligned_offset(1 + 2*jintSize)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  int  dest_offset_at(int i) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  int  length()                                  { return high_key()-low_key()+1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// Abstraction for invoke_{virtual, static, interface, special}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
class Bytecode_invoke: public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  methodHandle _method;                          // method containing the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  int          _bci;                             // position of the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  Bytecode_invoke(methodHandle method, int bci)  : _method(method), _bci(bci) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  methodHandle method() const                    { return _method; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  int          bci() const                       { return _bci; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  address      bcp() const                       { return _method->bcp_from(bci()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  int          index() const;                    // the constant pool index for the invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  symbolOop    name() const;                     // returns the name of the invoked method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  symbolOop    signature() const;                // returns the signature of the invoked method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  BasicType    result_type(Thread *thread) const; // returns the result type of the invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  Bytecodes::Code code() const                   { return Bytecodes::code_at(bcp(), _method()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  Bytecodes::Code adjusted_invoke_code() const   { return Bytecodes::java_code(code()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  methodHandle static_target(TRAPS);             // "specified" method   (from constant pool)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // Testers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  bool is_invokeinterface() const                { return adjusted_invoke_code() == Bytecodes::_invokeinterface; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  bool is_invokevirtual() const                  { return adjusted_invoke_code() == Bytecodes::_invokevirtual; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  bool is_invokestatic() const                   { return adjusted_invoke_code() == Bytecodes::_invokestatic; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  bool is_invokespecial() const                  { return adjusted_invoke_code() == Bytecodes::_invokespecial; }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   206
  bool is_invokedynamic() const                  { return adjusted_invoke_code() == Bytecodes::_invokedynamic; }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   207
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4564
diff changeset
   208
  bool has_receiver() const                      { return !is_invokestatic() && !is_invokedynamic(); }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   209
  bool has_giant_index() const                   { return is_invokedynamic(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  bool is_valid() const                          { return is_invokeinterface() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
                                                          is_invokevirtual()   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
                                                          is_invokestatic()    ||
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   214
                                                          is_invokespecial()   ||
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   215
                                                          is_invokedynamic(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  return b->is_valid() ? b : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
// Abstraction for all field accesses (put/get field/static_
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
class Bytecode_field: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  int  index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  bool is_static() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  Bytecode_field* b = (Bytecode_field*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
// Abstraction for {get,put}static
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
class Bytecode_static: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // Returns the result type of the send by inspecting the field ref
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  BasicType result_type(methodOop method) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  inline friend Bytecode_static* Bytecode_static_at(const methodOop method, address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
inline Bytecode_static* Bytecode_static_at(const methodOop method, address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  Bytecode_static* b = (Bytecode_static*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
// Abstraction for checkcast
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
class Bytecode_checkcast: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // Returns index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  long index() const   { return java_hwrd_at(1); };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
// Abstraction for instanceof
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
class Bytecode_instanceof: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // Returns index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  long index() const   { return java_hwrd_at(1); };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
class Bytecode_new: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // Returns index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  long index() const   { return java_hwrd_at(1); };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  inline friend Bytecode_new* Bytecode_new_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
inline Bytecode_new* Bytecode_new_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  Bytecode_new* b = (Bytecode_new*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
class Bytecode_multianewarray: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // Returns index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  long index() const   { return java_hwrd_at(1); };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
class Bytecode_anewarray: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // Returns index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  long index() const   { return java_hwrd_at(1); };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// Abstraction for ldc, ldc_w and ldc2_w
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
class Bytecode_loadconstant: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  void verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    assert(stdc == Bytecodes::_ldc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
           stdc == Bytecodes::_ldc_w ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
           stdc == Bytecodes::_ldc2_w, "load constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  int index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  debug_only(b->verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}