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