Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/bytecodes.hpp
32285 views
/*1* Copyright (c) 1997, 2016, 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_VM_INTERPRETER_BYTECODES_HPP25#define SHARE_VM_INTERPRETER_BYTECODES_HPP2627#include "memory/allocation.hpp"28#include "utilities/top.hpp"2930// Bytecodes specifies all bytecodes used in the VM and31// provides utility functions to get bytecode attributes.3233// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java34class Bytecodes: AllStatic {35public:36enum Code {37_illegal = -1,3839// Java bytecodes40_nop = 0, // 0x0041_aconst_null = 1, // 0x0142_iconst_m1 = 2, // 0x0243_iconst_0 = 3, // 0x0344_iconst_1 = 4, // 0x0445_iconst_2 = 5, // 0x0546_iconst_3 = 6, // 0x0647_iconst_4 = 7, // 0x0748_iconst_5 = 8, // 0x0849_lconst_0 = 9, // 0x0950_lconst_1 = 10, // 0x0a51_fconst_0 = 11, // 0x0b52_fconst_1 = 12, // 0x0c53_fconst_2 = 13, // 0x0d54_dconst_0 = 14, // 0x0e55_dconst_1 = 15, // 0x0f56_bipush = 16, // 0x1057_sipush = 17, // 0x1158_ldc = 18, // 0x1259_ldc_w = 19, // 0x1360_ldc2_w = 20, // 0x1461_iload = 21, // 0x1562_lload = 22, // 0x1663_fload = 23, // 0x1764_dload = 24, // 0x1865_aload = 25, // 0x1966_iload_0 = 26, // 0x1a67_iload_1 = 27, // 0x1b68_iload_2 = 28, // 0x1c69_iload_3 = 29, // 0x1d70_lload_0 = 30, // 0x1e71_lload_1 = 31, // 0x1f72_lload_2 = 32, // 0x2073_lload_3 = 33, // 0x2174_fload_0 = 34, // 0x2275_fload_1 = 35, // 0x2376_fload_2 = 36, // 0x2477_fload_3 = 37, // 0x2578_dload_0 = 38, // 0x2679_dload_1 = 39, // 0x2780_dload_2 = 40, // 0x2881_dload_3 = 41, // 0x2982_aload_0 = 42, // 0x2a83_aload_1 = 43, // 0x2b84_aload_2 = 44, // 0x2c85_aload_3 = 45, // 0x2d86_iaload = 46, // 0x2e87_laload = 47, // 0x2f88_faload = 48, // 0x3089_daload = 49, // 0x3190_aaload = 50, // 0x3291_baload = 51, // 0x3392_caload = 52, // 0x3493_saload = 53, // 0x3594_istore = 54, // 0x3695_lstore = 55, // 0x3796_fstore = 56, // 0x3897_dstore = 57, // 0x3998_astore = 58, // 0x3a99_istore_0 = 59, // 0x3b100_istore_1 = 60, // 0x3c101_istore_2 = 61, // 0x3d102_istore_3 = 62, // 0x3e103_lstore_0 = 63, // 0x3f104_lstore_1 = 64, // 0x40105_lstore_2 = 65, // 0x41106_lstore_3 = 66, // 0x42107_fstore_0 = 67, // 0x43108_fstore_1 = 68, // 0x44109_fstore_2 = 69, // 0x45110_fstore_3 = 70, // 0x46111_dstore_0 = 71, // 0x47112_dstore_1 = 72, // 0x48113_dstore_2 = 73, // 0x49114_dstore_3 = 74, // 0x4a115_astore_0 = 75, // 0x4b116_astore_1 = 76, // 0x4c117_astore_2 = 77, // 0x4d118_astore_3 = 78, // 0x4e119_iastore = 79, // 0x4f120_lastore = 80, // 0x50121_fastore = 81, // 0x51122_dastore = 82, // 0x52123_aastore = 83, // 0x53124_bastore = 84, // 0x54125_castore = 85, // 0x55126_sastore = 86, // 0x56127_pop = 87, // 0x57128_pop2 = 88, // 0x58129_dup = 89, // 0x59130_dup_x1 = 90, // 0x5a131_dup_x2 = 91, // 0x5b132_dup2 = 92, // 0x5c133_dup2_x1 = 93, // 0x5d134_dup2_x2 = 94, // 0x5e135_swap = 95, // 0x5f136_iadd = 96, // 0x60137_ladd = 97, // 0x61138_fadd = 98, // 0x62139_dadd = 99, // 0x63140_isub = 100, // 0x64141_lsub = 101, // 0x65142_fsub = 102, // 0x66143_dsub = 103, // 0x67144_imul = 104, // 0x68145_lmul = 105, // 0x69146_fmul = 106, // 0x6a147_dmul = 107, // 0x6b148_idiv = 108, // 0x6c149_ldiv = 109, // 0x6d150_fdiv = 110, // 0x6e151_ddiv = 111, // 0x6f152_irem = 112, // 0x70153_lrem = 113, // 0x71154_frem = 114, // 0x72155_drem = 115, // 0x73156_ineg = 116, // 0x74157_lneg = 117, // 0x75158_fneg = 118, // 0x76159_dneg = 119, // 0x77160_ishl = 120, // 0x78161_lshl = 121, // 0x79162_ishr = 122, // 0x7a163_lshr = 123, // 0x7b164_iushr = 124, // 0x7c165_lushr = 125, // 0x7d166_iand = 126, // 0x7e167_land = 127, // 0x7f168_ior = 128, // 0x80169_lor = 129, // 0x81170_ixor = 130, // 0x82171_lxor = 131, // 0x83172_iinc = 132, // 0x84173_i2l = 133, // 0x85174_i2f = 134, // 0x86175_i2d = 135, // 0x87176_l2i = 136, // 0x88177_l2f = 137, // 0x89178_l2d = 138, // 0x8a179_f2i = 139, // 0x8b180_f2l = 140, // 0x8c181_f2d = 141, // 0x8d182_d2i = 142, // 0x8e183_d2l = 143, // 0x8f184_d2f = 144, // 0x90185_i2b = 145, // 0x91186_i2c = 146, // 0x92187_i2s = 147, // 0x93188_lcmp = 148, // 0x94189_fcmpl = 149, // 0x95190_fcmpg = 150, // 0x96191_dcmpl = 151, // 0x97192_dcmpg = 152, // 0x98193_ifeq = 153, // 0x99194_ifne = 154, // 0x9a195_iflt = 155, // 0x9b196_ifge = 156, // 0x9c197_ifgt = 157, // 0x9d198_ifle = 158, // 0x9e199_if_icmpeq = 159, // 0x9f200_if_icmpne = 160, // 0xa0201_if_icmplt = 161, // 0xa1202_if_icmpge = 162, // 0xa2203_if_icmpgt = 163, // 0xa3204_if_icmple = 164, // 0xa4205_if_acmpeq = 165, // 0xa5206_if_acmpne = 166, // 0xa6207_goto = 167, // 0xa7208_jsr = 168, // 0xa8209_ret = 169, // 0xa9210_tableswitch = 170, // 0xaa211_lookupswitch = 171, // 0xab212_ireturn = 172, // 0xac213_lreturn = 173, // 0xad214_freturn = 174, // 0xae215_dreturn = 175, // 0xaf216_areturn = 176, // 0xb0217_return = 177, // 0xb1218_getstatic = 178, // 0xb2219_putstatic = 179, // 0xb3220_getfield = 180, // 0xb4221_putfield = 181, // 0xb5222_invokevirtual = 182, // 0xb6223_invokespecial = 183, // 0xb7224_invokestatic = 184, // 0xb8225_invokeinterface = 185, // 0xb9226_invokedynamic = 186, // 0xba // if EnableInvokeDynamic227_new = 187, // 0xbb228_newarray = 188, // 0xbc229_anewarray = 189, // 0xbd230_arraylength = 190, // 0xbe231_athrow = 191, // 0xbf232_checkcast = 192, // 0xc0233_instanceof = 193, // 0xc1234_monitorenter = 194, // 0xc2235_monitorexit = 195, // 0xc3236_wide = 196, // 0xc4237_multianewarray = 197, // 0xc5238_ifnull = 198, // 0xc6239_ifnonnull = 199, // 0xc7240_goto_w = 200, // 0xc8241_jsr_w = 201, // 0xc9242_breakpoint = 202, // 0xca243244number_of_java_codes,245246// JVM bytecodes247_fast_agetfield = number_of_java_codes,248_fast_bgetfield ,249_fast_cgetfield ,250_fast_dgetfield ,251_fast_fgetfield ,252_fast_igetfield ,253_fast_lgetfield ,254_fast_sgetfield ,255256_fast_aputfield ,257_fast_bputfield ,258_fast_zputfield ,259_fast_cputfield ,260_fast_dputfield ,261_fast_fputfield ,262_fast_iputfield ,263_fast_lputfield ,264_fast_sputfield ,265266_fast_aload_0 ,267_fast_iaccess_0 ,268_fast_aaccess_0 ,269_fast_faccess_0 ,270271_fast_iload ,272_fast_iload2 ,273_fast_icaload ,274275_fast_invokevfinal ,276_fast_linearswitch ,277_fast_binaryswitch ,278279// special handling of oop constants:280_fast_aldc ,281_fast_aldc_w ,282283_return_register_finalizer ,284285// special handling of signature-polymorphic methods:286_invokehandle ,287288_shouldnotreachhere, // For debugging289290// Platform specific JVM bytecodes291#ifdef TARGET_ARCH_x86292# include "bytecodes_x86.hpp"293#endif294#ifdef TARGET_ARCH_aarch32295# include "bytecodes_aarch32.hpp"296#endif297#ifdef TARGET_ARCH_aarch64298# include "bytecodes_aarch64.hpp"299#endif300#ifdef TARGET_ARCH_sparc301# include "bytecodes_sparc.hpp"302#endif303#ifdef TARGET_ARCH_zero304# include "bytecodes_zero.hpp"305#endif306#ifdef TARGET_ARCH_arm307# include "bytecodes_arm.hpp"308#endif309#ifdef TARGET_ARCH_ppc310# include "bytecodes_ppc.hpp"311#endif312313314number_of_codes315};316317// Flag bits derived from format strings, can_trap, can_rewrite, etc.:318enum Flags {319// semantic flags:320_bc_can_trap = 1<<0, // bytecode execution can trap or block321_bc_can_rewrite = 1<<1, // bytecode execution has an alternate form322323// format bits (determined only by the format string):324_fmt_has_c = 1<<2, // constant, such as sipush "bcc"325_fmt_has_j = 1<<3, // constant pool cache index, such as getfield "bjj"326_fmt_has_k = 1<<4, // constant pool index, such as ldc "bk"327_fmt_has_i = 1<<5, // local index, such as iload328_fmt_has_o = 1<<6, // offset, such as ifeq329_fmt_has_nbo = 1<<7, // contains native-order field(s)330_fmt_has_u2 = 1<<8, // contains double-byte field(s)331_fmt_has_u4 = 1<<9, // contains quad-byte field332_fmt_not_variable = 1<<10, // not of variable length (simple or wide)333_fmt_not_simple = 1<<11, // either wide or variable length334_all_fmt_bits = (_fmt_not_simple*2 - _fmt_has_c),335336// Example derived format syndromes:337_fmt_b = _fmt_not_variable,338_fmt_bc = _fmt_b | _fmt_has_c,339_fmt_bi = _fmt_b | _fmt_has_i,340_fmt_bkk = _fmt_b | _fmt_has_k | _fmt_has_u2,341_fmt_bJJ = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo,342_fmt_bo2 = _fmt_b | _fmt_has_o | _fmt_has_u2,343_fmt_bo4 = _fmt_b | _fmt_has_o | _fmt_has_u4344};345346private:347static bool _is_initialized;348static const char* _name [number_of_codes];349static BasicType _result_type [number_of_codes];350static s_char _depth [number_of_codes];351static u_char _lengths [number_of_codes];352static Code _java_code [number_of_codes];353static jchar _flags [(1<<BitsPerByte)*2]; // all second page for wide formats354355static void def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap);356static 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);357static void pd_initialize(); // platform specific initialization358static Code pd_base_code_for(Code code); // platform specific base_code_for implementation359360// Verify that bcp points into method361#ifdef ASSERT362static bool check_method(const Method* method, address bcp);363#endif364static bool check_must_rewrite(Bytecodes::Code bc);365366public:367// Conversion368static void check (Code code) { assert(is_defined(code), err_msg("illegal code: %d", (int)code)); }369static void wide_check (Code code) { assert(wide_is_defined(code), err_msg("illegal code: %d", (int)code)); }370static Code cast (int code) { return (Code)code; }371372373// Fetch a bytecode, hiding breakpoints as necessary. The method374// argument is used for conversion of breakpoints into the original375// bytecode. The CI uses these methods but guarantees that376// breakpoints are hidden so the method argument should be passed as377// NULL since in that case the bcp and Method* are unrelated378// memory.379static Code code_at(const Method* method, address bcp) {380assert(method == NULL || check_method(method, bcp), "bcp must point into method");381Code code = cast(*bcp);382assert(code != _breakpoint || method != NULL, "need Method* to decode breakpoint");383return (code != _breakpoint) ? code : non_breakpoint_code_at(method, bcp);384}385static Code java_code_at(const Method* method, address bcp) {386return java_code(code_at(method, bcp));387}388389// Fetch a bytecode or a breakpoint:390static Code code_or_bp_at(address bcp) { return (Code)cast(*bcp); }391392static Code code_at(Method* method, int bci);393static bool is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; }394395// find a bytecode, behind a breakpoint if necessary:396static Code non_breakpoint_code_at(const Method* method, address bcp);397398// Bytecode attributes399static bool is_defined (int code) { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }400static bool wide_is_defined(int code) { return is_defined(code) && flags(code, true) != 0; }401static const char* name (Code code) { check(code); return _name [code]; }402static BasicType result_type (Code code) { check(code); return _result_type [code]; }403static int depth (Code code) { check(code); return _depth [code]; }404// Note: Length functions must return <=0 for invalid bytecodes.405// Calling check(code) in length functions would throw an unwanted assert.406static int length_for (Code code) { /*no check*/ return _lengths [code] & 0xF; }407static int wide_length_for(Code code) { /*no check*/ return _lengths [code] >> 4; }408static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); }409static Code java_code (Code code) { check(code); return _java_code [code]; }410static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); }411static bool must_rewrite(Bytecodes::Code code) { return can_rewrite(code) && check_must_rewrite(code); }412static bool native_byte_order(Code code) { check(code); return has_all_flags(code, _fmt_has_nbo, false); }413static bool uses_cp_cache (Code code) { check(code); return has_all_flags(code, _fmt_has_j, false); }414// if 'end' is provided, it indicates the end of the code buffer which415// should not be read past when parsing.416static int special_length_at(Bytecodes::Code code, address bcp, address end = NULL);417static int special_length_at(Method* method, address bcp, address end = NULL) { return special_length_at(code_at(method, bcp), bcp, end); }418static int raw_special_length_at(address bcp, address end = NULL);419static int length_for_code_at(Bytecodes::Code code, address bcp) { int l = length_for(code); return l > 0 ? l : special_length_at(code, bcp); }420static int length_at (Method* method, address bcp) { return length_for_code_at(code_at(method, bcp), bcp); }421static int java_length_at (Method* method, address bcp) { return length_for_code_at(java_code_at(method, bcp), bcp); }422static bool is_java_code (Code code) { return 0 <= code && code < number_of_java_codes; }423424static bool is_aload (Code code) { return (code == _aload || code == _aload_0 || code == _aload_1425|| code == _aload_2 || code == _aload_3); }426static bool is_astore (Code code) { return (code == _astore || code == _astore_0 || code == _astore_1427|| code == _astore_2 || code == _astore_3); }428429static bool is_store_into_local(Code code){ return (_istore <= code && code <= _astore_3); }430static bool is_const (Code code) { return (_aconst_null <= code && code <= _ldc2_w); }431static bool is_zero_const (Code code) { return (code == _aconst_null || code == _iconst_0432|| code == _fconst_0 || code == _dconst_0); }433static bool is_return (Code code) { return (_ireturn <= code && code <= _return); }434static bool is_invoke (Code code) { return (_invokevirtual <= code && code <= _invokedynamic); }435static bool has_receiver (Code code) { assert(is_invoke(code), ""); return code == _invokevirtual ||436code == _invokespecial ||437code == _invokeinterface; }438static bool has_optional_appendix(Code code) { return code == _invokedynamic || code == _invokehandle; }439440static int compute_flags (const char* format, int more_flags = 0); // compute the flags441static int flags (int code, bool is_wide) {442assert(code == (u_char)code, "must be a byte");443return _flags[code + (is_wide ? (1<<BitsPerByte) : 0)];444}445static int format_bits (Code code, bool is_wide) { return flags(code, is_wide) & _all_fmt_bits; }446static bool has_all_flags (Code code, int test_flags, bool is_wide) {447return (flags(code, is_wide) & test_flags) == test_flags;448}449450// Initialization451static void initialize ();452};453454#endif // SHARE_VM_INTERPRETER_BYTECODES_HPP455456457