src/share/vm/interpreter/bytecode.hpp

Wed, 20 Jul 2011 18:04:17 -0700

author
iveresov
date
Wed, 20 Jul 2011 18:04:17 -0700
changeset 3035
43f9d800f276
parent 2508
b92c45f2bc75
child 3251
e342a5110bed
permissions
-rw-r--r--

7066339: Tiered: policy should make consistent decisions about osr levels
Summary: Added feedback disabling flag to common(), fixed handling of TieredStopAtLevel.
Reviewed-by: kvn, never

duke@435 1 /*
never@2462 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_INTERPRETER_BYTECODE_HPP
stefank@2314 26 #define SHARE_VM_INTERPRETER_BYTECODE_HPP
stefank@2314 27
stefank@2314 28 #include "interpreter/bytecodes.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "oops/methodOop.hpp"
stefank@2314 31 #ifdef TARGET_ARCH_x86
stefank@2314 32 # include "bytes_x86.hpp"
stefank@2314 33 #endif
stefank@2314 34 #ifdef TARGET_ARCH_sparc
stefank@2314 35 # include "bytes_sparc.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_ARCH_zero
stefank@2314 38 # include "bytes_zero.hpp"
stefank@2314 39 #endif
bobv@2508 40 #ifdef TARGET_ARCH_arm
bobv@2508 41 # include "bytes_arm.hpp"
bobv@2508 42 #endif
bobv@2508 43 #ifdef TARGET_ARCH_ppc
bobv@2508 44 # include "bytes_ppc.hpp"
bobv@2508 45 #endif
stefank@2314 46
never@2462 47 class ciBytecodeStream;
duke@435 48
never@2462 49 // The base class for different kinds of bytecode abstractions.
never@2462 50 // Provides the primitive operations to manipulate code relative
never@2462 51 // to the bcp.
never@2462 52
never@2462 53 class Bytecode: public StackObj {
never@2462 54 protected:
never@2462 55 const address _bcp;
never@2462 56 const Bytecodes::Code _code;
never@2462 57
duke@435 58 // Address computation
never@2462 59 address addr_at (int offset) const { return (address)_bcp + offset; }
never@2462 60 u_char byte_at(int offset) const { return *addr_at(offset); }
duke@435 61 address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
duke@435 62 int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); }
duke@435 63
jrose@1920 64 // Word access:
jrose@1920 65 int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); }
jrose@1920 66 int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
jrose@1920 67 int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); }
jrose@1920 68 int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); }
duke@435 69
duke@435 70 public:
never@2462 71 Bytecode(methodOop method, address bcp): _bcp(bcp), _code(Bytecodes::code_at(method, addr_at(0))) {
never@2462 72 assert(method != NULL, "this form requires a valid methodOop");
never@2462 73 }
never@2462 74 // Defined in ciStreams.hpp
never@2462 75 inline Bytecode(const ciBytecodeStream* stream, address bcp = NULL);
never@2462 76
duke@435 77 // Attributes
never@2462 78 address bcp() const { return _bcp; }
never@2462 79 int instruction_size() const { return Bytecodes::length_for_code_at(_code, bcp()); }
duke@435 80
never@2462 81 Bytecodes::Code code() const { return _code; }
duke@435 82 Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); }
jrose@1161 83
jrose@1920 84 // Static functions for parsing bytecodes in place.
jrose@1920 85 int get_index_u1(Bytecodes::Code bc) const {
jrose@1920 86 assert_same_format_as(bc); assert_index_size(1, bc);
jrose@1920 87 return *(jubyte*)addr_at(1);
jrose@1920 88 }
jrose@1920 89 int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
jrose@1920 90 assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
jrose@1920 91 address p = addr_at(is_wide ? 2 : 1);
jrose@1920 92 if (can_use_native_byte_order(bc, is_wide))
never@2462 93 return Bytes::get_native_u2(p);
jrose@1920 94 else return Bytes::get_Java_u2(p);
jrose@1920 95 }
jrose@1957 96 int get_index_u1_cpcache(Bytecodes::Code bc) const {
jrose@1957 97 assert_same_format_as(bc); assert_index_size(1, bc);
jrose@1957 98 return *(jubyte*)addr_at(1) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
jrose@1957 99 }
jrose@1920 100 int get_index_u2_cpcache(Bytecodes::Code bc) const {
jrose@1920 101 assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);
jrose@1957 102 return Bytes::get_native_u2(addr_at(1)) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
jrose@1920 103 }
jrose@1920 104 int get_index_u4(Bytecodes::Code bc) const {
jrose@1920 105 assert_same_format_as(bc); assert_index_size(4, bc);
jrose@1920 106 assert(can_use_native_byte_order(bc), "");
jrose@1920 107 return Bytes::get_native_u4(addr_at(1));
jrose@1920 108 }
jrose@1920 109 bool has_index_u4(Bytecodes::Code bc) const {
jrose@1920 110 return bc == Bytecodes::_invokedynamic;
jrose@1920 111 }
jrose@1920 112
jrose@1920 113 int get_offset_s2(Bytecodes::Code bc) const {
jrose@1920 114 assert_same_format_as(bc); assert_offset_size(2, bc);
jrose@1920 115 return (jshort) Bytes::get_Java_u2(addr_at(1));
jrose@1920 116 }
jrose@1920 117 int get_offset_s4(Bytecodes::Code bc) const {
jrose@1920 118 assert_same_format_as(bc); assert_offset_size(4, bc);
jrose@1920 119 return (jint) Bytes::get_Java_u4(addr_at(1));
jrose@1920 120 }
jrose@1920 121
jrose@1920 122 int get_constant_u1(int offset, Bytecodes::Code bc) const {
jrose@1920 123 assert_same_format_as(bc); assert_constant_size(1, offset, bc);
jrose@1920 124 return *(jbyte*)addr_at(offset);
jrose@1920 125 }
jrose@1920 126 int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const {
jrose@1920 127 assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide);
jrose@1920 128 return (jshort) Bytes::get_Java_u2(addr_at(offset));
jrose@1920 129 }
jrose@1920 130
jrose@1920 131 // These are used locally and also from bytecode streams.
jrose@1920 132 void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN;
jrose@1920 133 static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
jrose@1920 134 static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
jrose@1920 135 static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
jrose@1920 136 static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
jrose@1920 137 static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) {
jrose@1920 138 return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/));
jrose@1161 139 }
duke@435 140 };
duke@435 141
duke@435 142
duke@435 143 // Abstractions for lookupswitch bytecode
never@2462 144 class LookupswitchPair VALUE_OBJ_CLASS_SPEC {
never@2462 145 private:
never@2462 146 const address _bcp;
duke@435 147
never@2462 148 address addr_at (int offset) const { return _bcp + offset; }
never@2462 149 int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
duke@435 150
duke@435 151 public:
never@2462 152 LookupswitchPair(address bcp): _bcp(bcp) {}
jrose@1920 153 int match() const { return get_Java_u4_at(0 * jintSize); }
jrose@1920 154 int offset() const { return get_Java_u4_at(1 * jintSize); }
duke@435 155 };
duke@435 156
duke@435 157
duke@435 158 class Bytecode_lookupswitch: public Bytecode {
duke@435 159 public:
never@2462 160 Bytecode_lookupswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
never@2462 161 // Defined in ciStreams.hpp
never@2462 162 inline Bytecode_lookupswitch(const ciBytecodeStream* stream);
duke@435 163 void verify() const PRODUCT_RETURN;
duke@435 164
duke@435 165 // Attributes
jrose@1920 166 int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
jrose@1920 167 int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
never@2462 168 LookupswitchPair pair_at(int i) const {
never@2462 169 assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
never@2462 170 return LookupswitchPair(aligned_addr_at(1 + (1 + i)*2*jintSize));
never@2462 171 }
duke@435 172 };
duke@435 173
duke@435 174 class Bytecode_tableswitch: public Bytecode {
duke@435 175 public:
never@2462 176 Bytecode_tableswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
never@2462 177 // Defined in ciStreams.hpp
never@2462 178 inline Bytecode_tableswitch(const ciBytecodeStream* stream);
duke@435 179 void verify() const PRODUCT_RETURN;
duke@435 180
duke@435 181 // Attributes
jrose@1920 182 int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
jrose@1920 183 int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
jrose@1920 184 int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); }
duke@435 185 int dest_offset_at(int i) const;
duke@435 186 int length() { return high_key()-low_key()+1; }
duke@435 187 };
duke@435 188
jrose@1957 189 // Common code for decoding invokes and field references.
duke@435 190
never@2462 191 class Bytecode_member_ref: public Bytecode {
duke@435 192 protected:
never@2462 193 const methodHandle _method; // method containing the bytecode
duke@435 194
never@2462 195 Bytecode_member_ref(methodHandle method, int bci) : Bytecode(method(), method()->bcp_from(bci)), _method(method) {}
never@2462 196
never@2462 197 methodHandle method() const { return _method; }
jrose@1957 198
jrose@1957 199 public:
jrose@1957 200 int index() const; // cache index (loaded from instruction)
jrose@1957 201 int pool_index() const; // constant pool index
coleenp@2497 202 Symbol* name() const; // returns the name of the method or field
coleenp@2497 203 Symbol* signature() const; // returns the signature of the method or field
jrose@1957 204
coleenp@2497 205 BasicType result_type() const; // returns the result type of the getfield or invoke
jrose@1957 206 };
jrose@1957 207
jrose@1957 208 // Abstraction for invoke_{virtual, static, interface, special}
jrose@1957 209
jrose@1957 210 class Bytecode_invoke: public Bytecode_member_ref {
jrose@1957 211 protected:
never@2462 212 // Constructor that skips verification
never@2462 213 Bytecode_invoke(methodHandle method, int bci, bool unused) : Bytecode_member_ref(method, bci) {}
duke@435 214
duke@435 215 public:
never@2462 216 Bytecode_invoke(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
duke@435 217 void verify() const;
duke@435 218
duke@435 219 // Attributes
duke@435 220 methodHandle static_target(TRAPS); // "specified" method (from constant pool)
duke@435 221
duke@435 222 // Testers
jrose@1957 223 bool is_invokeinterface() const { return java_code() == Bytecodes::_invokeinterface; }
jrose@1957 224 bool is_invokevirtual() const { return java_code() == Bytecodes::_invokevirtual; }
jrose@1957 225 bool is_invokestatic() const { return java_code() == Bytecodes::_invokestatic; }
jrose@1957 226 bool is_invokespecial() const { return java_code() == Bytecodes::_invokespecial; }
jrose@1957 227 bool is_invokedynamic() const { return java_code() == Bytecodes::_invokedynamic; }
jrose@1161 228
twisti@1573 229 bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); }
duke@435 230
duke@435 231 bool is_valid() const { return is_invokeinterface() ||
duke@435 232 is_invokevirtual() ||
duke@435 233 is_invokestatic() ||
twisti@1570 234 is_invokespecial() ||
twisti@1570 235 is_invokedynamic(); }
duke@435 236
never@2462 237 // Helper to skip verification. Used is_valid() to check if the result is really an invoke
never@2462 238 inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci);
duke@435 239 };
duke@435 240
never@2462 241 inline Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci) {
never@2462 242 return Bytecode_invoke(method, bci, false);
duke@435 243 }
duke@435 244
duke@435 245
jrose@1957 246 // Abstraction for all field accesses (put/get field/static)
jrose@1957 247 class Bytecode_field: public Bytecode_member_ref {
never@2462 248 public:
never@2462 249 Bytecode_field(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
jrose@1957 250
jrose@1957 251 // Testers
jrose@1957 252 bool is_getfield() const { return java_code() == Bytecodes::_getfield; }
jrose@1957 253 bool is_putfield() const { return java_code() == Bytecodes::_putfield; }
jrose@1957 254 bool is_getstatic() const { return java_code() == Bytecodes::_getstatic; }
jrose@1957 255 bool is_putstatic() const { return java_code() == Bytecodes::_putstatic; }
jrose@1957 256
jrose@1957 257 bool is_getter() const { return is_getfield() || is_getstatic(); }
jrose@1957 258 bool is_static() const { return is_getstatic() || is_putstatic(); }
jrose@1957 259
jrose@1957 260 bool is_valid() const { return is_getfield() ||
jrose@1957 261 is_putfield() ||
jrose@1957 262 is_getstatic() ||
jrose@1957 263 is_putstatic(); }
duke@435 264 void verify() const;
duke@435 265 };
duke@435 266
duke@435 267 // Abstraction for checkcast
duke@435 268 class Bytecode_checkcast: public Bytecode {
duke@435 269 public:
never@2462 270 Bytecode_checkcast(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
duke@435 271 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
duke@435 272
duke@435 273 // Returns index
jrose@1920 274 long index() const { return get_index_u2(Bytecodes::_checkcast); };
duke@435 275 };
duke@435 276
duke@435 277 // Abstraction for instanceof
duke@435 278 class Bytecode_instanceof: public Bytecode {
duke@435 279 public:
never@2462 280 Bytecode_instanceof(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
duke@435 281 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
duke@435 282
duke@435 283 // Returns index
jrose@1920 284 long index() const { return get_index_u2(Bytecodes::_instanceof); };
duke@435 285 };
duke@435 286
duke@435 287 class Bytecode_new: public Bytecode {
duke@435 288 public:
never@2462 289 Bytecode_new(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
duke@435 290 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
duke@435 291
duke@435 292 // Returns index
jrose@1920 293 long index() const { return get_index_u2(Bytecodes::_new); };
duke@435 294 };
duke@435 295
duke@435 296 class Bytecode_multianewarray: public Bytecode {
duke@435 297 public:
never@2462 298 Bytecode_multianewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
duke@435 299 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
duke@435 300
duke@435 301 // Returns index
jrose@1920 302 long index() const { return get_index_u2(Bytecodes::_multianewarray); };
duke@435 303 };
duke@435 304
duke@435 305 class Bytecode_anewarray: public Bytecode {
duke@435 306 public:
never@2462 307 Bytecode_anewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
duke@435 308 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
duke@435 309
duke@435 310 // Returns index
jrose@1920 311 long index() const { return get_index_u2(Bytecodes::_anewarray); };
duke@435 312 };
duke@435 313
duke@435 314 // Abstraction for ldc, ldc_w and ldc2_w
never@2462 315 class Bytecode_loadconstant: public Bytecode {
jrose@1957 316 private:
never@2462 317 const methodHandle _method;
jrose@1957 318
jrose@1957 319 int raw_index() const;
jrose@1957 320
duke@435 321 public:
never@2462 322 Bytecode_loadconstant(methodHandle method, int bci): Bytecode(method(), method->bcp_from(bci)), _method(method) { verify(); }
jrose@1957 323
duke@435 324 void verify() const {
jrose@1957 325 assert(_method.not_null(), "must supply method");
duke@435 326 Bytecodes::Code stdc = Bytecodes::java_code(code());
duke@435 327 assert(stdc == Bytecodes::_ldc ||
duke@435 328 stdc == Bytecodes::_ldc_w ||
duke@435 329 stdc == Bytecodes::_ldc2_w, "load constant");
duke@435 330 }
duke@435 331
jrose@1957 332 // Only non-standard bytecodes (fast_aldc) have CP cache indexes.
jrose@1957 333 bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; }
duke@435 334
jrose@1957 335 int pool_index() const; // index into constant pool
jrose@1957 336 int cache_index() const { // index into CP cache (or -1 if none)
jrose@1957 337 return has_cache_index() ? raw_index() : -1;
jrose@1957 338 }
jrose@1957 339
jrose@1957 340 BasicType result_type() const; // returns the result type of the ldc
jrose@1957 341
jrose@1957 342 oop resolve_constant(TRAPS) const;
duke@435 343 };
duke@435 344
stefank@2314 345 #endif // SHARE_VM_INTERPRETER_BYTECODE_HPP

mercurial