src/share/vm/interpreter/bytecode.hpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 1573
dd57230ba8fe
child 1934
e9ff18c4ace7
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

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

mercurial