1 /* 2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "interpreter/bytecodes.hpp" 26 #include "memory/resourceArea.hpp" 27 #include "oops/method.hpp" 28 #include "utilities/align.hpp" 29 #include "utilities/bytes.hpp" 30 31 #define JVM_BYTECODES_DO(def) \ 32 def(_fast_agetfield , "fast_agetfield" , "bJJ" , nullptr , T_OBJECT , 0, true , _getfield ) \ 33 def(_fast_bgetfield , "fast_bgetfield" , "bJJ" , nullptr , T_INT , 0, true , _getfield ) \ 34 def(_fast_cgetfield , "fast_cgetfield" , "bJJ" , nullptr , T_CHAR , 0, true , _getfield ) \ 35 def(_fast_dgetfield , "fast_dgetfield" , "bJJ" , nullptr , T_DOUBLE , 0, true , _getfield ) \ 36 def(_fast_fgetfield , "fast_fgetfield" , "bJJ" , nullptr , T_FLOAT , 0, true , _getfield ) \ 37 def(_fast_igetfield , "fast_igetfield" , "bJJ" , nullptr , T_INT , 0, true , _getfield ) \ 38 def(_fast_lgetfield , "fast_lgetfield" , "bJJ" , nullptr , T_LONG , 0, true , _getfield ) \ 39 def(_fast_sgetfield , "fast_sgetfield" , "bJJ" , nullptr , T_SHORT , 0, true , _getfield ) \ 40 \ 41 def(_fast_aputfield , "fast_aputfield" , "bJJ" , nullptr , T_OBJECT , 0, true , _putfield ) \ 42 def(_fast_bputfield , "fast_bputfield" , "bJJ" , nullptr , T_INT , 0, true , _putfield ) \ 43 def(_fast_zputfield , "fast_zputfield" , "bJJ" , nullptr , T_INT , 0, true , _putfield ) \ 44 def(_fast_cputfield , "fast_cputfield" , "bJJ" , nullptr , T_CHAR , 0, true , _putfield ) \ 45 def(_fast_dputfield , "fast_dputfield" , "bJJ" , nullptr , T_DOUBLE , 0, true , _putfield ) \ 46 def(_fast_fputfield , "fast_fputfield" , "bJJ" , nullptr , T_FLOAT , 0, true , _putfield ) \ 47 def(_fast_iputfield , "fast_iputfield" , "bJJ" , nullptr , T_INT , 0, true , _putfield ) \ 48 def(_fast_lputfield , "fast_lputfield" , "bJJ" , nullptr , T_LONG , 0, true , _putfield ) \ 49 def(_fast_sputfield , "fast_sputfield" , "bJJ" , nullptr , T_SHORT , 0, true , _putfield ) \ 50 \ 51 def(_fast_aload_0 , "fast_aload_0" , "b" , nullptr , T_OBJECT , 1, true , _aload_0 ) \ 52 def(_fast_iaccess_0 , "fast_iaccess_0" , "b_JJ" , nullptr , T_INT , 1, true , _aload_0 ) \ 53 def(_fast_aaccess_0 , "fast_aaccess_0" , "b_JJ" , nullptr , T_OBJECT , 1, true , _aload_0 ) \ 54 def(_fast_faccess_0 , "fast_faccess_0" , "b_JJ" , nullptr , T_OBJECT , 1, true , _aload_0 ) \ 55 \ 56 def(_fast_iload , "fast_iload" , "bi" , nullptr , T_INT , 1, false, _iload ) \ 57 def(_fast_iload2 , "fast_iload2" , "bi_i" , nullptr , T_INT , 2, false, _iload ) \ 58 def(_fast_icaload , "fast_icaload" , "bi_" , nullptr , T_INT , 0, false, _iload ) \ 59 \ 60 def(_fast_invokevfinal , "fast_invokevfinal" , "bJJ" , nullptr , T_ILLEGAL, -1, true , _invokevirtual ) \ 61 def(_fast_linearswitch , "fast_linearswitch" , "" , nullptr , T_VOID , -1, false, _lookupswitch ) \ 62 def(_fast_binaryswitch , "fast_binaryswitch" , "" , nullptr , T_VOID , -1, false, _lookupswitch ) \ 63 \ 64 def(_fast_aldc , "fast_aldc" , "bj" , nullptr , T_OBJECT , 1, true , _ldc ) \ 65 def(_fast_aldc_w , "fast_aldc_w" , "bJJ" , nullptr , T_OBJECT , 1, true , _ldc_w ) \ 66 \ 67 def(_return_register_finalizer , "return_register_finalizer" , "b" , nullptr , T_VOID , 0, true , _return ) \ 68 \ 69 def(_invokehandle , "invokehandle" , "bJJ" , nullptr , T_ILLEGAL, -1, true , _invokevirtual ) \ 70 \ 71 def(_nofast_getfield , "nofast_getfield" , "bJJ" , nullptr , T_ILLEGAL, 0, true , _getfield ) \ 72 def(_nofast_putfield , "nofast_putfield" , "bJJ" , nullptr , T_ILLEGAL, -2, true , _putfield ) \ 73 def(_nofast_aload_0 , "nofast_aload_0" , "b" , nullptr , T_OBJECT , 1, true , _aload_0 ) \ 74 def(_nofast_iload , "nofast_iload" , "bi" , nullptr , T_INT , 1, false, _iload ) \ 75 \ 76 def(_shouldnotreachhere , "_shouldnotreachhere" , "b" , nullptr , T_VOID , 0, false, _shouldnotreachhere) 77 78 #define BYTECODES_DO(def) \ 79 def(_nop , "nop" , "b" , nullptr , T_VOID , 0, false, _nop ) \ 80 def(_aconst_null , "aconst_null" , "b" , nullptr , T_OBJECT , 1, false, _aconst_null ) \ 81 def(_iconst_m1 , "iconst_m1" , "b" , nullptr , T_INT , 1, false, _iconst_m1 ) \ 82 def(_iconst_0 , "iconst_0" , "b" , nullptr , T_INT , 1, false, _iconst_0 ) \ 83 def(_iconst_1 , "iconst_1" , "b" , nullptr , T_INT , 1, false, _iconst_1 ) \ 84 def(_iconst_2 , "iconst_2" , "b" , nullptr , T_INT , 1, false, _iconst_2 ) \ 85 def(_iconst_3 , "iconst_3" , "b" , nullptr , T_INT , 1, false, _iconst_3 ) \ 86 def(_iconst_4 , "iconst_4" , "b" , nullptr , T_INT , 1, false, _iconst_4 ) \ 87 def(_iconst_5 , "iconst_5" , "b" , nullptr , T_INT , 1, false, _iconst_5 ) \ 88 def(_lconst_0 , "lconst_0" , "b" , nullptr , T_LONG , 2, false, _lconst_0 ) \ 89 def(_lconst_1 , "lconst_1" , "b" , nullptr , T_LONG , 2, false, _lconst_1 ) \ 90 def(_fconst_0 , "fconst_0" , "b" , nullptr , T_FLOAT , 1, false, _fconst_0 ) \ 91 def(_fconst_1 , "fconst_1" , "b" , nullptr , T_FLOAT , 1, false, _fconst_1 ) \ 92 def(_fconst_2 , "fconst_2" , "b" , nullptr , T_FLOAT , 1, false, _fconst_2 ) \ 93 def(_dconst_0 , "dconst_0" , "b" , nullptr , T_DOUBLE , 2, false, _dconst_0 ) \ 94 def(_dconst_1 , "dconst_1" , "b" , nullptr , T_DOUBLE , 2, false, _dconst_1 ) \ 95 def(_bipush , "bipush" , "bc" , nullptr , T_INT , 1, false, _bipush ) \ 96 def(_sipush , "sipush" , "bcc" , nullptr , T_INT , 1, false, _sipush ) \ 97 def(_ldc , "ldc" , "bk" , nullptr , T_ILLEGAL, 1, true , _ldc ) \ 98 def(_ldc_w , "ldc_w" , "bkk" , nullptr , T_ILLEGAL, 1, true , _ldc_w ) \ 99 def(_ldc2_w , "ldc2_w" , "bkk" , nullptr , T_ILLEGAL, 2, true , _ldc2_w ) \ 100 def(_iload , "iload" , "bi" , "wbii" , T_INT , 1, false, _iload ) \ 101 def(_lload , "lload" , "bi" , "wbii" , T_LONG , 2, false, _lload ) \ 102 def(_fload , "fload" , "bi" , "wbii" , T_FLOAT , 1, false, _fload ) \ 103 def(_dload , "dload" , "bi" , "wbii" , T_DOUBLE , 2, false, _dload ) \ 104 def(_aload , "aload" , "bi" , "wbii" , T_OBJECT , 1, false, _aload ) \ 105 def(_iload_0 , "iload_0" , "b" , nullptr , T_INT , 1, false, _iload_0 ) \ 106 def(_iload_1 , "iload_1" , "b" , nullptr , T_INT , 1, false, _iload_1 ) \ 107 def(_iload_2 , "iload_2" , "b" , nullptr , T_INT , 1, false, _iload_2 ) \ 108 def(_iload_3 , "iload_3" , "b" , nullptr , T_INT , 1, false, _iload_3 ) \ 109 def(_lload_0 , "lload_0" , "b" , nullptr , T_LONG , 2, false, _lload_0 ) \ 110 def(_lload_1 , "lload_1" , "b" , nullptr , T_LONG , 2, false, _lload_1 ) \ 111 def(_lload_2 , "lload_2" , "b" , nullptr , T_LONG , 2, false, _lload_2 ) \ 112 def(_lload_3 , "lload_3" , "b" , nullptr , T_LONG , 2, false, _lload_3 ) \ 113 def(_fload_0 , "fload_0" , "b" , nullptr , T_FLOAT , 1, false, _fload_0 ) \ 114 def(_fload_1 , "fload_1" , "b" , nullptr , T_FLOAT , 1, false, _fload_1 ) \ 115 def(_fload_2 , "fload_2" , "b" , nullptr , T_FLOAT , 1, false, _fload_2 ) \ 116 def(_fload_3 , "fload_3" , "b" , nullptr , T_FLOAT , 1, false, _fload_3 ) \ 117 def(_dload_0 , "dload_0" , "b" , nullptr , T_DOUBLE , 2, false, _dload_0 ) \ 118 def(_dload_1 , "dload_1" , "b" , nullptr , T_DOUBLE , 2, false, _dload_1 ) \ 119 def(_dload_2 , "dload_2" , "b" , nullptr , T_DOUBLE , 2, false, _dload_2 ) \ 120 def(_dload_3 , "dload_3" , "b" , nullptr , T_DOUBLE , 2, false, _dload_3 ) \ 121 def(_aload_0 , "aload_0" , "b" , nullptr , T_OBJECT , 1, true , _aload_0 ) \ 122 def(_aload_1 , "aload_1" , "b" , nullptr , T_OBJECT , 1, false, _aload_1 ) \ 123 def(_aload_2 , "aload_2" , "b" , nullptr , T_OBJECT , 1, false, _aload_2 ) \ 124 def(_aload_3 , "aload_3" , "b" , nullptr , T_OBJECT , 1, false, _aload_3 ) \ 125 def(_iaload , "iaload" , "b" , nullptr , T_INT , -1, true , _iaload ) \ 126 def(_laload , "laload" , "b" , nullptr , T_LONG , 0, true , _laload ) \ 127 def(_faload , "faload" , "b" , nullptr , T_FLOAT , -1, true , _faload ) \ 128 def(_daload , "daload" , "b" , nullptr , T_DOUBLE , 0, true , _daload ) \ 129 def(_aaload , "aaload" , "b" , nullptr , T_OBJECT , -1, true , _aaload ) \ 130 def(_baload , "baload" , "b" , nullptr , T_INT , -1, true , _baload ) \ 131 def(_caload , "caload" , "b" , nullptr , T_INT , -1, true , _caload ) \ 132 def(_saload , "saload" , "b" , nullptr , T_INT , -1, true , _saload ) \ 133 def(_istore , "istore" , "bi" , "wbii" , T_VOID , -1, false, _istore ) \ 134 def(_lstore , "lstore" , "bi" , "wbii" , T_VOID , -2, false, _lstore ) \ 135 def(_fstore , "fstore" , "bi" , "wbii" , T_VOID , -1, false, _fstore ) \ 136 def(_dstore , "dstore" , "bi" , "wbii" , T_VOID , -2, false, _dstore ) \ 137 def(_astore , "astore" , "bi" , "wbii" , T_VOID , -1, false, _astore ) \ 138 def(_istore_0 , "istore_0" , "b" , nullptr , T_VOID , -1, false, _istore_0 ) \ 139 def(_istore_1 , "istore_1" , "b" , nullptr , T_VOID , -1, false, _istore_1 ) \ 140 def(_istore_2 , "istore_2" , "b" , nullptr , T_VOID , -1, false, _istore_2 ) \ 141 def(_istore_3 , "istore_3" , "b" , nullptr , T_VOID , -1, false, _istore_3 ) \ 142 def(_lstore_0 , "lstore_0" , "b" , nullptr , T_VOID , -2, false, _lstore_0 ) \ 143 def(_lstore_1 , "lstore_1" , "b" , nullptr , T_VOID , -2, false, _lstore_1 ) \ 144 def(_lstore_2 , "lstore_2" , "b" , nullptr , T_VOID , -2, false, _lstore_2 ) \ 145 def(_lstore_3 , "lstore_3" , "b" , nullptr , T_VOID , -2, false, _lstore_3 ) \ 146 def(_fstore_0 , "fstore_0" , "b" , nullptr , T_VOID , -1, false, _fstore_0 ) \ 147 def(_fstore_1 , "fstore_1" , "b" , nullptr , T_VOID , -1, false, _fstore_1 ) \ 148 def(_fstore_2 , "fstore_2" , "b" , nullptr , T_VOID , -1, false, _fstore_2 ) \ 149 def(_fstore_3 , "fstore_3" , "b" , nullptr , T_VOID , -1, false, _fstore_3 ) \ 150 def(_dstore_0 , "dstore_0" , "b" , nullptr , T_VOID , -2, false, _dstore_0 ) \ 151 def(_dstore_1 , "dstore_1" , "b" , nullptr , T_VOID , -2, false, _dstore_1 ) \ 152 def(_dstore_2 , "dstore_2" , "b" , nullptr , T_VOID , -2, false, _dstore_2 ) \ 153 def(_dstore_3 , "dstore_3" , "b" , nullptr , T_VOID , -2, false, _dstore_3 ) \ 154 def(_astore_0 , "astore_0" , "b" , nullptr , T_VOID , -1, false, _astore_0 ) \ 155 def(_astore_1 , "astore_1" , "b" , nullptr , T_VOID , -1, false, _astore_1 ) \ 156 def(_astore_2 , "astore_2" , "b" , nullptr , T_VOID , -1, false, _astore_2 ) \ 157 def(_astore_3 , "astore_3" , "b" , nullptr , T_VOID , -1, false, _astore_3 ) \ 158 def(_iastore , "iastore" , "b" , nullptr , T_VOID , -3, true , _iastore ) \ 159 def(_lastore , "lastore" , "b" , nullptr , T_VOID , -4, true , _lastore ) \ 160 def(_fastore , "fastore" , "b" , nullptr , T_VOID , -3, true , _fastore ) \ 161 def(_dastore , "dastore" , "b" , nullptr , T_VOID , -4, true , _dastore ) \ 162 def(_aastore , "aastore" , "b" , nullptr , T_VOID , -3, true , _aastore ) \ 163 def(_bastore , "bastore" , "b" , nullptr , T_VOID , -3, true , _bastore ) \ 164 def(_castore , "castore" , "b" , nullptr , T_VOID , -3, true , _castore ) \ 165 def(_sastore , "sastore" , "b" , nullptr , T_VOID , -3, true , _sastore ) \ 166 def(_pop , "pop" , "b" , nullptr , T_VOID , -1, false, _pop ) \ 167 def(_pop2 , "pop2" , "b" , nullptr , T_VOID , -2, false, _pop2 ) \ 168 def(_dup , "dup" , "b" , nullptr , T_VOID , 1, false, _dup ) \ 169 def(_dup_x1 , "dup_x1" , "b" , nullptr , T_VOID , 1, false, _dup_x1 ) \ 170 def(_dup_x2 , "dup_x2" , "b" , nullptr , T_VOID , 1, false, _dup_x2 ) \ 171 def(_dup2 , "dup2" , "b" , nullptr , T_VOID , 2, false, _dup2 ) \ 172 def(_dup2_x1 , "dup2_x1" , "b" , nullptr , T_VOID , 2, false, _dup2_x1 ) \ 173 def(_dup2_x2 , "dup2_x2" , "b" , nullptr , T_VOID , 2, false, _dup2_x2 ) \ 174 def(_swap , "swap" , "b" , nullptr , T_VOID , 0, false, _swap ) \ 175 def(_iadd , "iadd" , "b" , nullptr , T_INT , -1, false, _iadd ) \ 176 def(_ladd , "ladd" , "b" , nullptr , T_LONG , -2, false, _ladd ) \ 177 def(_fadd , "fadd" , "b" , nullptr , T_FLOAT , -1, false, _fadd ) \ 178 def(_dadd , "dadd" , "b" , nullptr , T_DOUBLE , -2, false, _dadd ) \ 179 def(_isub , "isub" , "b" , nullptr , T_INT , -1, false, _isub ) \ 180 def(_lsub , "lsub" , "b" , nullptr , T_LONG , -2, false, _lsub ) \ 181 def(_fsub , "fsub" , "b" , nullptr , T_FLOAT , -1, false, _fsub ) \ 182 def(_dsub , "dsub" , "b" , nullptr , T_DOUBLE , -2, false, _dsub ) \ 183 def(_imul , "imul" , "b" , nullptr , T_INT , -1, false, _imul ) \ 184 def(_lmul , "lmul" , "b" , nullptr , T_LONG , -2, false, _lmul ) \ 185 def(_fmul , "fmul" , "b" , nullptr , T_FLOAT , -1, false, _fmul ) \ 186 def(_dmul , "dmul" , "b" , nullptr , T_DOUBLE , -2, false, _dmul ) \ 187 def(_idiv , "idiv" , "b" , nullptr , T_INT , -1, true , _idiv ) \ 188 def(_ldiv , "ldiv" , "b" , nullptr , T_LONG , -2, true , _ldiv ) \ 189 def(_fdiv , "fdiv" , "b" , nullptr , T_FLOAT , -1, false, _fdiv ) \ 190 def(_ddiv , "ddiv" , "b" , nullptr , T_DOUBLE , -2, false, _ddiv ) \ 191 def(_irem , "irem" , "b" , nullptr , T_INT , -1, true , _irem ) \ 192 def(_lrem , "lrem" , "b" , nullptr , T_LONG , -2, true , _lrem ) \ 193 def(_frem , "frem" , "b" , nullptr , T_FLOAT , -1, false, _frem ) \ 194 def(_drem , "drem" , "b" , nullptr , T_DOUBLE , -2, false, _drem ) \ 195 def(_ineg , "ineg" , "b" , nullptr , T_INT , 0, false, _ineg ) \ 196 def(_lneg , "lneg" , "b" , nullptr , T_LONG , 0, false, _lneg ) \ 197 def(_fneg , "fneg" , "b" , nullptr , T_FLOAT , 0, false, _fneg ) \ 198 def(_dneg , "dneg" , "b" , nullptr , T_DOUBLE , 0, false, _dneg ) \ 199 def(_ishl , "ishl" , "b" , nullptr , T_INT , -1, false, _ishl ) \ 200 def(_lshl , "lshl" , "b" , nullptr , T_LONG , -1, false, _lshl ) \ 201 def(_ishr , "ishr" , "b" , nullptr , T_INT , -1, false, _ishr ) \ 202 def(_lshr , "lshr" , "b" , nullptr , T_LONG , -1, false, _lshr ) \ 203 def(_iushr , "iushr" , "b" , nullptr , T_INT , -1, false, _iushr ) \ 204 def(_lushr , "lushr" , "b" , nullptr , T_LONG , -1, false, _lushr ) \ 205 def(_iand , "iand" , "b" , nullptr , T_INT , -1, false, _iand ) \ 206 def(_land , "land" , "b" , nullptr , T_LONG , -2, false, _land ) \ 207 def(_ior , "ior" , "b" , nullptr , T_INT , -1, false, _ior ) \ 208 def(_lor , "lor" , "b" , nullptr , T_LONG , -2, false, _lor ) \ 209 def(_ixor , "ixor" , "b" , nullptr , T_INT , -1, false, _ixor ) \ 210 def(_lxor , "lxor" , "b" , nullptr , T_LONG , -2, false, _lxor ) \ 211 def(_iinc , "iinc" , "bic" , "wbiicc", T_VOID , 0, false, _iinc ) \ 212 def(_i2l , "i2l" , "b" , nullptr , T_LONG , 1, false, _i2l ) \ 213 def(_i2f , "i2f" , "b" , nullptr , T_FLOAT , 0, false, _i2f ) \ 214 def(_i2d , "i2d" , "b" , nullptr , T_DOUBLE , 1, false, _i2d ) \ 215 def(_l2i , "l2i" , "b" , nullptr , T_INT , -1, false, _l2i ) \ 216 def(_l2f , "l2f" , "b" , nullptr , T_FLOAT , -1, false, _l2f ) \ 217 def(_l2d , "l2d" , "b" , nullptr , T_DOUBLE , 0, false, _l2d ) \ 218 def(_f2i , "f2i" , "b" , nullptr , T_INT , 0, false, _f2i ) \ 219 def(_f2l , "f2l" , "b" , nullptr , T_LONG , 1, false, _f2l ) \ 220 def(_f2d , "f2d" , "b" , nullptr , T_DOUBLE , 1, false, _f2d ) \ 221 def(_d2i , "d2i" , "b" , nullptr , T_INT , -1, false, _d2i ) \ 222 def(_d2l , "d2l" , "b" , nullptr , T_LONG , 0, false, _d2l ) \ 223 def(_d2f , "d2f" , "b" , nullptr , T_FLOAT , -1, false, _d2f ) \ 224 def(_i2b , "i2b" , "b" , nullptr , T_BYTE , 0, false, _i2b ) \ 225 def(_i2c , "i2c" , "b" , nullptr , T_CHAR , 0, false, _i2c ) \ 226 def(_i2s , "i2s" , "b" , nullptr , T_SHORT , 0, false, _i2s ) \ 227 def(_lcmp , "lcmp" , "b" , nullptr , T_VOID , -3, false, _lcmp ) \ 228 def(_fcmpl , "fcmpl" , "b" , nullptr , T_VOID , -1, false, _fcmpl ) \ 229 def(_fcmpg , "fcmpg" , "b" , nullptr , T_VOID , -1, false, _fcmpg ) \ 230 def(_dcmpl , "dcmpl" , "b" , nullptr , T_VOID , -3, false, _dcmpl ) \ 231 def(_dcmpg , "dcmpg" , "b" , nullptr , T_VOID , -3, false, _dcmpg ) \ 232 def(_ifeq , "ifeq" , "boo" , nullptr , T_VOID , -1, false, _ifeq ) \ 233 def(_ifne , "ifne" , "boo" , nullptr , T_VOID , -1, false, _ifne ) \ 234 def(_iflt , "iflt" , "boo" , nullptr , T_VOID , -1, false, _iflt ) \ 235 def(_ifge , "ifge" , "boo" , nullptr , T_VOID , -1, false, _ifge ) \ 236 def(_ifgt , "ifgt" , "boo" , nullptr , T_VOID , -1, false, _ifgt ) \ 237 def(_ifle , "ifle" , "boo" , nullptr , T_VOID , -1, false, _ifle ) \ 238 def(_if_icmpeq , "if_icmpeq" , "boo" , nullptr , T_VOID , -2, false, _if_icmpeq ) \ 239 def(_if_icmpne , "if_icmpne" , "boo" , nullptr , T_VOID , -2, false, _if_icmpne ) \ 240 def(_if_icmplt , "if_icmplt" , "boo" , nullptr , T_VOID , -2, false, _if_icmplt ) \ 241 def(_if_icmpge , "if_icmpge" , "boo" , nullptr , T_VOID , -2, false, _if_icmpge ) \ 242 def(_if_icmpgt , "if_icmpgt" , "boo" , nullptr , T_VOID , -2, false, _if_icmpgt ) \ 243 def(_if_icmple , "if_icmple" , "boo" , nullptr , T_VOID , -2, false, _if_icmple ) \ 244 def(_if_acmpeq , "if_acmpeq" , "boo" , nullptr , T_VOID , -2, false, _if_acmpeq ) \ 245 def(_if_acmpne , "if_acmpne" , "boo" , nullptr , T_VOID , -2, false, _if_acmpne ) \ 246 def(_goto , "goto" , "boo" , nullptr , T_VOID , 0, false, _goto ) \ 247 def(_jsr , "jsr" , "boo" , nullptr , T_INT , 0, false, _jsr ) \ 248 def(_ret , "ret" , "bi" , "wbii" , T_VOID , 0, false, _ret ) \ 249 def(_tableswitch , "tableswitch" , "" , nullptr , T_VOID , -1, false, _tableswitch ) \ 250 def(_lookupswitch , "lookupswitch" , "" , nullptr , T_VOID , -1, false, _lookupswitch ) \ 251 def(_ireturn , "ireturn" , "b" , nullptr , T_INT , -1, true , _ireturn ) \ 252 def(_lreturn , "lreturn" , "b" , nullptr , T_LONG , -2, true , _lreturn ) \ 253 def(_freturn , "freturn" , "b" , nullptr , T_FLOAT , -1, true , _freturn ) \ 254 def(_dreturn , "dreturn" , "b" , nullptr , T_DOUBLE , -2, true , _dreturn ) \ 255 def(_areturn , "areturn" , "b" , nullptr , T_OBJECT , -1, true , _areturn ) \ 256 def(_return , "return" , "b" , nullptr , T_VOID , 0, true , _return ) \ 257 def(_getstatic , "getstatic" , "bJJ" , nullptr , T_ILLEGAL, 1, true , _getstatic ) \ 258 def(_putstatic , "putstatic" , "bJJ" , nullptr , T_ILLEGAL, -1, true , _putstatic ) \ 259 def(_getfield , "getfield" , "bJJ" , nullptr , T_ILLEGAL, 0, true , _getfield ) \ 260 def(_putfield , "putfield" , "bJJ" , nullptr , T_ILLEGAL, -2, true , _putfield ) \ 261 def(_invokevirtual , "invokevirtual" , "bJJ" , nullptr , T_ILLEGAL, -1, true , _invokevirtual ) \ 262 def(_invokespecial , "invokespecial" , "bJJ" , nullptr , T_ILLEGAL, -1, true , _invokespecial ) \ 263 def(_invokestatic , "invokestatic" , "bJJ" , nullptr , T_ILLEGAL, 0, true , _invokestatic ) \ 264 def(_invokeinterface , "invokeinterface" , "bJJ__", nullptr , T_ILLEGAL, -1, true , _invokeinterface) \ 265 def(_invokedynamic , "invokedynamic" , "bJJJJ", nullptr , T_ILLEGAL, 0, true , _invokedynamic ) \ 266 def(_new , "new" , "bkk" , nullptr , T_OBJECT , 1, true , _new ) \ 267 def(_newarray , "newarray" , "bc" , nullptr , T_OBJECT , 0, true , _newarray ) \ 268 def(_anewarray , "anewarray" , "bkk" , nullptr , T_OBJECT , 0, true , _anewarray ) \ 269 def(_arraylength , "arraylength" , "b" , nullptr , T_INT , 0, true , _arraylength ) \ 270 def(_athrow , "athrow" , "b" , nullptr , T_VOID , -1, true , _athrow ) \ 271 def(_checkcast , "checkcast" , "bkk" , nullptr , T_OBJECT , 0, true , _checkcast ) \ 272 def(_instanceof , "instanceof" , "bkk" , nullptr , T_INT , 0, true , _instanceof ) \ 273 def(_monitorenter , "monitorenter" , "b" , nullptr , T_VOID , -1, true , _monitorenter ) \ 274 def(_monitorexit , "monitorexit" , "b" , nullptr , T_VOID , -1, true , _monitorexit ) \ 275 def(_wide , "wide" , "" , nullptr , T_VOID , 0, false, _wide ) \ 276 def(_multianewarray , "multianewarray" , "bkkc" , nullptr , T_OBJECT , 1, true , _multianewarray ) \ 277 def(_ifnull , "ifnull" , "boo" , nullptr , T_VOID , -1, false, _ifnull ) \ 278 def(_ifnonnull , "ifnonnull" , "boo" , nullptr , T_VOID , -1, false, _ifnonnull ) \ 279 def(_goto_w , "goto_w" , "boooo", nullptr , T_VOID , 0, false, _goto_w ) \ 280 def(_jsr_w , "jsr_w" , "boooo", nullptr , T_INT , 0, false, _jsr_w ) \ 281 def(_breakpoint , "breakpoint" , "" , nullptr , T_VOID , 0, true , _breakpoint ) \ 282 JVM_BYTECODES_DO(def) 283 284 bool Bytecodes::_is_initialized = false; 285 286 const char* const Bytecodes::_name[Bytecodes::number_of_codes] = { 287 #define BYTECODE_NAME(code, name, format, wide_format, result_type, depth, can_trap, java_code) name, 288 BYTECODES_DO(BYTECODE_NAME) 289 #undef BYTECODE_NAME 290 }; 291 292 const BasicType Bytecodes::_result_type[Bytecodes::number_of_codes] = { 293 #define BYTECODE_RESULT_TYPE(code, name, format, wide_format, result_type, depth, can_trap, java_code) result_type, 294 BYTECODES_DO(BYTECODE_RESULT_TYPE) 295 #undef BYTECODE_RESULT_TYPE 296 }; 297 298 const s_char Bytecodes::_depth[Bytecodes::number_of_codes] = { 299 #define BYTECODE_DEPTH(code, name, format, wide_format, result_type, depth, can_trap, java_code) depth, 300 BYTECODES_DO(BYTECODE_DEPTH) 301 #undef BYTECODE_DEPTH 302 }; 303 304 // Helper for determining the size (a.k.a. length) of a string literal. 305 struct StringLiteralSize { 306 template <size_t N> 307 static constexpr size_t invoke(const char (&)[N]) { 308 static_assert(N > 0, "N must be greater than 0"); 309 // The size is N - 1, as C strings have an implicit NUL at the end. So "foo" will result in N 310 // being 4, but we actually want 3. 311 return N - 1; 312 } 313 314 static constexpr size_t invoke(std::nullptr_t) { 315 return 0; 316 } 317 }; 318 319 #define STRING_SIZE(string) StringLiteralSize::invoke(string) 320 321 const u_char Bytecodes::_lengths[Bytecodes::number_of_codes] = { 322 #define BYTECODE_LENGTHS(code, name, format, wide_format, result_type, depth, can_trap, java_code) static_cast<u_char>((STRING_SIZE(wide_format) << 4) | (STRING_SIZE(format) & 0xf)), 323 BYTECODES_DO(BYTECODE_LENGTHS) 324 #undef BYTECODE_LENGTHS 325 }; 326 327 const Bytecodes::Code Bytecodes::_java_code[Bytecodes::number_of_codes] = { 328 #define BYTECODE_JAVA_CODE(code, name, format, wide_format, result_type, depth, can_trap, java_code) Bytecodes::java_code, 329 BYTECODES_DO(BYTECODE_JAVA_CODE) 330 #undef BYTECODE_JAVA_CODE 331 }; 332 333 jchar Bytecodes::_flags[(1<<BitsPerByte)*2]; 334 335 #ifdef ASSERT 336 bool Bytecodes::check_method(const Method* method, address bcp) { 337 return method->contains(bcp); 338 } 339 #endif 340 341 bool Bytecodes::check_must_rewrite(Bytecodes::Code code) { 342 assert(can_rewrite(code), "post-check only"); 343 344 // Some codes are conditionally rewriting. Look closely at them. 345 switch (code) { 346 case Bytecodes::_aload_0: 347 // Even if RewriteFrequentPairs is turned on, 348 // the _aload_0 code might delay its rewrite until 349 // a following _getfield rewrites itself. 350 return false; 351 352 case Bytecodes::_lookupswitch: 353 return false; // the rewrite is not done by the interpreter 354 355 case Bytecodes::_new: 356 // (Could actually look at the class here, but the profit would be small.) 357 return false; // the rewrite is not always done 358 359 default: 360 // No other special cases. 361 return true; 362 } 363 } 364 365 Bytecodes::Code Bytecodes::code_at(Method* method, int bci) { 366 return code_at(method, method->bcp_from(bci)); 367 } 368 369 Bytecodes::Code Bytecodes::non_breakpoint_code_at(const Method* method, address bcp) { 370 assert(method != nullptr, "must have the method for breakpoint conversion"); 371 assert(method->contains(bcp), "must be valid bcp in method"); 372 return method->orig_bytecode_at(method->bci_from(bcp)); 373 } 374 375 int Bytecodes::special_length_at(Bytecodes::Code code, address bcp, address end) { 376 switch (code) { 377 case _wide: 378 if (end != nullptr && bcp + 1 >= end) { 379 return -1; // don't read past end of code buffer 380 } 381 return wide_length_for(cast(*(bcp + 1))); 382 case _tableswitch: 383 { address aligned_bcp = align_up(bcp + 1, jintSize); 384 if (end != nullptr && aligned_bcp + 3*jintSize >= end) { 385 return -1; // don't read past end of code buffer 386 } 387 // Promote calculation to signed 64 bits to do range checks, used by the verifier. 388 int64_t lo = (int)Bytes::get_Java_u4(aligned_bcp + 1*jintSize); 389 int64_t hi = (int)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); 390 int64_t len = (aligned_bcp - bcp) + (3 + hi - lo + 1)*jintSize; 391 // Only return len if it can be represented as a positive int and lo <= hi. 392 // The caller checks for bytecode stream overflow. 393 if (lo <= hi && len == (int)len) { 394 assert(len > 0, "must be"); 395 return (int)len; 396 } else { 397 return -1; 398 } 399 } 400 401 case _lookupswitch: // fall through 402 case _fast_binaryswitch: // fall through 403 case _fast_linearswitch: 404 { address aligned_bcp = align_up(bcp + 1, jintSize); 405 if (end != nullptr && aligned_bcp + 2*jintSize >= end) { 406 return -1; // don't read past end of code buffer 407 } 408 // Promote calculation to 64 bits to do range checks, used by the verifier. 409 int64_t npairs = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); 410 int64_t len = (aligned_bcp - bcp) + (2 + 2*npairs)*jintSize; 411 // Only return len if it can be represented as a positive int and npairs >= 0. 412 if (npairs >= 0 && len == (int)len) { 413 assert(len > 0, "must be"); 414 return (int)len; 415 } else { 416 return -1; 417 } 418 } 419 default: 420 // Note: Length functions must return <=0 for invalid bytecodes. 421 return 0; 422 } 423 } 424 425 // At a breakpoint instruction, this returns the breakpoint's length, 426 // otherwise, it's the same as special_length_at(). This is used by 427 // the RawByteCodeStream, which wants to see the actual bytecode 428 // values (including breakpoint). RawByteCodeStream is used by the 429 // verifier when reading in bytecode to verify. Other mechanisms that 430 // run at runtime (such as generateOopMaps) need to iterate over the code 431 // and don't expect to see breakpoints: they want to see the instruction 432 // which was replaced so that they can get the correct length and find 433 // the next bytecode. 434 // 435 // 'end' indicates the end of the code buffer, which we should not try to read 436 // past. 437 int Bytecodes::raw_special_length_at(address bcp, address end) { 438 Code code = code_or_bp_at(bcp); 439 if (code == _breakpoint) { 440 return 1; 441 } else { 442 return special_length_at(code, bcp, end); 443 } 444 } 445 446 void Bytecodes::def_flags(Code code, const char* format, const char* wide_format, bool can_trap, Code java_code) { 447 assert(wide_format == nullptr || format != nullptr, "short form must exist if there's a wide form"); 448 #ifdef ASSERT 449 int len = (format != nullptr ? (int) strlen(format) : 0); 450 int wlen = (wide_format != nullptr ? (int) strlen(wide_format) : 0); 451 #endif 452 jchar bc_flags = 0; 453 if (can_trap) bc_flags |= _bc_can_trap; 454 if (java_code != code) bc_flags |= _bc_can_rewrite; 455 _flags[(u1)code+0*(1<<BitsPerByte)] = compute_flags(format, bc_flags); 456 _flags[(u1)code+1*(1<<BitsPerByte)] = compute_flags(wide_format, bc_flags); 457 assert(is_defined(code) == (format != nullptr), ""); 458 assert(wide_is_defined(code) == (wide_format != nullptr), ""); 459 assert(length_for(code) == len, ""); 460 assert(wide_length_for(code) == wlen, ""); 461 } 462 463 464 // Format strings interpretation: 465 // 466 // b: bytecode 467 // c: signed constant, Java byte-ordering 468 // i: unsigned local index, Java byte-ordering (I = native byte ordering) 469 // j: unsigned CP cache index, Java byte-ordering (J = native byte ordering) 470 // k: unsigned CP index, Java byte-ordering 471 // o: branch offset, Java byte-ordering 472 // _: unused/ignored 473 // w: wide bytecode 474 // 475 // Note: The format strings are used for 2 purposes: 476 // 1. to specify the length of the bytecode 477 // (= number of characters in format string) 478 // 2. to derive bytecode format flags (_fmt_has_k, etc.) 479 // 480 // Note: For bytecodes with variable length, the format string is the empty string. 481 482 jchar Bytecodes::compute_flags(const char* format, jchar more_flags) { 483 if (format == nullptr) return 0; // not even more_flags 484 jchar flags = more_flags; 485 const char* fp = format; 486 switch (*fp) { 487 case '\0': 488 flags |= _fmt_not_simple; // but variable 489 break; 490 case 'b': 491 flags |= _fmt_not_variable; // but simple 492 ++fp; // skip 'b' 493 break; 494 case 'w': 495 flags |= _fmt_not_variable | _fmt_not_simple; 496 ++fp; // skip 'w' 497 guarantee(*fp == 'b', "wide format must start with 'wb'"); 498 ++fp; // skip 'b' 499 break; 500 } 501 502 int has_nbo = 0, has_jbo = 0, has_size = 0; 503 for (;;) { 504 jchar this_flag = 0; 505 char fc = *fp++; 506 switch (fc) { 507 case '\0': // end of string 508 return flags; 509 510 case '_': continue; // ignore these 511 512 case 'j': this_flag = _fmt_has_j; has_jbo = 1; break; 513 case 'k': this_flag = _fmt_has_k; has_jbo = 1; break; 514 case 'i': this_flag = _fmt_has_i; has_jbo = 1; break; 515 case 'c': this_flag = _fmt_has_c; has_jbo = 1; break; 516 case 'o': this_flag = _fmt_has_o; has_jbo = 1; break; 517 518 // uppercase versions mark native byte order (from Rewriter) 519 // actually, only the 'J' case happens currently 520 case 'J': this_flag = _fmt_has_j; has_nbo = 1; break; 521 case 'K': this_flag = _fmt_has_k; has_nbo = 1; break; 522 case 'I': this_flag = _fmt_has_i; has_nbo = 1; break; 523 case 'C': this_flag = _fmt_has_c; has_nbo = 1; break; 524 case 'O': this_flag = _fmt_has_o; has_nbo = 1; break; 525 default: guarantee(false, "bad char in format"); 526 } 527 528 flags |= this_flag; 529 530 guarantee(!(has_jbo && has_nbo), "mixed byte orders in format"); 531 if (has_nbo) 532 flags |= _fmt_has_nbo; 533 534 int this_size = 1; 535 if (*fp == fc) { 536 // advance beyond run of the same characters 537 this_size = 2; 538 while (*++fp == fc) this_size++; 539 switch (this_size) { 540 case 2: flags |= _fmt_has_u2; break; 541 case 4: flags |= _fmt_has_u4; break; 542 default: guarantee(false, "bad rep count in format"); 543 } 544 } 545 guarantee(has_size == 0 || // no field yet 546 this_size == has_size || // same size 547 (this_size < has_size && *fp == '\0'), // last field can be short 548 "mixed field sizes in format"); 549 has_size = this_size; 550 } 551 } 552 553 void Bytecodes::initialize() { 554 if (_is_initialized) return; 555 556 // initialize bytecode tables - didn't use static array initializers 557 // (such as {}) so we can do additional consistency checks and init- 558 // code is independent of actual bytecode numbering. 559 // 560 // Note 1: The result type is T_ILLEGAL for bytecodes where the top of stack 561 // type after execution is not only determined by the bytecode itself. 562 563 #define BYTECODE(code, name, format, wide_format, result_type, depth, can_trap, java_code) \ 564 assert(strcmp(_name[code], name) == 0, "bytecode name mismatch"); \ 565 assert(_result_type[code] == result_type, "bytecode result_type mismatch"); \ 566 assert(_depth[code] == depth, "bytecode depth mismatch"); \ 567 assert(_lengths[code] == ((STRING_SIZE(wide_format) << 4) | (STRING_SIZE(format) & 0xF)), \ 568 "bytecode lengths mismatch"); \ 569 assert(_java_code[code] == java_code, "bytecode java_code mismatch"); \ 570 def_flags(code, format, wide_format, can_trap, java_code); 571 BYTECODES_DO(BYTECODE) 572 #undef BYTECODE 573 574 // compare can_trap information for each bytecode with the 575 // can_trap information for the corresponding base bytecode 576 // (if a rewritten bytecode can trap, so must the base bytecode) 577 #ifdef ASSERT 578 { for (int i = 0; i < number_of_codes; i++) { 579 if (is_defined(i)) { 580 Code code = cast(i); 581 Code java = java_code(code); 582 if (can_trap(code) && !can_trap(java)) 583 fatal("%s can trap => %s can trap, too", name(code), name(java)); 584 } 585 } 586 } 587 #endif 588 589 // initialization successful 590 _is_initialized = true; 591 } 592 593 594 void bytecodes_init() { 595 Bytecodes::initialize(); 596 } 597 598 // Restore optimization 599 #ifdef _M_AMD64 600 #pragma optimize ("", on) 601 #endif