annotate src/share/vm/interpreter/bytecode.hpp @ 844:bd02caa94611

6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
author xdono
date Tue, 28 Jul 2009 12:12:40 -0700
parents be93aad57795
children e66fd840cb6b
rev   line source
duke@0 1 /*
xdono@844 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // Base class for different kinds of abstractions working
duke@0 26 // relative to an objects 'this' pointer.
duke@0 27
duke@0 28 class ThisRelativeObj VALUE_OBJ_CLASS_SPEC {
duke@0 29 private:
duke@0 30 int sign_extend (int x, int size) const { const int s = (BytesPerInt - size)*BitsPerByte; return (x << s) >> s; }
duke@0 31
duke@0 32 public:
duke@0 33 // Address computation
duke@0 34 address addr_at (int offset) const { return (address)this + offset; }
duke@0 35 address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
duke@0 36 int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); }
duke@0 37
duke@0 38 // Java unsigned accessors (using Java spec byte ordering)
duke@0 39 int java_byte_at (int offset) const { return *(jubyte*)addr_at(offset); }
duke@0 40 int java_hwrd_at (int offset) const { return java_byte_at(offset) << (1 * BitsPerByte) | java_byte_at(offset + 1); }
duke@0 41 int java_word_at (int offset) const { return java_hwrd_at(offset) << (2 * BitsPerByte) | java_hwrd_at(offset + 2); }
duke@0 42
duke@0 43 // Java signed accessors (using Java spec byte ordering)
duke@0 44 int java_signed_byte_at(int offset) const { return sign_extend(java_byte_at(offset), 1); }
duke@0 45 int java_signed_hwrd_at(int offset) const { return sign_extend(java_hwrd_at(offset), 2); }
duke@0 46 int java_signed_word_at(int offset) const { return java_word_at(offset) ; }
duke@0 47
duke@0 48 // Fast accessors (using the machine's natural byte ordering)
duke@0 49 int fast_byte_at (int offset) const { return *(jubyte *)addr_at(offset); }
duke@0 50 int fast_hwrd_at (int offset) const { return *(jushort*)addr_at(offset); }
duke@0 51 int fast_word_at (int offset) const { return *(juint *)addr_at(offset); }
duke@0 52
duke@0 53 // Fast signed accessors (using the machine's natural byte ordering)
duke@0 54 int fast_signed_byte_at(int offset) const { return *(jbyte *)addr_at(offset); }
duke@0 55 int fast_signed_hwrd_at(int offset) const { return *(jshort*)addr_at(offset); }
duke@0 56 int fast_signed_word_at(int offset) const { return *(jint *)addr_at(offset); }
duke@0 57
duke@0 58 // Fast manipulators (using the machine's natural byte ordering)
duke@0 59 void set_fast_byte_at (int offset, int x) const { *(jbyte *)addr_at(offset) = (jbyte )x; }
duke@0 60 void set_fast_hwrd_at (int offset, int x) const { *(jshort*)addr_at(offset) = (jshort)x; }
duke@0 61 void set_fast_word_at (int offset, int x) const { *(jint *)addr_at(offset) = (jint )x; }
duke@0 62 };
duke@0 63
duke@0 64
duke@0 65 // The base class for different kinds of bytecode abstractions.
duke@0 66 // Provides the primitive operations to manipulate code relative
duke@0 67 // to an objects 'this' pointer.
duke@0 68
duke@0 69 class Bytecode: public ThisRelativeObj {
duke@0 70 protected:
duke@0 71 u_char byte_at(int offset) const { return *addr_at(offset); }
duke@0 72 bool check_must_rewrite() const;
duke@0 73
duke@0 74 public:
duke@0 75 // Attributes
duke@0 76 address bcp() const { return addr_at(0); }
duke@0 77 address next_bcp() const { return addr_at(0) + Bytecodes::length_at(bcp()); }
jrose@726 78 int instruction_size() const { return Bytecodes::length_at(bcp()); }
duke@0 79
duke@0 80 Bytecodes::Code code() const { return Bytecodes::code_at(addr_at(0)); }
duke@0 81 Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); }
duke@0 82 bool must_rewrite() const { return Bytecodes::can_rewrite(code()) && check_must_rewrite(); }
duke@0 83 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); }
duke@0 84
jrose@726 85 int one_byte_index() const { assert_index_size(1); return byte_at(1); }
jrose@726 86 int two_byte_index() const { assert_index_size(2); return (byte_at(1) << 8) + byte_at(2); }
jrose@726 87
duke@0 88 int offset() const { return (two_byte_index() << 16) >> 16; }
duke@0 89 address destination() const { return bcp() + offset(); }
duke@0 90
duke@0 91 // Attribute modification
duke@0 92 void set_code(Bytecodes::Code code);
duke@0 93
duke@0 94 // Creation
duke@0 95 inline friend Bytecode* Bytecode_at(address bcp);
jrose@726 96
jrose@726 97 private:
jrose@726 98 void assert_index_size(int required_size) const {
jrose@726 99 #ifdef ASSERT
jrose@726 100 int isize = instruction_size() - 1;
jrose@726 101 if (isize == 2 && code() == Bytecodes::_iinc)
jrose@726 102 isize = 1;
jrose@726 103 else if (isize <= 2)
jrose@726 104 ; // no change
jrose@726 105 else if (code() == Bytecodes::_invokedynamic)
jrose@726 106 isize = 4;
jrose@726 107 else
jrose@726 108 isize = 2;
jrose@726 109 assert(isize = required_size, "wrong index size");
jrose@726 110 #endif
jrose@726 111 }
duke@0 112 };
duke@0 113
duke@0 114 inline Bytecode* Bytecode_at(address bcp) {
duke@0 115 return (Bytecode*)bcp;
duke@0 116 }
duke@0 117
duke@0 118
duke@0 119 // Abstractions for lookupswitch bytecode
duke@0 120
duke@0 121 class LookupswitchPair: ThisRelativeObj {
duke@0 122 private:
duke@0 123 int _match;
duke@0 124 int _offset;
duke@0 125
duke@0 126 public:
duke@0 127 int match() const { return java_signed_word_at(0 * jintSize); }
duke@0 128 int offset() const { return java_signed_word_at(1 * jintSize); }
duke@0 129 };
duke@0 130
duke@0 131
duke@0 132 class Bytecode_lookupswitch: public Bytecode {
duke@0 133 public:
duke@0 134 void verify() const PRODUCT_RETURN;
duke@0 135
duke@0 136 // Attributes
duke@0 137 int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
duke@0 138 int number_of_pairs() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
duke@0 139 LookupswitchPair* pair_at(int i) const { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
duke@0 140 return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); }
duke@0 141 // Creation
duke@0 142 inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp);
duke@0 143 };
duke@0 144
duke@0 145 inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
duke@0 146 Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
duke@0 147 debug_only(b->verify());
duke@0 148 return b;
duke@0 149 }
duke@0 150
duke@0 151
duke@0 152 class Bytecode_tableswitch: public Bytecode {
duke@0 153 public:
duke@0 154 void verify() const PRODUCT_RETURN;
duke@0 155
duke@0 156 // Attributes
duke@0 157 int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
duke@0 158 int low_key() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
duke@0 159 int high_key() const { return java_signed_word_at(aligned_offset(1 + 2*jintSize)); }
duke@0 160 int dest_offset_at(int i) const;
duke@0 161 int length() { return high_key()-low_key()+1; }
duke@0 162
duke@0 163 // Creation
duke@0 164 inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp);
duke@0 165 };
duke@0 166
duke@0 167 inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
duke@0 168 Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
duke@0 169 debug_only(b->verify());
duke@0 170 return b;
duke@0 171 }
duke@0 172
duke@0 173
duke@0 174 // Abstraction for invoke_{virtual, static, interface, special}
duke@0 175
duke@0 176 class Bytecode_invoke: public ResourceObj {
duke@0 177 protected:
duke@0 178 methodHandle _method; // method containing the bytecode
duke@0 179 int _bci; // position of the bytecode
duke@0 180
duke@0 181 Bytecode_invoke(methodHandle method, int bci) : _method(method), _bci(bci) {}
duke@0 182
duke@0 183 public:
duke@0 184 void verify() const;
duke@0 185
duke@0 186 // Attributes
duke@0 187 methodHandle method() const { return _method; }
duke@0 188 int bci() const { return _bci; }
duke@0 189 address bcp() const { return _method->bcp_from(bci()); }
duke@0 190
duke@0 191 int index() const; // the constant pool index for the invoke
duke@0 192 symbolOop name() const; // returns the name of the invoked method
duke@0 193 symbolOop signature() const; // returns the signature of the invoked method
duke@0 194 BasicType result_type(Thread *thread) const; // returns the result type of the invoke
duke@0 195
duke@0 196 Bytecodes::Code code() const { return Bytecodes::code_at(bcp(), _method()); }
duke@0 197 Bytecodes::Code adjusted_invoke_code() const { return Bytecodes::java_code(code()); }
duke@0 198
duke@0 199 methodHandle static_target(TRAPS); // "specified" method (from constant pool)
duke@0 200
duke@0 201 // Testers
duke@0 202 bool is_invokeinterface() const { return adjusted_invoke_code() == Bytecodes::_invokeinterface; }
duke@0 203 bool is_invokevirtual() const { return adjusted_invoke_code() == Bytecodes::_invokevirtual; }
duke@0 204 bool is_invokestatic() const { return adjusted_invoke_code() == Bytecodes::_invokestatic; }
duke@0 205 bool is_invokespecial() const { return adjusted_invoke_code() == Bytecodes::_invokespecial; }
jrose@726 206 bool is_invokedynamic() const { return adjusted_invoke_code() == Bytecodes::_invokedynamic; }
jrose@726 207
jrose@726 208 bool has_giant_index() const { return is_invokedynamic(); }
duke@0 209
duke@0 210 bool is_valid() const { return is_invokeinterface() ||
duke@0 211 is_invokevirtual() ||
duke@0 212 is_invokestatic() ||
duke@0 213 is_invokespecial(); }
duke@0 214
duke@0 215 // Creation
duke@0 216 inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
duke@0 217
duke@0 218 // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
duke@0 219 inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
duke@0 220 };
duke@0 221
duke@0 222 inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
duke@0 223 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@0 224 debug_only(b->verify());
duke@0 225 return b;
duke@0 226 }
duke@0 227
duke@0 228 inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
duke@0 229 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@0 230 return b->is_valid() ? b : NULL;
duke@0 231 }
duke@0 232
duke@0 233
duke@0 234 // Abstraction for all field accesses (put/get field/static_
duke@0 235 class Bytecode_field: public Bytecode {
duke@0 236 public:
duke@0 237 void verify() const;
duke@0 238
duke@0 239 int index() const;
duke@0 240 bool is_static() const;
duke@0 241
duke@0 242 // Creation
duke@0 243 inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp);
duke@0 244 };
duke@0 245
duke@0 246 inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) {
duke@0 247 Bytecode_field* b = (Bytecode_field*)bcp;
duke@0 248 debug_only(b->verify());
duke@0 249 return b;
duke@0 250 }
duke@0 251
duke@0 252
duke@0 253 // Abstraction for {get,put}static
duke@0 254
duke@0 255 class Bytecode_static: public Bytecode {
duke@0 256 public:
duke@0 257 void verify() const;
duke@0 258
duke@0 259 // Returns the result type of the send by inspecting the field ref
duke@0 260 BasicType result_type(methodOop method) const;
duke@0 261
duke@0 262 // Creation
duke@0 263 inline friend Bytecode_static* Bytecode_static_at(const methodOop method, address bcp);
duke@0 264 };
duke@0 265
duke@0 266 inline Bytecode_static* Bytecode_static_at(const methodOop method, address bcp) {
duke@0 267 Bytecode_static* b = (Bytecode_static*)bcp;
duke@0 268 debug_only(b->verify());
duke@0 269 return b;
duke@0 270 }
duke@0 271
duke@0 272
duke@0 273 // Abstraction for checkcast
duke@0 274
duke@0 275 class Bytecode_checkcast: public Bytecode {
duke@0 276 public:
duke@0 277 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
duke@0 278
duke@0 279 // Returns index
duke@0 280 long index() const { return java_hwrd_at(1); };
duke@0 281
duke@0 282 // Creation
duke@0 283 inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
duke@0 284 };
duke@0 285
duke@0 286 inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
duke@0 287 Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
duke@0 288 debug_only(b->verify());
duke@0 289 return b;
duke@0 290 }
duke@0 291
duke@0 292
duke@0 293 // Abstraction for instanceof
duke@0 294
duke@0 295 class Bytecode_instanceof: public Bytecode {
duke@0 296 public:
duke@0 297 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
duke@0 298
duke@0 299 // Returns index
duke@0 300 long index() const { return java_hwrd_at(1); };
duke@0 301
duke@0 302 // Creation
duke@0 303 inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
duke@0 304 };
duke@0 305
duke@0 306 inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
duke@0 307 Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
duke@0 308 debug_only(b->verify());
duke@0 309 return b;
duke@0 310 }
duke@0 311
duke@0 312
duke@0 313 class Bytecode_new: public Bytecode {
duke@0 314 public:
duke@0 315 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
duke@0 316
duke@0 317 // Returns index
duke@0 318 long index() const { return java_hwrd_at(1); };
duke@0 319
duke@0 320 // Creation
duke@0 321 inline friend Bytecode_new* Bytecode_new_at(address bcp);
duke@0 322 };
duke@0 323
duke@0 324 inline Bytecode_new* Bytecode_new_at(address bcp) {
duke@0 325 Bytecode_new* b = (Bytecode_new*)bcp;
duke@0 326 debug_only(b->verify());
duke@0 327 return b;
duke@0 328 }
duke@0 329
duke@0 330
duke@0 331 class Bytecode_multianewarray: public Bytecode {
duke@0 332 public:
duke@0 333 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
duke@0 334
duke@0 335 // Returns index
duke@0 336 long index() const { return java_hwrd_at(1); };
duke@0 337
duke@0 338 // Creation
duke@0 339 inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
duke@0 340 };
duke@0 341
duke@0 342 inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
duke@0 343 Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
duke@0 344 debug_only(b->verify());
duke@0 345 return b;
duke@0 346 }
duke@0 347
duke@0 348
duke@0 349 class Bytecode_anewarray: public Bytecode {
duke@0 350 public:
duke@0 351 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
duke@0 352
duke@0 353 // Returns index
duke@0 354 long index() const { return java_hwrd_at(1); };
duke@0 355
duke@0 356 // Creation
duke@0 357 inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
duke@0 358 };
duke@0 359
duke@0 360 inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
duke@0 361 Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
duke@0 362 debug_only(b->verify());
duke@0 363 return b;
duke@0 364 }
duke@0 365
duke@0 366
duke@0 367 // Abstraction for ldc, ldc_w and ldc2_w
duke@0 368
duke@0 369 class Bytecode_loadconstant: public Bytecode {
duke@0 370 public:
duke@0 371 void verify() const {
duke@0 372 Bytecodes::Code stdc = Bytecodes::java_code(code());
duke@0 373 assert(stdc == Bytecodes::_ldc ||
duke@0 374 stdc == Bytecodes::_ldc_w ||
duke@0 375 stdc == Bytecodes::_ldc2_w, "load constant");
duke@0 376 }
duke@0 377
duke@0 378 int index() const;
duke@0 379
duke@0 380 inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp);
duke@0 381 };
duke@0 382
duke@0 383 inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) {
duke@0 384 Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp;
duke@0 385 debug_only(b->verify());
duke@0 386 return b;
duke@0 387 }