hotspot/src/share/vm/interpreter/bytecode.hpp
author jrose
Wed, 09 Jun 2010 18:50:45 -0700
changeset 5882 6b2aecc4f7d8
parent 5702 201c5cde25bb
child 7397 5b173b4ca846
permissions -rw-r--r--
6939203: JSR 292 needs method handle constants Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode. Reviewed-by: twisti, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5702
jrose
parents: 5547 5688
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
diff changeset
    21
 * questions.
1
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
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // Address computation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  address addr_at            (int offset)        const     { return (address)this + offset; }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    32
  int     byte_at            (int offset)        const     { return *(addr_at(offset)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  address aligned_addr_at    (int offset)        const     { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  int     aligned_offset     (int offset)        const     { return aligned_addr_at(offset) - addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    36
  // Word access:
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    37
  int     get_Java_u2_at     (int offset)        const     { return Bytes::get_Java_u2(addr_at(offset)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    38
  int     get_Java_u4_at     (int offset)        const     { return Bytes::get_Java_u4(addr_at(offset)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    39
  int     get_native_u2_at   (int offset)        const     { return Bytes::get_native_u2(addr_at(offset)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    40
  int     get_native_u4_at   (int offset)        const     { return Bytes::get_native_u4(addr_at(offset)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// The base class for different kinds of bytecode abstractions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// Provides the primitive operations to manipulate code relative
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// to an objects 'this' pointer.
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    47
// FIXME: Make this a ResourceObj, include the enclosing methodOop, and cache the opcode.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class Bytecode: public ThisRelativeObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  u_char byte_at(int offset) const               { return *addr_at(offset); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    52
  bool check_must_rewrite(Bytecodes::Code bc) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  address bcp() const                            { return addr_at(0); }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    57
  int instruction_size() const                   { return Bytecodes::length_at(bcp()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    59
  // Warning: Use code() with caution on live bytecode streams.  4926272
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  Bytecodes::Code code() const                   { return Bytecodes::code_at(addr_at(0)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    62
  bool must_rewrite(Bytecodes::Code code) const  { return Bytecodes::can_rewrite(code) && check_must_rewrite(code); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  inline friend Bytecode* Bytecode_at(address bcp);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    66
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    67
  // Static functions for parsing bytecodes in place.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    68
  int get_index_u1(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    69
    assert_same_format_as(bc); assert_index_size(1, bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    70
    return *(jubyte*)addr_at(1);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    71
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    72
  int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    73
    assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    74
    address p = addr_at(is_wide ? 2 : 1);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    75
    if (can_use_native_byte_order(bc, is_wide))
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    76
          return Bytes::get_native_u2(p);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    77
    else  return Bytes::get_Java_u2(p);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    78
  }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    79
  int get_index_u1_cpcache(Bytecodes::Code bc) const {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    80
    assert_same_format_as(bc); assert_index_size(1, bc);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    81
    return *(jubyte*)addr_at(1) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    82
  }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    83
  int get_index_u2_cpcache(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    84
    assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    85
    return Bytes::get_native_u2(addr_at(1)) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    86
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    87
  int get_index_u4(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    88
    assert_same_format_as(bc); assert_index_size(4, bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    89
    assert(can_use_native_byte_order(bc), "");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    90
    return Bytes::get_native_u4(addr_at(1));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    91
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    92
  bool has_index_u4(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    93
    return bc == Bytecodes::_invokedynamic;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    94
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    95
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    96
  int get_offset_s2(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    97
    assert_same_format_as(bc); assert_offset_size(2, bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    98
    return (jshort) Bytes::get_Java_u2(addr_at(1));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
    99
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   100
  int get_offset_s4(Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   101
    assert_same_format_as(bc); assert_offset_size(4, bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   102
    return (jint) Bytes::get_Java_u4(addr_at(1));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   103
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   104
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   105
  int get_constant_u1(int offset, Bytecodes::Code bc) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   106
    assert_same_format_as(bc); assert_constant_size(1, offset, bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   107
    return *(jbyte*)addr_at(offset);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   108
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   109
  int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   110
    assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   111
    return (jshort) Bytes::get_Java_u2(addr_at(offset));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   112
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   113
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   114
  // These are used locally and also from bytecode streams.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   115
  void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   116
  static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   117
  static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   118
  static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   119
  static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   120
  static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   121
    return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/));
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   122
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
inline Bytecode* Bytecode_at(address bcp) {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   126
  // Warning: Use with caution on live bytecode streams.  4926272
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return (Bytecode*)bcp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// Abstractions for lookupswitch bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
class LookupswitchPair: ThisRelativeObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  int  _match;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  int  _offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 public:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   139
  int  match() const                             { return get_Java_u4_at(0 * jintSize); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   140
  int  offset() const                            { return get_Java_u4_at(1 * jintSize); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
class Bytecode_lookupswitch: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  void verify() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Attributes
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   149
  int  default_offset() const                    { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   150
  int  number_of_pairs() const                   { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  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
   152
                                                   return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   159
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
class Bytecode_tableswitch: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void verify() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Attributes
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   169
  int  default_offset() const                    { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   170
  int  low_key() const                           { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   171
  int  high_key() const                          { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  int  dest_offset_at(int i) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  int  length()                                  { return high_key()-low_key()+1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   181
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   186
// Common code for decoding invokes and field references.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   188
class Bytecode_member_ref: public ResourceObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  methodHandle _method;                          // method containing the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  int          _bci;                             // position of the bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   193
  Bytecode_member_ref(methodHandle method, int bci)  : _method(method), _bci(bci) {}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   194
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   195
 public:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   196
  // Attributes
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   197
  methodHandle method() const                    { return _method; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   198
  int          bci() const                       { return _bci; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   199
  address      bcp() const                       { return _method->bcp_from(bci()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   200
  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   201
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   202
  int          index() const;                    // cache index (loaded from instruction)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   203
  int          pool_index() const;               // constant pool index
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   204
  symbolOop    name() const;                     // returns the name of the method or field
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   205
  symbolOop    signature() const;                // returns the signature of the method or field
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   206
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   207
  BasicType    result_type(Thread* thread) const; // returns the result type of the getfield or invoke
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   208
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   209
  Bytecodes::Code code() const                   { return Bytecodes::code_at(bcp(), _method()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   210
  Bytecodes::Code java_code() const              { return Bytecodes::java_code(code()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   211
};
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   212
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   213
// Abstraction for invoke_{virtual, static, interface, special}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   214
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   215
class Bytecode_invoke: public Bytecode_member_ref {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   216
 protected:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   217
  Bytecode_invoke(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  methodHandle static_target(TRAPS);             // "specified" method   (from constant pool)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // Testers
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   226
  bool is_invokeinterface() const                { return java_code() == Bytecodes::_invokeinterface; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   227
  bool is_invokevirtual() const                  { return java_code() == Bytecodes::_invokevirtual; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   228
  bool is_invokestatic() const                   { return java_code() == Bytecodes::_invokestatic; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   229
  bool is_invokespecial() const                  { return java_code() == Bytecodes::_invokespecial; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   230
  bool is_invokedynamic() const                  { return java_code() == Bytecodes::_invokedynamic; }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   231
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4564
diff changeset
   232
  bool has_receiver() const                      { return !is_invokestatic() && !is_invokedynamic(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool is_valid() const                          { return is_invokeinterface() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                                                          is_invokevirtual()   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
                                                          is_invokestatic()    ||
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   237
                                                          is_invokespecial()   ||
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   238
                                                          is_invokedynamic(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   249
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  Bytecode_invoke* b = new Bytecode_invoke(method, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  return b->is_valid() ? b : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   259
// Abstraction for all field accesses (put/get field/static)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   260
class Bytecode_field: public Bytecode_member_ref {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   261
 protected:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   262
  Bytecode_field(methodHandle method, int bci)  : Bytecode_member_ref(method, bci) {}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   263
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   264
 public:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   265
  // Testers
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   266
  bool is_getfield() const                       { return java_code() == Bytecodes::_getfield; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   267
  bool is_putfield() const                       { return java_code() == Bytecodes::_putfield; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   268
  bool is_getstatic() const                      { return java_code() == Bytecodes::_getstatic; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   269
  bool is_putstatic() const                      { return java_code() == Bytecodes::_putstatic; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   270
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   271
  bool is_getter() const                         { return is_getfield()  || is_getstatic(); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   272
  bool is_static() const                         { return is_getstatic() || is_putstatic(); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   273
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   274
  bool is_valid() const                          { return is_getfield()   ||
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   275
                                                          is_putfield()   ||
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   276
                                                          is_getstatic()  ||
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   277
                                                          is_putstatic(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Creation
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   281
  inline friend Bytecode_field* Bytecode_field_at(methodHandle method, int bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   284
inline Bytecode_field* Bytecode_field_at(methodHandle method, int bci) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   285
  Bytecode_field* b = new Bytecode_field(method, bci);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   286
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
// Abstraction for checkcast
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
class Bytecode_checkcast: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // Returns index
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   298
  long index() const   { return get_index_u2(Bytecodes::_checkcast); };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   306
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
// Abstraction for instanceof
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
class Bytecode_instanceof: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Returns index
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   318
  long index() const   { return get_index_u2(Bytecodes::_instanceof); };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   326
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
class Bytecode_new: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // Returns index
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   336
  long index() const   { return get_index_u2(Bytecodes::_new); };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  inline friend Bytecode_new* Bytecode_new_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
inline Bytecode_new* Bytecode_new_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  Bytecode_new* b = (Bytecode_new*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   344
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
class Bytecode_multianewarray: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // Returns index
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   354
  long index() const   { return get_index_u2(Bytecodes::_multianewarray); };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   362
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
class Bytecode_anewarray: public Bytecode {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  // Returns index
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4567
diff changeset
   372
  long index() const   { return get_index_u2(Bytecodes::_anewarray); };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   380
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
// Abstraction for ldc, ldc_w and ldc2_w
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   387
class Bytecode_loadconstant: public ResourceObj {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   388
 private:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   389
  int          _bci;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   390
  methodHandle _method;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   391
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   392
  Bytecodes::Code code() const                   { return bytecode()->code(); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   393
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   394
  int raw_index() const;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   395
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   396
  Bytecode_loadconstant(methodHandle method, int bci) : _method(method), _bci(bci) {}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   397
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
 public:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   399
  // Attributes
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   400
  methodHandle method() const                    { return _method; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   401
  int          bci() const                       { return _bci; }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   402
  address      bcp() const                       { return _method->bcp_from(bci()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   403
  Bytecode*    bytecode() const                  { return Bytecode_at(bcp()); }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   404
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  void verify() const {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   406
    assert(_method.not_null(), "must supply method");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    assert(stdc == Bytecodes::_ldc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
           stdc == Bytecodes::_ldc_w ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
           stdc == Bytecodes::_ldc2_w, "load constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   413
  // Only non-standard bytecodes (fast_aldc) have CP cache indexes.
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   414
  bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   416
  int pool_index() const;               // index into constant pool
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   417
  int cache_index() const {             // index into CP cache (or -1 if none)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   418
    return has_cache_index() ? raw_index() : -1;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   419
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   420
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   421
  BasicType result_type() const;        // returns the result type of the ldc
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   422
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   423
  oop resolve_constant(TRAPS) const;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   424
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   425
  // Creation
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   426
  inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   429
inline Bytecode_loadconstant* Bytecode_loadconstant_at(methodHandle method, int bci) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   430
  Bytecode_loadconstant* b = new Bytecode_loadconstant(method, bci);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   431
  DEBUG_ONLY(b->verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  return b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
}