bytecodes.hpp revision 0:a61af66fc99e
117680Spst/* 239300Sfenner * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. 317680Spst * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 417680Spst * 517680Spst * This code is free software; you can redistribute it and/or modify it 617680Spst * under the terms of the GNU General Public License version 2 only, as 717680Spst * published by the Free Software Foundation. 817680Spst * 917680Spst * This code is distributed in the hope that it will be useful, but WITHOUT 1017680Spst * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1117680Spst * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1217680Spst * version 2 for more details (a copy is included in the LICENSE file that 1317680Spst * accompanied this code). 1417680Spst * 1517680Spst * You should have received a copy of the GNU General Public License version 1617680Spst * 2 along with this work; if not, write to the Free Software Foundation, 1717680Spst * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1817680Spst * 1917680Spst * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2017680Spst * CA 95054 USA or visit www.sun.com if you need additional information or 2117680Spst * have any questions. 2217680Spst * 2317680Spst */ 2417680Spst 2526183Sfenner// Bytecodes specifies all bytecodes used in the VM and 2639300Sfenner// provides utility functions to get bytecode attributes. 2717680Spst 2817680Spst// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java 2917680Spstclass Bytecodes: AllStatic { 3017680Spst public: 3117680Spst enum Code { 3217680Spst _illegal = -1, 3317680Spst 3417680Spst // Java bytecodes 3517680Spst _nop = 0, // 0x00 3617680Spst _aconst_null = 1, // 0x01 3717680Spst _iconst_m1 = 2, // 0x02 3817680Spst _iconst_0 = 3, // 0x03 3917680Spst _iconst_1 = 4, // 0x04 4021262Swollman _iconst_2 = 5, // 0x05 4117680Spst _iconst_3 = 6, // 0x06 4217680Spst _iconst_4 = 7, // 0x07 4317680Spst _iconst_5 = 8, // 0x08 4417680Spst _lconst_0 = 9, // 0x09 4517680Spst _lconst_1 = 10, // 0x0a 4617680Spst _fconst_0 = 11, // 0x0b 4717680Spst _fconst_1 = 12, // 0x0c 4839300Sfenner _fconst_2 = 13, // 0x0d 4939300Sfenner _dconst_0 = 14, // 0x0e 5039300Sfenner _dconst_1 = 15, // 0x0f 5139300Sfenner _bipush = 16, // 0x10 5239300Sfenner _sipush = 17, // 0x11 5339300Sfenner _ldc = 18, // 0x12 5417680Spst _ldc_w = 19, // 0x13 5517680Spst _ldc2_w = 20, // 0x14 5617680Spst _iload = 21, // 0x15 5717680Spst _lload = 22, // 0x16 5817680Spst _fload = 23, // 0x17 5917680Spst _dload = 24, // 0x18 6017680Spst _aload = 25, // 0x19 6117680Spst _iload_0 = 26, // 0x1a 6217680Spst _iload_1 = 27, // 0x1b 6339300Sfenner _iload_2 = 28, // 0x1c 6439300Sfenner _iload_3 = 29, // 0x1d 6517680Spst _lload_0 = 30, // 0x1e 6617680Spst _lload_1 = 31, // 0x1f 6717680Spst _lload_2 = 32, // 0x20 6817680Spst _lload_3 = 33, // 0x21 6917680Spst _fload_0 = 34, // 0x22 7017680Spst _fload_1 = 35, // 0x23 7117680Spst _fload_2 = 36, // 0x24 7217680Spst _fload_3 = 37, // 0x25 7317680Spst _dload_0 = 38, // 0x26 7417680Spst _dload_1 = 39, // 0x27 7517680Spst _dload_2 = 40, // 0x28 7617680Spst _dload_3 = 41, // 0x29 7717680Spst _aload_0 = 42, // 0x2a 7817680Spst _aload_1 = 43, // 0x2b 7917680Spst _aload_2 = 44, // 0x2c 8017680Spst _aload_3 = 45, // 0x2d 8117680Spst _iaload = 46, // 0x2e 8217680Spst _laload = 47, // 0x2f 8317680Spst _faload = 48, // 0x30 8417680Spst _daload = 49, // 0x31 8517680Spst _aaload = 50, // 0x32 8617680Spst _baload = 51, // 0x33 8717680Spst _caload = 52, // 0x34 8817680Spst _saload = 53, // 0x35 8917680Spst _istore = 54, // 0x36 9017680Spst _lstore = 55, // 0x37 9117680Spst _fstore = 56, // 0x38 9217680Spst _dstore = 57, // 0x39 9317680Spst _astore = 58, // 0x3a 9417680Spst _istore_0 = 59, // 0x3b 9517680Spst _istore_1 = 60, // 0x3c 9617680Spst _istore_2 = 61, // 0x3d 9717680Spst _istore_3 = 62, // 0x3e 9817680Spst _lstore_0 = 63, // 0x3f 9917680Spst _lstore_1 = 64, // 0x40 10017680Spst _lstore_2 = 65, // 0x41 10117680Spst _lstore_3 = 66, // 0x42 10217680Spst _fstore_0 = 67, // 0x43 10317680Spst _fstore_1 = 68, // 0x44 10417680Spst _fstore_2 = 69, // 0x45 10517680Spst _fstore_3 = 70, // 0x46 10617680Spst _dstore_0 = 71, // 0x47 10717680Spst _dstore_1 = 72, // 0x48 10817680Spst _dstore_2 = 73, // 0x49 10917680Spst _dstore_3 = 74, // 0x4a 11017680Spst _astore_0 = 75, // 0x4b 11117680Spst _astore_1 = 76, // 0x4c 11217680Spst _astore_2 = 77, // 0x4d 11317680Spst _astore_3 = 78, // 0x4e 11417680Spst _iastore = 79, // 0x4f 11517680Spst _lastore = 80, // 0x50 11617680Spst _fastore = 81, // 0x51 11717680Spst _dastore = 82, // 0x52 11817680Spst _aastore = 83, // 0x53 11917680Spst _bastore = 84, // 0x54 12017680Spst _castore = 85, // 0x55 12117680Spst _sastore = 86, // 0x56 12217680Spst _pop = 87, // 0x57 12317680Spst _pop2 = 88, // 0x58 12417680Spst _dup = 89, // 0x59 12517680Spst _dup_x1 = 90, // 0x5a 12617680Spst _dup_x2 = 91, // 0x5b 12717680Spst _dup2 = 92, // 0x5c 12817680Spst _dup2_x1 = 93, // 0x5d 12917680Spst _dup2_x2 = 94, // 0x5e 13017680Spst _swap = 95, // 0x5f 13117680Spst _iadd = 96, // 0x60 13217680Spst _ladd = 97, // 0x61 13317680Spst _fadd = 98, // 0x62 13417680Spst _dadd = 99, // 0x63 13517680Spst _isub = 100, // 0x64 13617680Spst _lsub = 101, // 0x65 13717680Spst _fsub = 102, // 0x66 13817680Spst _dsub = 103, // 0x67 13917680Spst _imul = 104, // 0x68 14017680Spst _lmul = 105, // 0x69 14117680Spst _fmul = 106, // 0x6a 14217680Spst _dmul = 107, // 0x6b 14317680Spst _idiv = 108, // 0x6c 14417680Spst _ldiv = 109, // 0x6d 14517680Spst _fdiv = 110, // 0x6e 14617680Spst _ddiv = 111, // 0x6f 14717680Spst _irem = 112, // 0x70 14817680Spst _lrem = 113, // 0x71 14917680Spst _frem = 114, // 0x72 15017680Spst _drem = 115, // 0x73 15117680Spst _ineg = 116, // 0x74 15217680Spst _lneg = 117, // 0x75 15317680Spst _fneg = 118, // 0x76 15417680Spst _dneg = 119, // 0x77 15517680Spst _ishl = 120, // 0x78 15617680Spst _lshl = 121, // 0x79 15717680Spst _ishr = 122, // 0x7a 15817680Spst _lshr = 123, // 0x7b 15917680Spst _iushr = 124, // 0x7c 16017680Spst _lushr = 125, // 0x7d 16117680Spst _iand = 126, // 0x7e 16217680Spst _land = 127, // 0x7f 16317680Spst _ior = 128, // 0x80 16417680Spst _lor = 129, // 0x81 16517680Spst _ixor = 130, // 0x82 16617680Spst _lxor = 131, // 0x83 16717680Spst _iinc = 132, // 0x84 16817680Spst _i2l = 133, // 0x85 16917680Spst _i2f = 134, // 0x86 17017680Spst _i2d = 135, // 0x87 17117680Spst _l2i = 136, // 0x88 17217680Spst _l2f = 137, // 0x89 17317680Spst _l2d = 138, // 0x8a 17417680Spst _f2i = 139, // 0x8b 17526183Sfenner _f2l = 140, // 0x8c 17617680Spst _f2d = 141, // 0x8d 17717680Spst _d2i = 142, // 0x8e 17817680Spst _d2l = 143, // 0x8f 17917680Spst _d2f = 144, // 0x90 18017680Spst _i2b = 145, // 0x91 18117680Spst _i2c = 146, // 0x92 18217680Spst _i2s = 147, // 0x93 18317680Spst _lcmp = 148, // 0x94 18426183Sfenner _fcmpl = 149, // 0x95 18526183Sfenner _fcmpg = 150, // 0x96 18626183Sfenner _dcmpl = 151, // 0x97 18726183Sfenner _dcmpg = 152, // 0x98 18817680Spst _ifeq = 153, // 0x99 18917680Spst _ifne = 154, // 0x9a 19017680Spst _iflt = 155, // 0x9b 19117680Spst _ifge = 156, // 0x9c 19217680Spst _ifgt = 157, // 0x9d 19317680Spst _ifle = 158, // 0x9e 19426183Sfenner _if_icmpeq = 159, // 0x9f 19526183Sfenner _if_icmpne = 160, // 0xa0 19626183Sfenner _if_icmplt = 161, // 0xa1 19726183Sfenner _if_icmpge = 162, // 0xa2 19826183Sfenner _if_icmpgt = 163, // 0xa3 19926183Sfenner _if_icmple = 164, // 0xa4 20017680Spst _if_acmpeq = 165, // 0xa5 20117680Spst _if_acmpne = 166, // 0xa6 20217680Spst _goto = 167, // 0xa7 20317680Spst _jsr = 168, // 0xa8 20417680Spst _ret = 169, // 0xa9 20517680Spst _tableswitch = 170, // 0xaa 20617680Spst _lookupswitch = 171, // 0xab 20717680Spst _ireturn = 172, // 0xac 20817680Spst _lreturn = 173, // 0xad 20917680Spst _freturn = 174, // 0xae 21017680Spst _dreturn = 175, // 0xaf 21117680Spst _areturn = 176, // 0xb0 21217680Spst _return = 177, // 0xb1 21317680Spst _getstatic = 178, // 0xb2 21417680Spst _putstatic = 179, // 0xb3 21517680Spst _getfield = 180, // 0xb4 21617680Spst _putfield = 181, // 0xb5 21717680Spst _invokevirtual = 182, // 0xb6 21817680Spst _invokespecial = 183, // 0xb7 21939300Sfenner _invokestatic = 184, // 0xb8 22039300Sfenner _invokeinterface = 185, // 0xb9 22139300Sfenner _xxxunusedxxx = 186, // 0xba 22239300Sfenner _new = 187, // 0xbb 22339300Sfenner _newarray = 188, // 0xbc 22417680Spst _anewarray = 189, // 0xbd 22539300Sfenner _arraylength = 190, // 0xbe 22639300Sfenner _athrow = 191, // 0xbf 22739300Sfenner _checkcast = 192, // 0xc0 22839300Sfenner _instanceof = 193, // 0xc1 22917680Spst _monitorenter = 194, // 0xc2 23039300Sfenner _monitorexit = 195, // 0xc3 23117680Spst _wide = 196, // 0xc4 23217680Spst _multianewarray = 197, // 0xc5 23317680Spst _ifnull = 198, // 0xc6 23417680Spst _ifnonnull = 199, // 0xc7 23517680Spst _goto_w = 200, // 0xc8 23617680Spst _jsr_w = 201, // 0xc9 23717680Spst _breakpoint = 202, // 0xca 23817680Spst 23917680Spst number_of_java_codes, 24017680Spst 24117680Spst // JVM bytecodes 24217680Spst _fast_agetfield = number_of_java_codes, 24317680Spst _fast_bgetfield , 24417680Spst _fast_cgetfield , 24517680Spst _fast_dgetfield , 24617680Spst _fast_fgetfield , 24717680Spst _fast_igetfield , 24817680Spst _fast_lgetfield , 24917680Spst _fast_sgetfield , 25017680Spst 25117680Spst _fast_aputfield , 25217680Spst _fast_bputfield , 25317680Spst _fast_cputfield , 25417680Spst _fast_dputfield , 25517680Spst _fast_fputfield , 25617680Spst _fast_iputfield , 25717680Spst _fast_lputfield , 25817680Spst _fast_sputfield , 25917680Spst 26017680Spst _fast_aload_0 , 26117680Spst _fast_iaccess_0 , 26217680Spst _fast_aaccess_0 , 26317680Spst _fast_faccess_0 , 26417680Spst 26517680Spst _fast_iload , 26617680Spst _fast_iload2 , 26717680Spst _fast_icaload , 26817680Spst 26917680Spst _fast_invokevfinal , 27017680Spst _fast_linearswitch , 27117680Spst _fast_binaryswitch , 27217680Spst 27317680Spst _return_register_finalizer , 27417680Spst 27517680Spst _shouldnotreachhere, // For debugging 27617680Spst 27717680Spst // Platform specific JVM bytecodes 27817680Spst #include "incls/_bytecodes_pd.hpp.incl" 27917680Spst 28017680Spst number_of_codes 28117680Spst }; 28217680Spst 28317680Spst private: 28417680Spst static bool _is_initialized; 28517680Spst static const char* _name [number_of_codes]; 28617680Spst static const char* _format [number_of_codes]; 28717680Spst static const char* _wide_format [number_of_codes]; 28817680Spst static BasicType _result_type [number_of_codes]; 28917680Spst static s_char _depth [number_of_codes]; 29017680Spst static u_char _length [number_of_codes]; 29117680Spst static bool _can_trap [number_of_codes]; 29217680Spst static Code _java_code [number_of_codes]; 29317680Spst static bool _can_rewrite [number_of_codes]; 29417680Spst 29517680Spst static void def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap); 29617680Spst 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); 29717680Spst static void pd_initialize(); // platform specific initialization 29817680Spst static Code pd_base_code_for(Code code); // platform specific base_code_for implementation 29917680Spst 30017680Spst public: 30117680Spst // Conversion 30217680Spst static void check (Code code) { assert(is_defined(code), "illegal code"); } 30317680Spst static void wide_check (Code code) { assert(wide_is_defined(code), "illegal code"); } 30417680Spst static Code cast (int code) { return (Code)code; } 30517680Spst 30617680Spst 30717680Spst // Fetch a bytecode, hiding breakpoints as necessary: 30817680Spst static Code code_at(address bcp, methodOop method = NULL) { 30917680Spst Code code = cast(*bcp); return (code != _breakpoint) ? code : non_breakpoint_code_at(bcp, method); 31017680Spst } 31117680Spst static Code java_code_at(address bcp, methodOop method = NULL) { 31217680Spst return java_code(code_at(bcp, method)); 31317680Spst } 31417680Spst 31517680Spst // Fetch a bytecode or a breakpoint: 31617680Spst static Code code_or_bp_at(address bcp) { return (Code)cast(*bcp); } 31717680Spst 31817680Spst static Code code_at(methodOop method, int bci); 31917680Spst static bool is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; } 32039300Sfenner 32117680Spst // find a bytecode, behind a breakpoint if necessary: 32217680Spst static Code non_breakpoint_code_at(address bcp, methodOop method = NULL); 32317680Spst 32417680Spst // Bytecode attributes 32517680Spst static bool is_defined (int code) { return 0 <= code && code < number_of_codes && _format[code] != NULL; } 32617680Spst static bool wide_is_defined(int code) { return is_defined(code) && _wide_format[code] != NULL; } 32717680Spst static const char* name (Code code) { check(code); return _name [code]; } 32817680Spst static const char* format (Code code) { check(code); return _format [code]; } 32917680Spst static const char* wide_format (Code code) { return _wide_format[code]; } 33017680Spst static BasicType result_type (Code code) { check(code); return _result_type [code]; } 33117680Spst static int depth (Code code) { check(code); return _depth [code]; } 33217680Spst static int length_for (Code code) { return _length[code]; } 33317680Spst static bool can_trap (Code code) { check(code); return _can_trap [code]; } 33417680Spst static Code java_code (Code code) { check(code); return _java_code [code]; } 33517680Spst static bool can_rewrite (Code code) { check(code); return _can_rewrite [code]; } 33617680Spst static int wide_length_for(Code code) { 33717680Spst if (!is_defined(code)) { 33817680Spst return 0; 33917680Spst } 34017680Spst const char* wf = wide_format(code); 34117680Spst return (wf == NULL) ? 0 : (int)strlen(wf); 34217680Spst } 34317680Spst static int special_length_at(address bcp); 34417680Spst static int raw_special_length_at(address bcp); 34517680Spst static int length_at (address bcp) { int l = length_for(code_at(bcp)); return l > 0 ? l : special_length_at(bcp); } 34617680Spst static int java_length_at (address bcp) { int l = length_for(java_code_at(bcp)); return l > 0 ? l : special_length_at(bcp); } 34717680Spst static bool is_java_code (Code code) { return 0 <= code && code < number_of_java_codes; } 34817680Spst 34917680Spst static bool is_aload (Code code) { return (code == _aload || code == _aload_0 || code == _aload_1 35017680Spst || code == _aload_2 || code == _aload_3); } 35117680Spst static bool is_astore (Code code) { return (code == _astore || code == _astore_0 || code == _astore_1 35217680Spst || code == _astore_2 || code == _astore_3); } 35317680Spst 35417680Spst static bool is_zero_const (Code code) { return (code == _aconst_null || code == _iconst_0 35517680Spst || code == _fconst_0 || code == _dconst_0); } 35617680Spst // Initialization 35717680Spst static void initialize (); 35817680Spst}; 35917680Spst