annotate src/share/vm/interpreter/bytecode.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children be93aad57795
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2002 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 // Note: Even though it seems that the fast_index & set_fast_index
duke@0 70 // functions are machine specific, they're not. They only use
duke@0 71 // the natural way to store a 16bit index on a given machine,
duke@0 72 // independent of the particular byte ordering. Since all other
duke@0 73 // places in the system that refer to these indices use the
duke@0 74 // same method (the natural byte ordering on the platform)
duke@0 75 // this will always work and be machine-independent).
duke@0 76
duke@0 77 class Bytecode: public ThisRelativeObj {
duke@0 78 protected:
duke@0 79 u_char byte_at(int offset) const { return *addr_at(offset); }
duke@0 80 bool check_must_rewrite() const;
duke@0 81
duke@0 82 public:
duke@0 83 // Attributes
duke@0 84 address bcp() const { return addr_at(0); }
duke@0 85 address next_bcp() const { return addr_at(0) + Bytecodes::length_at(bcp()); }
duke@0 86
duke@0 87 Bytecodes::Code code() const { return Bytecodes::code_at(addr_at(0)); }
duke@0 88 Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); }
duke@0 89 bool must_rewrite() const { return Bytecodes::can_rewrite(code()) && check_must_rewrite(); }
duke@0 90 bool is_active_breakpoint() const { return Bytecodes::is_active_breakpoint_at(bcp()); }
duke@0 91
duke@0 92 int one_byte_index() const { return byte_at(1); }
duke@0 93 int two_byte_index() const { return (byte_at(1) << 8) + byte_at(2); }
duke@0 94 int offset() const { return (two_byte_index() << 16) >> 16; }
duke@0 95 address destination() const { return bcp() + offset(); }
duke@0 96 int fast_index() const { return Bytes::get_native_u2(addr_at(1)); }
duke@0 97
duke@0 98 // Attribute modification
duke@0 99 void set_code(Bytecodes::Code code);
duke@0 100 void set_fast_index(int i);
duke@0 101
duke@0 102 // Creation
duke@0 103 inline friend Bytecode* Bytecode_at(address bcp);
duke@0 104 };
duke@0 105
duke@0 106 inline Bytecode* Bytecode_at(address bcp) {
duke@0 107 return (Bytecode*)bcp;
duke@0 108 }
duke@0 109
duke@0 110
duke@0 111 // Abstractions for lookupswitch bytecode
duke@0 112
duke@0 113 class LookupswitchPair: ThisRelativeObj {
duke@0 114 private:
duke@0 115 int _match;
duke@0 116 int _offset;
duke@0 117
duke@0 118 public:
duke@0 119 int match() const { return java_signed_word_at(0 * jintSize); }
duke@0 120 int offset() const { return java_signed_word_at(1 * jintSize); }
duke@0 121 };
duke@0 122
duke@0 123
duke@0 124 class Bytecode_lookupswitch: public Bytecode {
duke@0 125 public:
duke@0 126 void verify() const PRODUCT_RETURN;
duke@0 127
duke@0 128 // Attributes
duke@0 129 int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
duke@0 130 int number_of_pairs() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
duke@0 131 LookupswitchPair* pair_at(int i) const { assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
duke@0 132 return (LookupswitchPair*)aligned_addr_at(1 + (1 + i)*2*jintSize); }
duke@0 133 // Creation
duke@0 134 inline friend Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp);
duke@0 135 };
duke@0 136
duke@0 137 inline Bytecode_lookupswitch* Bytecode_lookupswitch_at(address bcp) {
duke@0 138 Bytecode_lookupswitch* b = (Bytecode_lookupswitch*)bcp;
duke@0 139 debug_only(b->verify());
duke@0 140 return b;
duke@0 141 }
duke@0 142
duke@0 143
duke@0 144 class Bytecode_tableswitch: public Bytecode {
duke@0 145 public:
duke@0 146 void verify() const PRODUCT_RETURN;
duke@0 147
duke@0 148 // Attributes
duke@0 149 int default_offset() const { return java_signed_word_at(aligned_offset(1 + 0*jintSize)); }
duke@0 150 int low_key() const { return java_signed_word_at(aligned_offset(1 + 1*jintSize)); }
duke@0 151 int high_key() const { return java_signed_word_at(aligned_offset(1 + 2*jintSize)); }
duke@0 152 int dest_offset_at(int i) const;
duke@0 153 int length() { return high_key()-low_key()+1; }
duke@0 154
duke@0 155 // Creation
duke@0 156 inline friend Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp);
duke@0 157 };
duke@0 158
duke@0 159 inline Bytecode_tableswitch* Bytecode_tableswitch_at(address bcp) {
duke@0 160 Bytecode_tableswitch* b = (Bytecode_tableswitch*)bcp;
duke@0 161 debug_only(b->verify());
duke@0 162 return b;
duke@0 163 }
duke@0 164
duke@0 165
duke@0 166 // Abstraction for invoke_{virtual, static, interface, special}
duke@0 167
duke@0 168 class Bytecode_invoke: public ResourceObj {
duke@0 169 protected:
duke@0 170 methodHandle _method; // method containing the bytecode
duke@0 171 int _bci; // position of the bytecode
duke@0 172
duke@0 173 Bytecode_invoke(methodHandle method, int bci) : _method(method), _bci(bci) {}
duke@0 174
duke@0 175 public:
duke@0 176 void verify() const;
duke@0 177
duke@0 178 // Attributes
duke@0 179 methodHandle method() const { return _method; }
duke@0 180 int bci() const { return _bci; }
duke@0 181 address bcp() const { return _method->bcp_from(bci()); }
duke@0 182
duke@0 183 int index() const; // the constant pool index for the invoke
duke@0 184 symbolOop name() const; // returns the name of the invoked method
duke@0 185 symbolOop signature() const; // returns the signature of the invoked method
duke@0 186 BasicType result_type(Thread *thread) const; // returns the result type of the invoke
duke@0 187
duke@0 188 Bytecodes::Code code() const { return Bytecodes::code_at(bcp(), _method()); }
duke@0 189 Bytecodes::Code adjusted_invoke_code() const { return Bytecodes::java_code(code()); }
duke@0 190
duke@0 191 methodHandle static_target(TRAPS); // "specified" method (from constant pool)
duke@0 192
duke@0 193 // Testers
duke@0 194 bool is_invokeinterface() const { return adjusted_invoke_code() == Bytecodes::_invokeinterface; }
duke@0 195 bool is_invokevirtual() const { return adjusted_invoke_code() == Bytecodes::_invokevirtual; }
duke@0 196 bool is_invokestatic() const { return adjusted_invoke_code() == Bytecodes::_invokestatic; }
duke@0 197 bool is_invokespecial() const { return adjusted_invoke_code() == Bytecodes::_invokespecial; }
duke@0 198
duke@0 199 bool is_valid() const { return is_invokeinterface() ||
duke@0 200 is_invokevirtual() ||
duke@0 201 is_invokestatic() ||
duke@0 202 is_invokespecial(); }
duke@0 203
duke@0 204 // Creation
duke@0 205 inline friend Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci);
duke@0 206
duke@0 207 // Like Bytecode_invoke_at. Instead it returns NULL if the bci is not at an invoke.
duke@0 208 inline friend Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci);
duke@0 209 };
duke@0 210
duke@0 211 inline Bytecode_invoke* Bytecode_invoke_at(methodHandle method, int bci) {
duke@0 212 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@0 213 debug_only(b->verify());
duke@0 214 return b;
duke@0 215 }
duke@0 216
duke@0 217 inline Bytecode_invoke* Bytecode_invoke_at_check(methodHandle method, int bci) {
duke@0 218 Bytecode_invoke* b = new Bytecode_invoke(method, bci);
duke@0 219 return b->is_valid() ? b : NULL;
duke@0 220 }
duke@0 221
duke@0 222
duke@0 223 // Abstraction for all field accesses (put/get field/static_
duke@0 224 class Bytecode_field: public Bytecode {
duke@0 225 public:
duke@0 226 void verify() const;
duke@0 227
duke@0 228 int index() const;
duke@0 229 bool is_static() const;
duke@0 230
duke@0 231 // Creation
duke@0 232 inline friend Bytecode_field* Bytecode_field_at(const methodOop method, address bcp);
duke@0 233 };
duke@0 234
duke@0 235 inline Bytecode_field* Bytecode_field_at(const methodOop method, address bcp) {
duke@0 236 Bytecode_field* b = (Bytecode_field*)bcp;
duke@0 237 debug_only(b->verify());
duke@0 238 return b;
duke@0 239 }
duke@0 240
duke@0 241
duke@0 242 // Abstraction for {get,put}static
duke@0 243
duke@0 244 class Bytecode_static: public Bytecode {
duke@0 245 public:
duke@0 246 void verify() const;
duke@0 247
duke@0 248 // Returns the result type of the send by inspecting the field ref
duke@0 249 BasicType result_type(methodOop method) const;
duke@0 250
duke@0 251 // Creation
duke@0 252 inline friend Bytecode_static* Bytecode_static_at(const methodOop method, address bcp);
duke@0 253 };
duke@0 254
duke@0 255 inline Bytecode_static* Bytecode_static_at(const methodOop method, address bcp) {
duke@0 256 Bytecode_static* b = (Bytecode_static*)bcp;
duke@0 257 debug_only(b->verify());
duke@0 258 return b;
duke@0 259 }
duke@0 260
duke@0 261
duke@0 262 // Abstraction for checkcast
duke@0 263
duke@0 264 class Bytecode_checkcast: public Bytecode {
duke@0 265 public:
duke@0 266 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
duke@0 267
duke@0 268 // Returns index
duke@0 269 long index() const { return java_hwrd_at(1); };
duke@0 270
duke@0 271 // Creation
duke@0 272 inline friend Bytecode_checkcast* Bytecode_checkcast_at(address bcp);
duke@0 273 };
duke@0 274
duke@0 275 inline Bytecode_checkcast* Bytecode_checkcast_at(address bcp) {
duke@0 276 Bytecode_checkcast* b = (Bytecode_checkcast*)bcp;
duke@0 277 debug_only(b->verify());
duke@0 278 return b;
duke@0 279 }
duke@0 280
duke@0 281
duke@0 282 // Abstraction for instanceof
duke@0 283
duke@0 284 class Bytecode_instanceof: public Bytecode {
duke@0 285 public:
duke@0 286 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
duke@0 287
duke@0 288 // Returns index
duke@0 289 long index() const { return java_hwrd_at(1); };
duke@0 290
duke@0 291 // Creation
duke@0 292 inline friend Bytecode_instanceof* Bytecode_instanceof_at(address bcp);
duke@0 293 };
duke@0 294
duke@0 295 inline Bytecode_instanceof* Bytecode_instanceof_at(address bcp) {
duke@0 296 Bytecode_instanceof* b = (Bytecode_instanceof*)bcp;
duke@0 297 debug_only(b->verify());
duke@0 298 return b;
duke@0 299 }
duke@0 300
duke@0 301
duke@0 302 class Bytecode_new: public Bytecode {
duke@0 303 public:
duke@0 304 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
duke@0 305
duke@0 306 // Returns index
duke@0 307 long index() const { return java_hwrd_at(1); };
duke@0 308
duke@0 309 // Creation
duke@0 310 inline friend Bytecode_new* Bytecode_new_at(address bcp);
duke@0 311 };
duke@0 312
duke@0 313 inline Bytecode_new* Bytecode_new_at(address bcp) {
duke@0 314 Bytecode_new* b = (Bytecode_new*)bcp;
duke@0 315 debug_only(b->verify());
duke@0 316 return b;
duke@0 317 }
duke@0 318
duke@0 319
duke@0 320 class Bytecode_multianewarray: public Bytecode {
duke@0 321 public:
duke@0 322 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
duke@0 323
duke@0 324 // Returns index
duke@0 325 long index() const { return java_hwrd_at(1); };
duke@0 326
duke@0 327 // Creation
duke@0 328 inline friend Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp);
duke@0 329 };
duke@0 330
duke@0 331 inline Bytecode_multianewarray* Bytecode_multianewarray_at(address bcp) {
duke@0 332 Bytecode_multianewarray* b = (Bytecode_multianewarray*)bcp;
duke@0 333 debug_only(b->verify());
duke@0 334 return b;
duke@0 335 }
duke@0 336
duke@0 337
duke@0 338 class Bytecode_anewarray: public Bytecode {
duke@0 339 public:
duke@0 340 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
duke@0 341
duke@0 342 // Returns index
duke@0 343 long index() const { return java_hwrd_at(1); };
duke@0 344
duke@0 345 // Creation
duke@0 346 inline friend Bytecode_anewarray* Bytecode_anewarray_at(address bcp);
duke@0 347 };
duke@0 348
duke@0 349 inline Bytecode_anewarray* Bytecode_anewarray_at(address bcp) {
duke@0 350 Bytecode_anewarray* b = (Bytecode_anewarray*)bcp;
duke@0 351 debug_only(b->verify());
duke@0 352 return b;
duke@0 353 }
duke@0 354
duke@0 355
duke@0 356 // Abstraction for ldc, ldc_w and ldc2_w
duke@0 357
duke@0 358 class Bytecode_loadconstant: public Bytecode {
duke@0 359 public:
duke@0 360 void verify() const {
duke@0 361 Bytecodes::Code stdc = Bytecodes::java_code(code());
duke@0 362 assert(stdc == Bytecodes::_ldc ||
duke@0 363 stdc == Bytecodes::_ldc_w ||
duke@0 364 stdc == Bytecodes::_ldc2_w, "load constant");
duke@0 365 }
duke@0 366
duke@0 367 int index() const;
duke@0 368
duke@0 369 inline friend Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp);
duke@0 370 };
duke@0 371
duke@0 372 inline Bytecode_loadconstant* Bytecode_loadconstant_at(const methodOop method, address bcp) {
duke@0 373 Bytecode_loadconstant* b = (Bytecode_loadconstant*)bcp;
duke@0 374 debug_only(b->verify());
duke@0 375 return b;
duke@0 376 }