src/share/vm/interpreter/bytecodes.hpp

Wed, 02 Jun 2010 22:45:42 -0700

author
jrose
date
Wed, 02 Jun 2010 22:45:42 -0700
changeset 1934
e9ff18c4ace7
parent 1907
c18cbe5936b8
parent 1925
de91a2f25c7e
child 1957
136b78722a08
permissions
-rw-r--r--

Merge

duke@435 1 /*
jrose@1934 2 * Copyright (c) 1997, 2010, 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 // Bytecodes specifies all bytecodes used in the VM and
duke@435 26 // provides utility functions to get bytecode attributes.
duke@435 27
duke@435 28 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java
duke@435 29 class Bytecodes: AllStatic {
duke@435 30 public:
duke@435 31 enum Code {
duke@435 32 _illegal = -1,
duke@435 33
duke@435 34 // Java bytecodes
duke@435 35 _nop = 0, // 0x00
duke@435 36 _aconst_null = 1, // 0x01
duke@435 37 _iconst_m1 = 2, // 0x02
duke@435 38 _iconst_0 = 3, // 0x03
duke@435 39 _iconst_1 = 4, // 0x04
duke@435 40 _iconst_2 = 5, // 0x05
duke@435 41 _iconst_3 = 6, // 0x06
duke@435 42 _iconst_4 = 7, // 0x07
duke@435 43 _iconst_5 = 8, // 0x08
duke@435 44 _lconst_0 = 9, // 0x09
duke@435 45 _lconst_1 = 10, // 0x0a
duke@435 46 _fconst_0 = 11, // 0x0b
duke@435 47 _fconst_1 = 12, // 0x0c
duke@435 48 _fconst_2 = 13, // 0x0d
duke@435 49 _dconst_0 = 14, // 0x0e
duke@435 50 _dconst_1 = 15, // 0x0f
duke@435 51 _bipush = 16, // 0x10
duke@435 52 _sipush = 17, // 0x11
duke@435 53 _ldc = 18, // 0x12
duke@435 54 _ldc_w = 19, // 0x13
duke@435 55 _ldc2_w = 20, // 0x14
duke@435 56 _iload = 21, // 0x15
duke@435 57 _lload = 22, // 0x16
duke@435 58 _fload = 23, // 0x17
duke@435 59 _dload = 24, // 0x18
duke@435 60 _aload = 25, // 0x19
duke@435 61 _iload_0 = 26, // 0x1a
duke@435 62 _iload_1 = 27, // 0x1b
duke@435 63 _iload_2 = 28, // 0x1c
duke@435 64 _iload_3 = 29, // 0x1d
duke@435 65 _lload_0 = 30, // 0x1e
duke@435 66 _lload_1 = 31, // 0x1f
duke@435 67 _lload_2 = 32, // 0x20
duke@435 68 _lload_3 = 33, // 0x21
duke@435 69 _fload_0 = 34, // 0x22
duke@435 70 _fload_1 = 35, // 0x23
duke@435 71 _fload_2 = 36, // 0x24
duke@435 72 _fload_3 = 37, // 0x25
duke@435 73 _dload_0 = 38, // 0x26
duke@435 74 _dload_1 = 39, // 0x27
duke@435 75 _dload_2 = 40, // 0x28
duke@435 76 _dload_3 = 41, // 0x29
duke@435 77 _aload_0 = 42, // 0x2a
duke@435 78 _aload_1 = 43, // 0x2b
duke@435 79 _aload_2 = 44, // 0x2c
duke@435 80 _aload_3 = 45, // 0x2d
duke@435 81 _iaload = 46, // 0x2e
duke@435 82 _laload = 47, // 0x2f
duke@435 83 _faload = 48, // 0x30
duke@435 84 _daload = 49, // 0x31
duke@435 85 _aaload = 50, // 0x32
duke@435 86 _baload = 51, // 0x33
duke@435 87 _caload = 52, // 0x34
duke@435 88 _saload = 53, // 0x35
duke@435 89 _istore = 54, // 0x36
duke@435 90 _lstore = 55, // 0x37
duke@435 91 _fstore = 56, // 0x38
duke@435 92 _dstore = 57, // 0x39
duke@435 93 _astore = 58, // 0x3a
duke@435 94 _istore_0 = 59, // 0x3b
duke@435 95 _istore_1 = 60, // 0x3c
duke@435 96 _istore_2 = 61, // 0x3d
duke@435 97 _istore_3 = 62, // 0x3e
duke@435 98 _lstore_0 = 63, // 0x3f
duke@435 99 _lstore_1 = 64, // 0x40
duke@435 100 _lstore_2 = 65, // 0x41
duke@435 101 _lstore_3 = 66, // 0x42
duke@435 102 _fstore_0 = 67, // 0x43
duke@435 103 _fstore_1 = 68, // 0x44
duke@435 104 _fstore_2 = 69, // 0x45
duke@435 105 _fstore_3 = 70, // 0x46
duke@435 106 _dstore_0 = 71, // 0x47
duke@435 107 _dstore_1 = 72, // 0x48
duke@435 108 _dstore_2 = 73, // 0x49
duke@435 109 _dstore_3 = 74, // 0x4a
duke@435 110 _astore_0 = 75, // 0x4b
duke@435 111 _astore_1 = 76, // 0x4c
duke@435 112 _astore_2 = 77, // 0x4d
duke@435 113 _astore_3 = 78, // 0x4e
duke@435 114 _iastore = 79, // 0x4f
duke@435 115 _lastore = 80, // 0x50
duke@435 116 _fastore = 81, // 0x51
duke@435 117 _dastore = 82, // 0x52
duke@435 118 _aastore = 83, // 0x53
duke@435 119 _bastore = 84, // 0x54
duke@435 120 _castore = 85, // 0x55
duke@435 121 _sastore = 86, // 0x56
duke@435 122 _pop = 87, // 0x57
duke@435 123 _pop2 = 88, // 0x58
duke@435 124 _dup = 89, // 0x59
duke@435 125 _dup_x1 = 90, // 0x5a
duke@435 126 _dup_x2 = 91, // 0x5b
duke@435 127 _dup2 = 92, // 0x5c
duke@435 128 _dup2_x1 = 93, // 0x5d
duke@435 129 _dup2_x2 = 94, // 0x5e
duke@435 130 _swap = 95, // 0x5f
duke@435 131 _iadd = 96, // 0x60
duke@435 132 _ladd = 97, // 0x61
duke@435 133 _fadd = 98, // 0x62
duke@435 134 _dadd = 99, // 0x63
duke@435 135 _isub = 100, // 0x64
duke@435 136 _lsub = 101, // 0x65
duke@435 137 _fsub = 102, // 0x66
duke@435 138 _dsub = 103, // 0x67
duke@435 139 _imul = 104, // 0x68
duke@435 140 _lmul = 105, // 0x69
duke@435 141 _fmul = 106, // 0x6a
duke@435 142 _dmul = 107, // 0x6b
duke@435 143 _idiv = 108, // 0x6c
duke@435 144 _ldiv = 109, // 0x6d
duke@435 145 _fdiv = 110, // 0x6e
duke@435 146 _ddiv = 111, // 0x6f
duke@435 147 _irem = 112, // 0x70
duke@435 148 _lrem = 113, // 0x71
duke@435 149 _frem = 114, // 0x72
duke@435 150 _drem = 115, // 0x73
duke@435 151 _ineg = 116, // 0x74
duke@435 152 _lneg = 117, // 0x75
duke@435 153 _fneg = 118, // 0x76
duke@435 154 _dneg = 119, // 0x77
duke@435 155 _ishl = 120, // 0x78
duke@435 156 _lshl = 121, // 0x79
duke@435 157 _ishr = 122, // 0x7a
duke@435 158 _lshr = 123, // 0x7b
duke@435 159 _iushr = 124, // 0x7c
duke@435 160 _lushr = 125, // 0x7d
duke@435 161 _iand = 126, // 0x7e
duke@435 162 _land = 127, // 0x7f
duke@435 163 _ior = 128, // 0x80
duke@435 164 _lor = 129, // 0x81
duke@435 165 _ixor = 130, // 0x82
duke@435 166 _lxor = 131, // 0x83
duke@435 167 _iinc = 132, // 0x84
duke@435 168 _i2l = 133, // 0x85
duke@435 169 _i2f = 134, // 0x86
duke@435 170 _i2d = 135, // 0x87
duke@435 171 _l2i = 136, // 0x88
duke@435 172 _l2f = 137, // 0x89
duke@435 173 _l2d = 138, // 0x8a
duke@435 174 _f2i = 139, // 0x8b
duke@435 175 _f2l = 140, // 0x8c
duke@435 176 _f2d = 141, // 0x8d
duke@435 177 _d2i = 142, // 0x8e
duke@435 178 _d2l = 143, // 0x8f
duke@435 179 _d2f = 144, // 0x90
duke@435 180 _i2b = 145, // 0x91
duke@435 181 _i2c = 146, // 0x92
duke@435 182 _i2s = 147, // 0x93
duke@435 183 _lcmp = 148, // 0x94
duke@435 184 _fcmpl = 149, // 0x95
duke@435 185 _fcmpg = 150, // 0x96
duke@435 186 _dcmpl = 151, // 0x97
duke@435 187 _dcmpg = 152, // 0x98
duke@435 188 _ifeq = 153, // 0x99
duke@435 189 _ifne = 154, // 0x9a
duke@435 190 _iflt = 155, // 0x9b
duke@435 191 _ifge = 156, // 0x9c
duke@435 192 _ifgt = 157, // 0x9d
duke@435 193 _ifle = 158, // 0x9e
duke@435 194 _if_icmpeq = 159, // 0x9f
duke@435 195 _if_icmpne = 160, // 0xa0
duke@435 196 _if_icmplt = 161, // 0xa1
duke@435 197 _if_icmpge = 162, // 0xa2
duke@435 198 _if_icmpgt = 163, // 0xa3
duke@435 199 _if_icmple = 164, // 0xa4
duke@435 200 _if_acmpeq = 165, // 0xa5
duke@435 201 _if_acmpne = 166, // 0xa6
duke@435 202 _goto = 167, // 0xa7
duke@435 203 _jsr = 168, // 0xa8
duke@435 204 _ret = 169, // 0xa9
duke@435 205 _tableswitch = 170, // 0xaa
duke@435 206 _lookupswitch = 171, // 0xab
duke@435 207 _ireturn = 172, // 0xac
duke@435 208 _lreturn = 173, // 0xad
duke@435 209 _freturn = 174, // 0xae
duke@435 210 _dreturn = 175, // 0xaf
duke@435 211 _areturn = 176, // 0xb0
duke@435 212 _return = 177, // 0xb1
duke@435 213 _getstatic = 178, // 0xb2
duke@435 214 _putstatic = 179, // 0xb3
duke@435 215 _getfield = 180, // 0xb4
duke@435 216 _putfield = 181, // 0xb5
duke@435 217 _invokevirtual = 182, // 0xb6
duke@435 218 _invokespecial = 183, // 0xb7
duke@435 219 _invokestatic = 184, // 0xb8
duke@435 220 _invokeinterface = 185, // 0xb9
jrose@1161 221 _invokedynamic = 186, // 0xba // if EnableInvokeDynamic
duke@435 222 _new = 187, // 0xbb
duke@435 223 _newarray = 188, // 0xbc
duke@435 224 _anewarray = 189, // 0xbd
duke@435 225 _arraylength = 190, // 0xbe
duke@435 226 _athrow = 191, // 0xbf
duke@435 227 _checkcast = 192, // 0xc0
duke@435 228 _instanceof = 193, // 0xc1
duke@435 229 _monitorenter = 194, // 0xc2
duke@435 230 _monitorexit = 195, // 0xc3
duke@435 231 _wide = 196, // 0xc4
duke@435 232 _multianewarray = 197, // 0xc5
duke@435 233 _ifnull = 198, // 0xc6
duke@435 234 _ifnonnull = 199, // 0xc7
duke@435 235 _goto_w = 200, // 0xc8
duke@435 236 _jsr_w = 201, // 0xc9
duke@435 237 _breakpoint = 202, // 0xca
duke@435 238
duke@435 239 number_of_java_codes,
duke@435 240
duke@435 241 // JVM bytecodes
duke@435 242 _fast_agetfield = number_of_java_codes,
duke@435 243 _fast_bgetfield ,
duke@435 244 _fast_cgetfield ,
duke@435 245 _fast_dgetfield ,
duke@435 246 _fast_fgetfield ,
duke@435 247 _fast_igetfield ,
duke@435 248 _fast_lgetfield ,
duke@435 249 _fast_sgetfield ,
duke@435 250
duke@435 251 _fast_aputfield ,
duke@435 252 _fast_bputfield ,
duke@435 253 _fast_cputfield ,
duke@435 254 _fast_dputfield ,
duke@435 255 _fast_fputfield ,
duke@435 256 _fast_iputfield ,
duke@435 257 _fast_lputfield ,
duke@435 258 _fast_sputfield ,
duke@435 259
duke@435 260 _fast_aload_0 ,
duke@435 261 _fast_iaccess_0 ,
duke@435 262 _fast_aaccess_0 ,
duke@435 263 _fast_faccess_0 ,
duke@435 264
duke@435 265 _fast_iload ,
duke@435 266 _fast_iload2 ,
duke@435 267 _fast_icaload ,
duke@435 268
duke@435 269 _fast_invokevfinal ,
duke@435 270 _fast_linearswitch ,
duke@435 271 _fast_binaryswitch ,
duke@435 272
duke@435 273 _return_register_finalizer ,
duke@435 274
duke@435 275 _shouldnotreachhere, // For debugging
duke@435 276
duke@435 277 // Platform specific JVM bytecodes
duke@435 278 #include "incls/_bytecodes_pd.hpp.incl"
duke@435 279
duke@435 280 number_of_codes
duke@435 281 };
duke@435 282
jrose@1920 283 // Flag bits derived from format strings, can_trap, can_rewrite, etc.:
jrose@1920 284 enum Flags {
jrose@1920 285 // semantic flags:
jrose@1920 286 _bc_can_trap = 1<<0, // bytecode execution can trap or block
jrose@1920 287 _bc_can_rewrite = 1<<1, // bytecode execution has an alternate form
jrose@1920 288
jrose@1920 289 // format bits (determined only by the format string):
jrose@1920 290 _fmt_has_c = 1<<2, // constant, such as sipush "bcc"
jrose@1920 291 _fmt_has_j = 1<<3, // constant pool cache index, such as getfield "bjj"
jrose@1920 292 _fmt_has_k = 1<<4, // constant pool index, such as ldc "bk"
jrose@1920 293 _fmt_has_i = 1<<5, // local index, such as iload
jrose@1920 294 _fmt_has_o = 1<<6, // offset, such as ifeq
jrose@1920 295 _fmt_has_nbo = 1<<7, // contains native-order field(s)
jrose@1920 296 _fmt_has_u2 = 1<<8, // contains double-byte field(s)
jrose@1920 297 _fmt_has_u4 = 1<<9, // contains quad-byte field
jrose@1920 298 _fmt_not_variable = 1<<10, // not of variable length (simple or wide)
jrose@1920 299 _fmt_not_simple = 1<<11, // either wide or variable length
jrose@1920 300 _all_fmt_bits = (_fmt_not_simple*2 - _fmt_has_c),
jrose@1920 301
jrose@1920 302 // Example derived format syndromes:
jrose@1920 303 _fmt_b = _fmt_not_variable,
jrose@1920 304 _fmt_bc = _fmt_b | _fmt_has_c,
jrose@1920 305 _fmt_bi = _fmt_b | _fmt_has_i,
jrose@1920 306 _fmt_bkk = _fmt_b | _fmt_has_k | _fmt_has_u2,
jrose@1920 307 _fmt_bJJ = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo,
jrose@1920 308 _fmt_bo2 = _fmt_b | _fmt_has_o | _fmt_has_u2,
jrose@1920 309 _fmt_bo4 = _fmt_b | _fmt_has_o | _fmt_has_u4
jrose@1920 310 };
jrose@1920 311
duke@435 312 private:
duke@435 313 static bool _is_initialized;
duke@435 314 static const char* _name [number_of_codes];
duke@435 315 static BasicType _result_type [number_of_codes];
duke@435 316 static s_char _depth [number_of_codes];
jrose@1920 317 static u_char _lengths [number_of_codes];
duke@435 318 static Code _java_code [number_of_codes];
jrose@1920 319 static jchar _flags [(1<<BitsPerByte)*2]; // all second page for wide formats
duke@435 320
duke@435 321 static void def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap);
duke@435 322 static void def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap, Code java_code);
duke@435 323 static void pd_initialize(); // platform specific initialization
duke@435 324 static Code pd_base_code_for(Code code); // platform specific base_code_for implementation
duke@435 325
duke@435 326 public:
duke@435 327 // Conversion
duke@435 328 static void check (Code code) { assert(is_defined(code), "illegal code"); }
duke@435 329 static void wide_check (Code code) { assert(wide_is_defined(code), "illegal code"); }
duke@435 330 static Code cast (int code) { return (Code)code; }
duke@435 331
duke@435 332
duke@435 333 // Fetch a bytecode, hiding breakpoints as necessary:
duke@435 334 static Code code_at(address bcp, methodOop method = NULL) {
duke@435 335 Code code = cast(*bcp); return (code != _breakpoint) ? code : non_breakpoint_code_at(bcp, method);
duke@435 336 }
duke@435 337 static Code java_code_at(address bcp, methodOop method = NULL) {
duke@435 338 return java_code(code_at(bcp, method));
duke@435 339 }
duke@435 340
duke@435 341 // Fetch a bytecode or a breakpoint:
duke@435 342 static Code code_or_bp_at(address bcp) { return (Code)cast(*bcp); }
duke@435 343
duke@435 344 static Code code_at(methodOop method, int bci);
duke@435 345 static bool is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; }
duke@435 346
duke@435 347 // find a bytecode, behind a breakpoint if necessary:
duke@435 348 static Code non_breakpoint_code_at(address bcp, methodOop method = NULL);
duke@435 349
duke@435 350 // Bytecode attributes
jrose@1920 351 static bool is_defined (int code) { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
jrose@1920 352 static bool wide_is_defined(int code) { return is_defined(code) && flags(code, true) != 0; }
duke@435 353 static const char* name (Code code) { check(code); return _name [code]; }
duke@435 354 static BasicType result_type (Code code) { check(code); return _result_type [code]; }
duke@435 355 static int depth (Code code) { check(code); return _depth [code]; }
jrose@1925 356 // Note: Length functions must return <=0 for invalid bytecodes.
jrose@1925 357 // Calling check(code) in length functions would throw an unwanted assert.
jrose@1925 358 static int length_for (Code code) { /*no check*/ return _lengths [code] & 0xF; }
jrose@1925 359 static int wide_length_for(Code code) { /*no check*/ return _lengths [code] >> 4; }
jrose@1920 360 static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); }
duke@435 361 static Code java_code (Code code) { check(code); return _java_code [code]; }
jrose@1920 362 static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); }
jrose@1920 363 static bool native_byte_order(Code code) { check(code); return has_all_flags(code, _fmt_has_nbo, false); }
jrose@1920 364 static bool uses_cp_cache (Code code) { check(code); return has_all_flags(code, _fmt_has_j, false); }
kamg@848 365 // if 'end' is provided, it indicates the end of the code buffer which
kamg@848 366 // should not be read past when parsing.
kamg@848 367 static int special_length_at(address bcp, address end = NULL);
kamg@848 368 static int raw_special_length_at(address bcp, address end = NULL);
duke@435 369 static int length_at (address bcp) { int l = length_for(code_at(bcp)); return l > 0 ? l : special_length_at(bcp); }
duke@435 370 static int java_length_at (address bcp) { int l = length_for(java_code_at(bcp)); return l > 0 ? l : special_length_at(bcp); }
duke@435 371 static bool is_java_code (Code code) { return 0 <= code && code < number_of_java_codes; }
duke@435 372
duke@435 373 static bool is_aload (Code code) { return (code == _aload || code == _aload_0 || code == _aload_1
duke@435 374 || code == _aload_2 || code == _aload_3); }
duke@435 375 static bool is_astore (Code code) { return (code == _astore || code == _astore_0 || code == _astore_1
duke@435 376 || code == _astore_2 || code == _astore_3); }
duke@435 377
duke@435 378 static bool is_zero_const (Code code) { return (code == _aconst_null || code == _iconst_0
duke@435 379 || code == _fconst_0 || code == _dconst_0); }
jrose@1920 380 static int compute_flags (const char* format, int more_flags = 0); // compute the flags
jrose@1920 381 static int flags (int code, bool is_wide) {
jrose@1920 382 assert(code == (u_char)code, "must be a byte");
jrose@1920 383 return _flags[code + (is_wide ? (1<<BitsPerByte) : 0)];
jrose@1920 384 }
jrose@1920 385 static int format_bits (Code code, bool is_wide) { return flags(code, is_wide) & _all_fmt_bits; }
jrose@1920 386 static bool has_all_flags (Code code, int test_flags, bool is_wide) {
jrose@1920 387 return (flags(code, is_wide) & test_flags) == test_flags;
jrose@1920 388 }
jrose@1920 389
duke@435 390 // Initialization
duke@435 391 static void initialize ();
duke@435 392 };

mercurial