src/share/vm/interpreter/bytecode.hpp

Tue, 21 Apr 2009 23:21:04 -0700

author
jrose
date
Tue, 21 Apr 2009 23:21:04 -0700
changeset 1161
be93aad57795
parent 435
a61af66fc99e
child 1279
bd02caa94611
permissions
-rw-r--r--

6655646: dynamic languages need dynamically linked call sites
Summary: invokedynamic instruction (JSR 292 RI)
Reviewed-by: twisti, never

duke@435 1 /*
duke@435 2 * Copyright 1997-2002 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any 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
jrose@1161 208 bool has_giant_index() const { return is_invokedynamic(); }
duke@435 209
duke@435 210 bool is_valid() const { return is_invokeinterface() ||
duke@435 211 is_invokevirtual() ||
duke@435 212 is_invokestatic() ||
duke@435 213 is_invokespecial(); }
duke@435 214
duke@435 215 // Creation
duke@435 216 inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
duke@435 217
duke@435 218 // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
duke@435 219 inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
duke@435 220 };
duke@435 221
duke@435 222 inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
duke@435 223 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@435 224 debug_only(b->verify());
duke@435 225 return b;
duke@435 226 }
duke@435 227
duke@435 228 inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
duke@435 229 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@435 230 return b->is_valid() ? b : NULL;
duke@435 231 }
duke@435 232
duke@435 233
duke@435 234 // Abstraction for all field accesses (put/get field/static_
duke@435 235 class Bytecode_field: public Bytecode {
duke@435 236 public:
duke@435 237 void verify() const;
duke@435 238
duke@435 239 int index() const;
duke@435 240 bool is_static() const;
duke@435 241
duke@435 242 // Creation
duke@435 243 inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp);
duke@435 244 };
duke@435 245
duke@435 246 inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) {
duke@435 247 Bytecode_field* b = (Bytecode_field*)bcp;
duke@435 248 debug_only(b->verify());
duke@435 249 return b;
duke@435 250 }
duke@435 251
duke@435 252
duke@435 253 // Abstraction for {get,put}static
duke@435 254
duke@435 255 class Bytecode_static: public Bytecode {
duke@435 256 public:
duke@435 257 void verify() const;
duke@435 258
duke@435 259 // Returns the result type of the send by inspecting the field ref
duke@435 260 BasicType result_type(methodOop method) const;
duke@435 261
duke@435 262 // Creation
duke@435 263 inline friend Bytecode_static* Bytecode_static_at(const methodOop method, address bcp);
duke@435 264 };
duke@435 265
duke@435 266 inline Bytecode_static* Bytecode_static_at(const methodOop method, address bcp) {
duke@435 267 Bytecode_static* b = (Bytecode_static*)bcp;
duke@435 268 debug_only(b->verify());
duke@435 269 return b;
duke@435 270 }
duke@435 271
duke@435 272
duke@435 273 // Abstraction for checkcast
duke@435 274
duke@435 275 class Bytecode_checkcast: public Bytecode {
duke@435 276 public:
duke@435 277 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
duke@435 278
duke@435 279 // Returns index
duke@435 280 long index() const { return java_hwrd_at(1); };
duke@435 281
duke@435 282 // Creation
duke@435 283 inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
duke@435 284 };
duke@435 285
duke@435 286 inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
duke@435 287 Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
duke@435 288 debug_only(b->verify());
duke@435 289 return b;
duke@435 290 }
duke@435 291
duke@435 292
duke@435 293 // Abstraction for instanceof
duke@435 294
duke@435 295 class Bytecode_instanceof: public Bytecode {
duke@435 296 public:
duke@435 297 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
duke@435 298
duke@435 299 // Returns index
duke@435 300 long index() const { return java_hwrd_at(1); };
duke@435 301
duke@435 302 // Creation
duke@435 303 inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
duke@435 304 };
duke@435 305
duke@435 306 inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
duke@435 307 Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
duke@435 308 debug_only(b->verify());
duke@435 309 return b;
duke@435 310 }
duke@435 311
duke@435 312
duke@435 313 class Bytecode_new: public Bytecode {
duke@435 314 public:
duke@435 315 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
duke@435 316
duke@435 317 // Returns index
duke@435 318 long index() const { return java_hwrd_at(1); };
duke@435 319
duke@435 320 // Creation
duke@435 321 inline friend Bytecode_new* Bytecode_new_at(address bcp);
duke@435 322 };
duke@435 323
duke@435 324 inline Bytecode_new* Bytecode_new_at(address bcp) {
duke@435 325 Bytecode_new* b = (Bytecode_new*)bcp;
duke@435 326 debug_only(b->verify());
duke@435 327 return b;
duke@435 328 }
duke@435 329
duke@435 330
duke@435 331 class Bytecode_multianewarray: public Bytecode {
duke@435 332 public:
duke@435 333 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
duke@435 334
duke@435 335 // Returns index
duke@435 336 long index() const { return java_hwrd_at(1); };
duke@435 337
duke@435 338 // Creation
duke@435 339 inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
duke@435 340 };
duke@435 341
duke@435 342 inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
duke@435 343 Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
duke@435 344 debug_only(b->verify());
duke@435 345 return b;
duke@435 346 }
duke@435 347
duke@435 348
duke@435 349 class Bytecode_anewarray: public Bytecode {
duke@435 350 public:
duke@435 351 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
duke@435 352
duke@435 353 // Returns index
duke@435 354 long index() const { return java_hwrd_at(1); };
duke@435 355
duke@435 356 // Creation
duke@435 357 inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
duke@435 358 };
duke@435 359
duke@435 360 inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
duke@435 361 Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
duke@435 362 debug_only(b->verify());
duke@435 363 return b;
duke@435 364 }
duke@435 365
duke@435 366
duke@435 367 // Abstraction for ldc, ldc_w and ldc2_w
duke@435 368
duke@435 369 class Bytecode_loadconstant: public Bytecode {
duke@435 370 public:
duke@435 371 void verify() const {
duke@435 372 Bytecodes::Code stdc = Bytecodes::java_code(code());
duke@435 373 assert(stdc == Bytecodes::_ldc ||
duke@435 374 stdc == Bytecodes::_ldc_w ||
duke@435 375 stdc == Bytecodes::_ldc2_w, "load constant");
duke@435 376 }
duke@435 377
duke@435 378 int index() const;
duke@435 379
duke@435 380 inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp);
duke@435 381 };
duke@435 382
duke@435 383 inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) {
duke@435 384 Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp;
duke@435 385 debug_only(b->verify());
duke@435 386 return b;
duke@435 387 }

mercurial