Path: blob/master/src/hotspot/share/interpreter/bytecodes.hpp
40949 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_INTERPRETER_BYTECODES_HPP25#define SHARE_INTERPRETER_BYTECODES_HPP2627#include "memory/allocation.hpp"2829// Bytecodes specifies all bytecodes used in the VM and30// provides utility functions to get bytecode attributes.3132class Method;3334// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java35class Bytecodes: AllStatic {36public:37enum Code {38_illegal = -1,3940// Java bytecodes41_nop = 0, // 0x0042_aconst_null = 1, // 0x0143_iconst_m1 = 2, // 0x0244_iconst_0 = 3, // 0x0345_iconst_1 = 4, // 0x0446_iconst_2 = 5, // 0x0547_iconst_3 = 6, // 0x0648_iconst_4 = 7, // 0x0749_iconst_5 = 8, // 0x0850_lconst_0 = 9, // 0x0951_lconst_1 = 10, // 0x0a52_fconst_0 = 11, // 0x0b53_fconst_1 = 12, // 0x0c54_fconst_2 = 13, // 0x0d55_dconst_0 = 14, // 0x0e56_dconst_1 = 15, // 0x0f57_bipush = 16, // 0x1058_sipush = 17, // 0x1159_ldc = 18, // 0x1260_ldc_w = 19, // 0x1361_ldc2_w = 20, // 0x1462_iload = 21, // 0x1563_lload = 22, // 0x1664_fload = 23, // 0x1765_dload = 24, // 0x1866_aload = 25, // 0x1967_iload_0 = 26, // 0x1a68_iload_1 = 27, // 0x1b69_iload_2 = 28, // 0x1c70_iload_3 = 29, // 0x1d71_lload_0 = 30, // 0x1e72_lload_1 = 31, // 0x1f73_lload_2 = 32, // 0x2074_lload_3 = 33, // 0x2175_fload_0 = 34, // 0x2276_fload_1 = 35, // 0x2377_fload_2 = 36, // 0x2478_fload_3 = 37, // 0x2579_dload_0 = 38, // 0x2680_dload_1 = 39, // 0x2781_dload_2 = 40, // 0x2882_dload_3 = 41, // 0x2983_aload_0 = 42, // 0x2a84_aload_1 = 43, // 0x2b85_aload_2 = 44, // 0x2c86_aload_3 = 45, // 0x2d87_iaload = 46, // 0x2e88_laload = 47, // 0x2f89_faload = 48, // 0x3090_daload = 49, // 0x3191_aaload = 50, // 0x3292_baload = 51, // 0x3393_caload = 52, // 0x3494_saload = 53, // 0x3595_istore = 54, // 0x3696_lstore = 55, // 0x3797_fstore = 56, // 0x3898_dstore = 57, // 0x3999_astore = 58, // 0x3a100_istore_0 = 59, // 0x3b101_istore_1 = 60, // 0x3c102_istore_2 = 61, // 0x3d103_istore_3 = 62, // 0x3e104_lstore_0 = 63, // 0x3f105_lstore_1 = 64, // 0x40106_lstore_2 = 65, // 0x41107_lstore_3 = 66, // 0x42108_fstore_0 = 67, // 0x43109_fstore_1 = 68, // 0x44110_fstore_2 = 69, // 0x45111_fstore_3 = 70, // 0x46112_dstore_0 = 71, // 0x47113_dstore_1 = 72, // 0x48114_dstore_2 = 73, // 0x49115_dstore_3 = 74, // 0x4a116_astore_0 = 75, // 0x4b117_astore_1 = 76, // 0x4c118_astore_2 = 77, // 0x4d119_astore_3 = 78, // 0x4e120_iastore = 79, // 0x4f121_lastore = 80, // 0x50122_fastore = 81, // 0x51123_dastore = 82, // 0x52124_aastore = 83, // 0x53125_bastore = 84, // 0x54126_castore = 85, // 0x55127_sastore = 86, // 0x56128_pop = 87, // 0x57129_pop2 = 88, // 0x58130_dup = 89, // 0x59131_dup_x1 = 90, // 0x5a132_dup_x2 = 91, // 0x5b133_dup2 = 92, // 0x5c134_dup2_x1 = 93, // 0x5d135_dup2_x2 = 94, // 0x5e136_swap = 95, // 0x5f137_iadd = 96, // 0x60138_ladd = 97, // 0x61139_fadd = 98, // 0x62140_dadd = 99, // 0x63141_isub = 100, // 0x64142_lsub = 101, // 0x65143_fsub = 102, // 0x66144_dsub = 103, // 0x67145_imul = 104, // 0x68146_lmul = 105, // 0x69147_fmul = 106, // 0x6a148_dmul = 107, // 0x6b149_idiv = 108, // 0x6c150_ldiv = 109, // 0x6d151_fdiv = 110, // 0x6e152_ddiv = 111, // 0x6f153_irem = 112, // 0x70154_lrem = 113, // 0x71155_frem = 114, // 0x72156_drem = 115, // 0x73157_ineg = 116, // 0x74158_lneg = 117, // 0x75159_fneg = 118, // 0x76160_dneg = 119, // 0x77161_ishl = 120, // 0x78162_lshl = 121, // 0x79163_ishr = 122, // 0x7a164_lshr = 123, // 0x7b165_iushr = 124, // 0x7c166_lushr = 125, // 0x7d167_iand = 126, // 0x7e168_land = 127, // 0x7f169_ior = 128, // 0x80170_lor = 129, // 0x81171_ixor = 130, // 0x82172_lxor = 131, // 0x83173_iinc = 132, // 0x84174_i2l = 133, // 0x85175_i2f = 134, // 0x86176_i2d = 135, // 0x87177_l2i = 136, // 0x88178_l2f = 137, // 0x89179_l2d = 138, // 0x8a180_f2i = 139, // 0x8b181_f2l = 140, // 0x8c182_f2d = 141, // 0x8d183_d2i = 142, // 0x8e184_d2l = 143, // 0x8f185_d2f = 144, // 0x90186_i2b = 145, // 0x91187_i2c = 146, // 0x92188_i2s = 147, // 0x93189_lcmp = 148, // 0x94190_fcmpl = 149, // 0x95191_fcmpg = 150, // 0x96192_dcmpl = 151, // 0x97193_dcmpg = 152, // 0x98194_ifeq = 153, // 0x99195_ifne = 154, // 0x9a196_iflt = 155, // 0x9b197_ifge = 156, // 0x9c198_ifgt = 157, // 0x9d199_ifle = 158, // 0x9e200_if_icmpeq = 159, // 0x9f201_if_icmpne = 160, // 0xa0202_if_icmplt = 161, // 0xa1203_if_icmpge = 162, // 0xa2204_if_icmpgt = 163, // 0xa3205_if_icmple = 164, // 0xa4206_if_acmpeq = 165, // 0xa5207_if_acmpne = 166, // 0xa6208_goto = 167, // 0xa7209_jsr = 168, // 0xa8210_ret = 169, // 0xa9211_tableswitch = 170, // 0xaa212_lookupswitch = 171, // 0xab213_ireturn = 172, // 0xac214_lreturn = 173, // 0xad215_freturn = 174, // 0xae216_dreturn = 175, // 0xaf217_areturn = 176, // 0xb0218_return = 177, // 0xb1219_getstatic = 178, // 0xb2220_putstatic = 179, // 0xb3221_getfield = 180, // 0xb4222_putfield = 181, // 0xb5223_invokevirtual = 182, // 0xb6224_invokespecial = 183, // 0xb7225_invokestatic = 184, // 0xb8226_invokeinterface = 185, // 0xb9227_invokedynamic = 186, // 0xba228_new = 187, // 0xbb229_newarray = 188, // 0xbc230_anewarray = 189, // 0xbd231_arraylength = 190, // 0xbe232_athrow = 191, // 0xbf233_checkcast = 192, // 0xc0234_instanceof = 193, // 0xc1235_monitorenter = 194, // 0xc2236_monitorexit = 195, // 0xc3237_wide = 196, // 0xc4238_multianewarray = 197, // 0xc5239_ifnull = 198, // 0xc6240_ifnonnull = 199, // 0xc7241_goto_w = 200, // 0xc8242_jsr_w = 201, // 0xc9243_breakpoint = 202, // 0xca244245number_of_java_codes,246247// JVM bytecodes248_fast_agetfield = number_of_java_codes,249_fast_bgetfield ,250_fast_cgetfield ,251_fast_dgetfield ,252_fast_fgetfield ,253_fast_igetfield ,254_fast_lgetfield ,255_fast_sgetfield ,256257_fast_aputfield ,258_fast_bputfield ,259_fast_zputfield ,260_fast_cputfield ,261_fast_dputfield ,262_fast_fputfield ,263_fast_iputfield ,264_fast_lputfield ,265_fast_sputfield ,266267_fast_aload_0 ,268_fast_iaccess_0 ,269_fast_aaccess_0 ,270_fast_faccess_0 ,271272_fast_iload ,273_fast_iload2 ,274_fast_icaload ,275276_fast_invokevfinal ,277_fast_linearswitch ,278_fast_binaryswitch ,279280// special handling of oop constants:281_fast_aldc ,282_fast_aldc_w ,283284_return_register_finalizer ,285286// special handling of signature-polymorphic methods:287_invokehandle ,288289// These bytecodes are rewritten at CDS dump time, so that we can prevent them from being290// rewritten at run time. This way, the ConstMethods can be placed in the CDS ReadOnly291// section, and RewriteByteCodes/RewriteFrequentPairs can rewrite non-CDS bytecodes292// at run time.293//294// Rewritten at CDS dump time to | Original bytecode295// _invoke_virtual rewritten on sparc, will be disabled if UseSharedSpaces turned on.296// ------------------------------+------------------297_nofast_getfield , // <- _getfield298_nofast_putfield , // <- _putfield299_nofast_aload_0 , // <- _aload_0300_nofast_iload , // <- _iload301302_shouldnotreachhere , // For debugging303304305number_of_codes306};307308// Flag bits derived from format strings, can_trap, can_rewrite, etc.:309enum Flags {310// semantic flags:311_bc_can_trap = 1<<0, // bytecode execution can trap or block312_bc_can_rewrite = 1<<1, // bytecode execution has an alternate form313314// format bits (determined only by the format string):315_fmt_has_c = 1<<2, // constant, such as sipush "bcc"316_fmt_has_j = 1<<3, // constant pool cache index, such as getfield "bjj"317_fmt_has_k = 1<<4, // constant pool index, such as ldc "bk"318_fmt_has_i = 1<<5, // local index, such as iload319_fmt_has_o = 1<<6, // offset, such as ifeq320_fmt_has_nbo = 1<<7, // contains native-order field(s)321_fmt_has_u2 = 1<<8, // contains double-byte field(s)322_fmt_has_u4 = 1<<9, // contains quad-byte field323_fmt_not_variable = 1<<10, // not of variable length (simple or wide)324_fmt_not_simple = 1<<11, // either wide or variable length325_all_fmt_bits = (_fmt_not_simple*2 - _fmt_has_c),326327// Example derived format syndromes:328_fmt_b = _fmt_not_variable,329_fmt_bc = _fmt_b | _fmt_has_c,330_fmt_bi = _fmt_b | _fmt_has_i,331_fmt_bkk = _fmt_b | _fmt_has_k | _fmt_has_u2,332_fmt_bJJ = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo,333_fmt_bo2 = _fmt_b | _fmt_has_o | _fmt_has_u2,334_fmt_bo4 = _fmt_b | _fmt_has_o | _fmt_has_u4335};336337private:338static bool _is_initialized;339static const char* _name [number_of_codes];340static BasicType _result_type [number_of_codes];341static s_char _depth [number_of_codes];342static u_char _lengths [number_of_codes];343static Code _java_code [number_of_codes];344static jchar _flags [(1<<BitsPerByte)*2]; // all second page for wide formats345346static void def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap);347static 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);348349// Verify that bcp points into method350#ifdef ASSERT351static bool check_method(const Method* method, address bcp);352#endif353static bool check_must_rewrite(Bytecodes::Code bc);354355public:356// Conversion357static void check (Code code) { assert(is_defined(code), "illegal code: %d", (int)code); }358static void wide_check (Code code) { assert(wide_is_defined(code), "illegal code: %d", (int)code); }359static Code cast (int code) { return (Code)code; }360361362// Fetch a bytecode, hiding breakpoints as necessary. The method363// argument is used for conversion of breakpoints into the original364// bytecode. The CI uses these methods but guarantees that365// breakpoints are hidden so the method argument should be passed as366// NULL since in that case the bcp and Method* are unrelated367// memory.368static Code code_at(const Method* method, address bcp) {369assert(method == NULL || check_method(method, bcp), "bcp must point into method");370Code code = cast(*bcp);371assert(code != _breakpoint || method != NULL, "need Method* to decode breakpoint");372return (code != _breakpoint) ? code : non_breakpoint_code_at(method, bcp);373}374static Code java_code_at(const Method* method, address bcp) {375return java_code(code_at(method, bcp));376}377378// Fetch a bytecode or a breakpoint:379static Code code_or_bp_at(address bcp) { return (Code)cast(*bcp); }380381static Code code_at(Method* method, int bci);382383// find a bytecode, behind a breakpoint if necessary:384static Code non_breakpoint_code_at(const Method* method, address bcp);385386// Bytecode attributes387static bool is_valid (int code) { return 0 <= code && code < number_of_codes; }388static bool is_defined (int code) { return is_valid(code) && flags(code, false) != 0; }389static bool wide_is_defined(int code) { return is_defined(code) && flags(code, true) != 0; }390static const char* name (Code code) { check(code); return _name [code]; }391static BasicType result_type (Code code) { check(code); return _result_type [code]; }392static int depth (Code code) { check(code); return _depth [code]; }393// Note: Length functions must return <=0 for invalid bytecodes.394// Calling check(code) in length functions would throw an unwanted assert.395static int length_for (Code code) { return is_valid(code) ? _lengths[code] & 0xF : -1; }396static int wide_length_for(Code code) { return is_valid(code) ? _lengths[code] >> 4 : -1; }397static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); }398static Code java_code (Code code) { check(code); return _java_code [code]; }399static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); }400static bool must_rewrite(Bytecodes::Code code) { return can_rewrite(code) && check_must_rewrite(code); }401static bool native_byte_order(Code code) { check(code); return has_all_flags(code, _fmt_has_nbo, false); }402static bool uses_cp_cache (Code code) { check(code); return has_all_flags(code, _fmt_has_j, false); }403// if 'end' is provided, it indicates the end of the code buffer which404// should not be read past when parsing.405static int special_length_at(Bytecodes::Code code, address bcp, address end = NULL);406static int raw_special_length_at(address bcp, address end = NULL);407static int length_for_code_at(Bytecodes::Code code, address bcp) { int l = length_for(code); return l > 0 ? l : special_length_at(code, bcp); }408static int length_at (Method* method, address bcp) { return length_for_code_at(code_at(method, bcp), bcp); }409static int java_length_at (Method* method, address bcp) { return length_for_code_at(java_code_at(method, bcp), bcp); }410static bool is_java_code (Code code) { return 0 <= code && code < number_of_java_codes; }411412static bool is_store_into_local(Code code){ return (_istore <= code && code <= _astore_3); }413static bool is_const (Code code) { return (_aconst_null <= code && code <= _ldc2_w); }414static bool is_zero_const (Code code) { return (code == _aconst_null || code == _iconst_0415|| code == _fconst_0 || code == _dconst_0); }416static bool is_return (Code code) { return (_ireturn <= code && code <= _return); }417static bool is_invoke (Code code) { return (_invokevirtual <= code && code <= _invokedynamic); }418static bool has_receiver (Code code) { assert(is_invoke(code), ""); return code == _invokevirtual ||419code == _invokespecial ||420code == _invokeinterface; }421static bool has_optional_appendix(Code code) { return code == _invokedynamic || code == _invokehandle; }422423static int compute_flags (const char* format, int more_flags = 0); // compute the flags424static int flags (int code, bool is_wide) {425assert(code == (u_char)code, "must be a byte");426return _flags[code + (is_wide ? (1<<BitsPerByte) : 0)];427}428static bool has_all_flags (Code code, int test_flags, bool is_wide) {429return (flags(code, is_wide) & test_flags) == test_flags;430}431432// Initialization433static void initialize ();434};435436#endif // SHARE_INTERPRETER_BYTECODES_HPP437438439