duke@435: /* jrose@1920: * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // Bytecodes specifies all bytecodes used in the VM and duke@435: // provides utility functions to get bytecode attributes. duke@435: duke@435: // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java duke@435: class Bytecodes: AllStatic { duke@435: public: duke@435: enum Code { duke@435: _illegal = -1, duke@435: duke@435: // Java bytecodes duke@435: _nop = 0, // 0x00 duke@435: _aconst_null = 1, // 0x01 duke@435: _iconst_m1 = 2, // 0x02 duke@435: _iconst_0 = 3, // 0x03 duke@435: _iconst_1 = 4, // 0x04 duke@435: _iconst_2 = 5, // 0x05 duke@435: _iconst_3 = 6, // 0x06 duke@435: _iconst_4 = 7, // 0x07 duke@435: _iconst_5 = 8, // 0x08 duke@435: _lconst_0 = 9, // 0x09 duke@435: _lconst_1 = 10, // 0x0a duke@435: _fconst_0 = 11, // 0x0b duke@435: _fconst_1 = 12, // 0x0c duke@435: _fconst_2 = 13, // 0x0d duke@435: _dconst_0 = 14, // 0x0e duke@435: _dconst_1 = 15, // 0x0f duke@435: _bipush = 16, // 0x10 duke@435: _sipush = 17, // 0x11 duke@435: _ldc = 18, // 0x12 duke@435: _ldc_w = 19, // 0x13 duke@435: _ldc2_w = 20, // 0x14 duke@435: _iload = 21, // 0x15 duke@435: _lload = 22, // 0x16 duke@435: _fload = 23, // 0x17 duke@435: _dload = 24, // 0x18 duke@435: _aload = 25, // 0x19 duke@435: _iload_0 = 26, // 0x1a duke@435: _iload_1 = 27, // 0x1b duke@435: _iload_2 = 28, // 0x1c duke@435: _iload_3 = 29, // 0x1d duke@435: _lload_0 = 30, // 0x1e duke@435: _lload_1 = 31, // 0x1f duke@435: _lload_2 = 32, // 0x20 duke@435: _lload_3 = 33, // 0x21 duke@435: _fload_0 = 34, // 0x22 duke@435: _fload_1 = 35, // 0x23 duke@435: _fload_2 = 36, // 0x24 duke@435: _fload_3 = 37, // 0x25 duke@435: _dload_0 = 38, // 0x26 duke@435: _dload_1 = 39, // 0x27 duke@435: _dload_2 = 40, // 0x28 duke@435: _dload_3 = 41, // 0x29 duke@435: _aload_0 = 42, // 0x2a duke@435: _aload_1 = 43, // 0x2b duke@435: _aload_2 = 44, // 0x2c duke@435: _aload_3 = 45, // 0x2d duke@435: _iaload = 46, // 0x2e duke@435: _laload = 47, // 0x2f duke@435: _faload = 48, // 0x30 duke@435: _daload = 49, // 0x31 duke@435: _aaload = 50, // 0x32 duke@435: _baload = 51, // 0x33 duke@435: _caload = 52, // 0x34 duke@435: _saload = 53, // 0x35 duke@435: _istore = 54, // 0x36 duke@435: _lstore = 55, // 0x37 duke@435: _fstore = 56, // 0x38 duke@435: _dstore = 57, // 0x39 duke@435: _astore = 58, // 0x3a duke@435: _istore_0 = 59, // 0x3b duke@435: _istore_1 = 60, // 0x3c duke@435: _istore_2 = 61, // 0x3d duke@435: _istore_3 = 62, // 0x3e duke@435: _lstore_0 = 63, // 0x3f duke@435: _lstore_1 = 64, // 0x40 duke@435: _lstore_2 = 65, // 0x41 duke@435: _lstore_3 = 66, // 0x42 duke@435: _fstore_0 = 67, // 0x43 duke@435: _fstore_1 = 68, // 0x44 duke@435: _fstore_2 = 69, // 0x45 duke@435: _fstore_3 = 70, // 0x46 duke@435: _dstore_0 = 71, // 0x47 duke@435: _dstore_1 = 72, // 0x48 duke@435: _dstore_2 = 73, // 0x49 duke@435: _dstore_3 = 74, // 0x4a duke@435: _astore_0 = 75, // 0x4b duke@435: _astore_1 = 76, // 0x4c duke@435: _astore_2 = 77, // 0x4d duke@435: _astore_3 = 78, // 0x4e duke@435: _iastore = 79, // 0x4f duke@435: _lastore = 80, // 0x50 duke@435: _fastore = 81, // 0x51 duke@435: _dastore = 82, // 0x52 duke@435: _aastore = 83, // 0x53 duke@435: _bastore = 84, // 0x54 duke@435: _castore = 85, // 0x55 duke@435: _sastore = 86, // 0x56 duke@435: _pop = 87, // 0x57 duke@435: _pop2 = 88, // 0x58 duke@435: _dup = 89, // 0x59 duke@435: _dup_x1 = 90, // 0x5a duke@435: _dup_x2 = 91, // 0x5b duke@435: _dup2 = 92, // 0x5c duke@435: _dup2_x1 = 93, // 0x5d duke@435: _dup2_x2 = 94, // 0x5e duke@435: _swap = 95, // 0x5f duke@435: _iadd = 96, // 0x60 duke@435: _ladd = 97, // 0x61 duke@435: _fadd = 98, // 0x62 duke@435: _dadd = 99, // 0x63 duke@435: _isub = 100, // 0x64 duke@435: _lsub = 101, // 0x65 duke@435: _fsub = 102, // 0x66 duke@435: _dsub = 103, // 0x67 duke@435: _imul = 104, // 0x68 duke@435: _lmul = 105, // 0x69 duke@435: _fmul = 106, // 0x6a duke@435: _dmul = 107, // 0x6b duke@435: _idiv = 108, // 0x6c duke@435: _ldiv = 109, // 0x6d duke@435: _fdiv = 110, // 0x6e duke@435: _ddiv = 111, // 0x6f duke@435: _irem = 112, // 0x70 duke@435: _lrem = 113, // 0x71 duke@435: _frem = 114, // 0x72 duke@435: _drem = 115, // 0x73 duke@435: _ineg = 116, // 0x74 duke@435: _lneg = 117, // 0x75 duke@435: _fneg = 118, // 0x76 duke@435: _dneg = 119, // 0x77 duke@435: _ishl = 120, // 0x78 duke@435: _lshl = 121, // 0x79 duke@435: _ishr = 122, // 0x7a duke@435: _lshr = 123, // 0x7b duke@435: _iushr = 124, // 0x7c duke@435: _lushr = 125, // 0x7d duke@435: _iand = 126, // 0x7e duke@435: _land = 127, // 0x7f duke@435: _ior = 128, // 0x80 duke@435: _lor = 129, // 0x81 duke@435: _ixor = 130, // 0x82 duke@435: _lxor = 131, // 0x83 duke@435: _iinc = 132, // 0x84 duke@435: _i2l = 133, // 0x85 duke@435: _i2f = 134, // 0x86 duke@435: _i2d = 135, // 0x87 duke@435: _l2i = 136, // 0x88 duke@435: _l2f = 137, // 0x89 duke@435: _l2d = 138, // 0x8a duke@435: _f2i = 139, // 0x8b duke@435: _f2l = 140, // 0x8c duke@435: _f2d = 141, // 0x8d duke@435: _d2i = 142, // 0x8e duke@435: _d2l = 143, // 0x8f duke@435: _d2f = 144, // 0x90 duke@435: _i2b = 145, // 0x91 duke@435: _i2c = 146, // 0x92 duke@435: _i2s = 147, // 0x93 duke@435: _lcmp = 148, // 0x94 duke@435: _fcmpl = 149, // 0x95 duke@435: _fcmpg = 150, // 0x96 duke@435: _dcmpl = 151, // 0x97 duke@435: _dcmpg = 152, // 0x98 duke@435: _ifeq = 153, // 0x99 duke@435: _ifne = 154, // 0x9a duke@435: _iflt = 155, // 0x9b duke@435: _ifge = 156, // 0x9c duke@435: _ifgt = 157, // 0x9d duke@435: _ifle = 158, // 0x9e duke@435: _if_icmpeq = 159, // 0x9f duke@435: _if_icmpne = 160, // 0xa0 duke@435: _if_icmplt = 161, // 0xa1 duke@435: _if_icmpge = 162, // 0xa2 duke@435: _if_icmpgt = 163, // 0xa3 duke@435: _if_icmple = 164, // 0xa4 duke@435: _if_acmpeq = 165, // 0xa5 duke@435: _if_acmpne = 166, // 0xa6 duke@435: _goto = 167, // 0xa7 duke@435: _jsr = 168, // 0xa8 duke@435: _ret = 169, // 0xa9 duke@435: _tableswitch = 170, // 0xaa duke@435: _lookupswitch = 171, // 0xab duke@435: _ireturn = 172, // 0xac duke@435: _lreturn = 173, // 0xad duke@435: _freturn = 174, // 0xae duke@435: _dreturn = 175, // 0xaf duke@435: _areturn = 176, // 0xb0 duke@435: _return = 177, // 0xb1 duke@435: _getstatic = 178, // 0xb2 duke@435: _putstatic = 179, // 0xb3 duke@435: _getfield = 180, // 0xb4 duke@435: _putfield = 181, // 0xb5 duke@435: _invokevirtual = 182, // 0xb6 duke@435: _invokespecial = 183, // 0xb7 duke@435: _invokestatic = 184, // 0xb8 duke@435: _invokeinterface = 185, // 0xb9 jrose@1161: _invokedynamic = 186, // 0xba // if EnableInvokeDynamic duke@435: _new = 187, // 0xbb duke@435: _newarray = 188, // 0xbc duke@435: _anewarray = 189, // 0xbd duke@435: _arraylength = 190, // 0xbe duke@435: _athrow = 191, // 0xbf duke@435: _checkcast = 192, // 0xc0 duke@435: _instanceof = 193, // 0xc1 duke@435: _monitorenter = 194, // 0xc2 duke@435: _monitorexit = 195, // 0xc3 duke@435: _wide = 196, // 0xc4 duke@435: _multianewarray = 197, // 0xc5 duke@435: _ifnull = 198, // 0xc6 duke@435: _ifnonnull = 199, // 0xc7 duke@435: _goto_w = 200, // 0xc8 duke@435: _jsr_w = 201, // 0xc9 duke@435: _breakpoint = 202, // 0xca duke@435: duke@435: number_of_java_codes, duke@435: duke@435: // JVM bytecodes duke@435: _fast_agetfield = number_of_java_codes, duke@435: _fast_bgetfield , duke@435: _fast_cgetfield , duke@435: _fast_dgetfield , duke@435: _fast_fgetfield , duke@435: _fast_igetfield , duke@435: _fast_lgetfield , duke@435: _fast_sgetfield , duke@435: duke@435: _fast_aputfield , duke@435: _fast_bputfield , duke@435: _fast_cputfield , duke@435: _fast_dputfield , duke@435: _fast_fputfield , duke@435: _fast_iputfield , duke@435: _fast_lputfield , duke@435: _fast_sputfield , duke@435: duke@435: _fast_aload_0 , duke@435: _fast_iaccess_0 , duke@435: _fast_aaccess_0 , duke@435: _fast_faccess_0 , duke@435: duke@435: _fast_iload , duke@435: _fast_iload2 , duke@435: _fast_icaload , duke@435: duke@435: _fast_invokevfinal , duke@435: _fast_linearswitch , duke@435: _fast_binaryswitch , duke@435: duke@435: _return_register_finalizer , duke@435: duke@435: _shouldnotreachhere, // For debugging duke@435: duke@435: // Platform specific JVM bytecodes duke@435: #include "incls/_bytecodes_pd.hpp.incl" duke@435: duke@435: number_of_codes duke@435: }; duke@435: jrose@1920: // Flag bits derived from format strings, can_trap, can_rewrite, etc.: jrose@1920: enum Flags { jrose@1920: // semantic flags: jrose@1920: _bc_can_trap = 1<<0, // bytecode execution can trap or block jrose@1920: _bc_can_rewrite = 1<<1, // bytecode execution has an alternate form jrose@1920: jrose@1920: // format bits (determined only by the format string): jrose@1920: _fmt_has_c = 1<<2, // constant, such as sipush "bcc" jrose@1920: _fmt_has_j = 1<<3, // constant pool cache index, such as getfield "bjj" jrose@1920: _fmt_has_k = 1<<4, // constant pool index, such as ldc "bk" jrose@1920: _fmt_has_i = 1<<5, // local index, such as iload jrose@1920: _fmt_has_o = 1<<6, // offset, such as ifeq jrose@1920: _fmt_has_nbo = 1<<7, // contains native-order field(s) jrose@1920: _fmt_has_u2 = 1<<8, // contains double-byte field(s) jrose@1920: _fmt_has_u4 = 1<<9, // contains quad-byte field jrose@1920: _fmt_not_variable = 1<<10, // not of variable length (simple or wide) jrose@1920: _fmt_not_simple = 1<<11, // either wide or variable length jrose@1920: _all_fmt_bits = (_fmt_not_simple*2 - _fmt_has_c), jrose@1920: jrose@1920: // Example derived format syndromes: jrose@1920: _fmt_b = _fmt_not_variable, jrose@1920: _fmt_bc = _fmt_b | _fmt_has_c, jrose@1920: _fmt_bi = _fmt_b | _fmt_has_i, jrose@1920: _fmt_bkk = _fmt_b | _fmt_has_k | _fmt_has_u2, jrose@1920: _fmt_bJJ = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo, jrose@1920: _fmt_bo2 = _fmt_b | _fmt_has_o | _fmt_has_u2, jrose@1920: _fmt_bo4 = _fmt_b | _fmt_has_o | _fmt_has_u4 jrose@1920: }; jrose@1920: duke@435: private: duke@435: static bool _is_initialized; duke@435: static const char* _name [number_of_codes]; duke@435: static BasicType _result_type [number_of_codes]; duke@435: static s_char _depth [number_of_codes]; jrose@1920: static u_char _lengths [number_of_codes]; duke@435: static Code _java_code [number_of_codes]; jrose@1920: static jchar _flags [(1<> 4; } jrose@1920: static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); } duke@435: static Code java_code (Code code) { check(code); return _java_code [code]; } jrose@1920: static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); } jrose@1920: static bool native_byte_order(Code code) { check(code); return has_all_flags(code, _fmt_has_nbo, false); } jrose@1920: static bool uses_cp_cache (Code code) { check(code); return has_all_flags(code, _fmt_has_j, false); } kamg@848: // if 'end' is provided, it indicates the end of the code buffer which kamg@848: // should not be read past when parsing. kamg@848: static int special_length_at(address bcp, address end = NULL); kamg@848: static int raw_special_length_at(address bcp, address end = NULL); duke@435: static int length_at (address bcp) { int l = length_for(code_at(bcp)); return l > 0 ? l : special_length_at(bcp); } duke@435: 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: static bool is_java_code (Code code) { return 0 <= code && code < number_of_java_codes; } duke@435: duke@435: static bool is_aload (Code code) { return (code == _aload || code == _aload_0 || code == _aload_1 duke@435: || code == _aload_2 || code == _aload_3); } duke@435: static bool is_astore (Code code) { return (code == _astore || code == _astore_0 || code == _astore_1 duke@435: || code == _astore_2 || code == _astore_3); } duke@435: duke@435: static bool is_zero_const (Code code) { return (code == _aconst_null || code == _iconst_0 duke@435: || code == _fconst_0 || code == _dconst_0); } jrose@1920: static int compute_flags (const char* format, int more_flags = 0); // compute the flags jrose@1920: static int flags (int code, bool is_wide) { jrose@1920: assert(code == (u_char)code, "must be a byte"); jrose@1920: return _flags[code + (is_wide ? (1<