1 /*
2  * Copyright (c) 2001, 2018, 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 package sun.jvm.hotspot.interpreter;
26 
27 import java.util.*;
28 import sun.jvm.hotspot.oops.*;
29 import sun.jvm.hotspot.runtime.*;
30 import sun.jvm.hotspot.utilities.*;
31 
32 // Bytecodes specifies all bytecodes used in the VM and
33 // provides utility functions to get bytecode attributes.
34 
35 public class Bytecodes {
36   public static final int _illegal    =  -1;
37 
38   // Java bytecodes
39   public static final int _nop                  =   0; // 0x00
40   public static final int _aconst_null          =   1; // 0x01
41   public static final int _iconst_m1            =   2; // 0x02
42   public static final int _iconst_0             =   3; // 0x03
43   public static final int _iconst_1             =   4; // 0x04
44   public static final int _iconst_2             =   5; // 0x05
45   public static final int _iconst_3             =   6; // 0x06
46   public static final int _iconst_4             =   7; // 0x07
47   public static final int _iconst_5             =   8; // 0x08
48   public static final int _lconst_0             =   9; // 0x09
49   public static final int _lconst_1             =  10; // 0x0a
50   public static final int _fconst_0             =  11; // 0x0b
51   public static final int _fconst_1             =  12; // 0x0c
52   public static final int _fconst_2             =  13; // 0x0d
53   public static final int _dconst_0             =  14; // 0x0e
54   public static final int _dconst_1             =  15; // 0x0f
55   public static final int _bipush               =  16; // 0x10
56   public static final int _sipush               =  17; // 0x11
57   public static final int _ldc                  =  18; // 0x12
58   public static final int _ldc_w                =  19; // 0x13
59   public static final int _ldc2_w               =  20; // 0x14
60   public static final int _iload                =  21; // 0x15
61   public static final int _lload                =  22; // 0x16
62   public static final int _fload                =  23; // 0x17
63   public static final int _dload                =  24; // 0x18
64   public static final int _aload                =  25; // 0x19
65   public static final int _iload_0              =  26; // 0x1a
66   public static final int _iload_1              =  27; // 0x1b
67   public static final int _iload_2              =  28; // 0x1c
68   public static final int _iload_3              =  29; // 0x1d
69   public static final int _lload_0              =  30; // 0x1e
70   public static final int _lload_1              =  31; // 0x1f
71   public static final int _lload_2              =  32; // 0x20
72   public static final int _lload_3              =  33; // 0x21
73   public static final int _fload_0              =  34; // 0x22
74   public static final int _fload_1              =  35; // 0x23
75   public static final int _fload_2              =  36; // 0x24
76   public static final int _fload_3              =  37; // 0x25
77   public static final int _dload_0              =  38; // 0x26
78   public static final int _dload_1              =  39; // 0x27
79   public static final int _dload_2              =  40; // 0x28
80   public static final int _dload_3              =  41; // 0x29
81   public static final int _aload_0              =  42; // 0x2a
82   public static final int _aload_1              =  43; // 0x2b
83   public static final int _aload_2              =  44; // 0x2c
84   public static final int _aload_3              =  45; // 0x2d
85   public static final int _iaload               =  46; // 0x2e
86   public static final int _laload               =  47; // 0x2f
87   public static final int _faload               =  48; // 0x30
88   public static final int _daload               =  49; // 0x31
89   public static final int _aaload               =  50; // 0x32
90   public static final int _baload               =  51; // 0x33
91   public static final int _caload               =  52; // 0x34
92   public static final int _saload               =  53; // 0x35
93   public static final int _istore               =  54; // 0x36
94   public static final int _lstore               =  55; // 0x37
95   public static final int _fstore               =  56; // 0x38
96   public static final int _dstore               =  57; // 0x39
97   public static final int _astore               =  58; // 0x3a
98   public static final int _istore_0             =  59; // 0x3b
99   public static final int _istore_1             =  60; // 0x3c
100   public static final int _istore_2             =  61; // 0x3d
101   public static final int _istore_3             =  62; // 0x3e
102   public static final int _lstore_0             =  63; // 0x3f
103   public static final int _lstore_1             =  64; // 0x40
104   public static final int _lstore_2             =  65; // 0x41
105   public static final int _lstore_3             =  66; // 0x42
106   public static final int _fstore_0             =  67; // 0x43
107   public static final int _fstore_1             =  68; // 0x44
108   public static final int _fstore_2             =  69; // 0x45
109   public static final int _fstore_3             =  70; // 0x46
110   public static final int _dstore_0             =  71; // 0x47
111   public static final int _dstore_1             =  72; // 0x48
112   public static final int _dstore_2             =  73; // 0x49
113   public static final int _dstore_3             =  74; // 0x4a
114   public static final int _astore_0             =  75; // 0x4b
115   public static final int _astore_1             =  76; // 0x4c
116   public static final int _astore_2             =  77; // 0x4d
117   public static final int _astore_3             =  78; // 0x4e
118   public static final int _iastore              =  79; // 0x4f
119   public static final int _lastore              =  80; // 0x50
120   public static final int _fastore              =  81; // 0x51
121   public static final int _dastore              =  82; // 0x52
122   public static final int _aastore              =  83; // 0x53
123   public static final int _bastore              =  84; // 0x54
124   public static final int _castore              =  85; // 0x55
125   public static final int _sastore              =  86; // 0x56
126   public static final int _pop                  =  87; // 0x57
127   public static final int _pop2                 =  88; // 0x58
128   public static final int _dup                  =  89; // 0x59
129   public static final int _dup_x1               =  90; // 0x5a
130   public static final int _dup_x2               =  91; // 0x5b
131   public static final int _dup2                 =  92; // 0x5c
132   public static final int _dup2_x1              =  93; // 0x5d
133   public static final int _dup2_x2              =  94; // 0x5e
134   public static final int _swap                 =  95; // 0x5f
135   public static final int _iadd                 =  96; // 0x60
136   public static final int _ladd                 =  97; // 0x61
137   public static final int _fadd                 =  98; // 0x62
138   public static final int _dadd                 =  99; // 0x63
139   public static final int _isub                 = 100; // 0x64
140   public static final int _lsub                 = 101; // 0x65
141   public static final int _fsub                 = 102; // 0x66
142   public static final int _dsub                 = 103; // 0x67
143   public static final int _imul                 = 104; // 0x68
144   public static final int _lmul                 = 105; // 0x69
145   public static final int _fmul                 = 106; // 0x6a
146   public static final int _dmul                 = 107; // 0x6b
147   public static final int _idiv                 = 108; // 0x6c
148   public static final int _ldiv                 = 109; // 0x6d
149   public static final int _fdiv                 = 110; // 0x6e
150   public static final int _ddiv                 = 111; // 0x6f
151   public static final int _irem                 = 112; // 0x70
152   public static final int _lrem                 = 113; // 0x71
153   public static final int _frem                 = 114; // 0x72
154   public static final int _drem                 = 115; // 0x73
155   public static final int _ineg                 = 116; // 0x74
156   public static final int _lneg                 = 117; // 0x75
157   public static final int _fneg                 = 118; // 0x76
158   public static final int _dneg                 = 119; // 0x77
159   public static final int _ishl                 = 120; // 0x78
160   public static final int _lshl                 = 121; // 0x79
161   public static final int _ishr                 = 122; // 0x7a
162   public static final int _lshr                 = 123; // 0x7b
163   public static final int _iushr                = 124; // 0x7c
164   public static final int _lushr                = 125; // 0x7d
165   public static final int _iand                 = 126; // 0x7e
166   public static final int _land                 = 127; // 0x7f
167   public static final int _ior                  = 128; // 0x80
168   public static final int _lor                  = 129; // 0x81
169   public static final int _ixor                 = 130; // 0x82
170   public static final int _lxor                 = 131; // 0x83
171   public static final int _iinc                 = 132; // 0x84
172   public static final int _i2l                  = 133; // 0x85
173   public static final int _i2f                  = 134; // 0x86
174   public static final int _i2d                  = 135; // 0x87
175   public static final int _l2i                  = 136; // 0x88
176   public static final int _l2f                  = 137; // 0x89
177   public static final int _l2d                  = 138; // 0x8a
178   public static final int _f2i                  = 139; // 0x8b
179   public static final int _f2l                  = 140; // 0x8c
180   public static final int _f2d                  = 141; // 0x8d
181   public static final int _d2i                  = 142; // 0x8e
182   public static final int _d2l                  = 143; // 0x8f
183   public static final int _d2f                  = 144; // 0x90
184   public static final int _i2b                  = 145; // 0x91
185   public static final int _i2c                  = 146; // 0x92
186   public static final int _i2s                  = 147; // 0x93
187   public static final int _lcmp                 = 148; // 0x94
188   public static final int _fcmpl                = 149; // 0x95
189   public static final int _fcmpg                = 150; // 0x96
190   public static final int _dcmpl                = 151; // 0x97
191   public static final int _dcmpg                = 152; // 0x98
192   public static final int _ifeq                 = 153; // 0x99
193   public static final int _ifne                 = 154; // 0x9a
194   public static final int _iflt                 = 155; // 0x9b
195   public static final int _ifge                 = 156; // 0x9c
196   public static final int _ifgt                 = 157; // 0x9d
197   public static final int _ifle                 = 158; // 0x9e
198   public static final int _if_icmpeq            = 159; // 0x9f
199   public static final int _if_icmpne            = 160; // 0xa0
200   public static final int _if_icmplt            = 161; // 0xa1
201   public static final int _if_icmpge            = 162; // 0xa2
202   public static final int _if_icmpgt            = 163; // 0xa3
203   public static final int _if_icmple            = 164; // 0xa4
204   public static final int _if_acmpeq            = 165; // 0xa5
205   public static final int _if_acmpne            = 166; // 0xa6
206   public static final int _goto                 = 167; // 0xa7
207   public static final int _jsr                  = 168; // 0xa8
208   public static final int _ret                  = 169; // 0xa9
209   public static final int _tableswitch          = 170; // 0xaa
210   public static final int _lookupswitch         = 171; // 0xab
211   public static final int _ireturn              = 172; // 0xac
212   public static final int _lreturn              = 173; // 0xad
213   public static final int _freturn              = 174; // 0xae
214   public static final int _dreturn              = 175; // 0xaf
215   public static final int _areturn              = 176; // 0xb0
216   public static final int _return               = 177; // 0xb1
217   public static final int _getstatic            = 178; // 0xb2
218   public static final int _putstatic            = 179; // 0xb3
219   public static final int _getfield             = 180; // 0xb4
220   public static final int _putfield             = 181; // 0xb5
221   public static final int _invokevirtual        = 182; // 0xb6
222   public static final int _invokespecial        = 183; // 0xb7
223   public static final int _invokestatic         = 184; // 0xb8
224   public static final int _invokeinterface      = 185; // 0xb9
225   public static final int _invokedynamic        = 186; // 0xba
226   public static final int _new                  = 187; // 0xbb
227   public static final int _newarray             = 188; // 0xbc
228   public static final int _anewarray            = 189; // 0xbd
229   public static final int _arraylength          = 190; // 0xbe
230   public static final int _athrow               = 191; // 0xbf
231   public static final int _checkcast            = 192; // 0xc0
232   public static final int _instanceof           = 193; // 0xc1
233   public static final int _monitorenter         = 194; // 0xc2
234   public static final int _monitorexit          = 195; // 0xc3
235   public static final int _wide                 = 196; // 0xc4
236   public static final int _multianewarray       = 197; // 0xc5
237   public static final int _ifnull               = 198; // 0xc6
238   public static final int _ifnonnull            = 199; // 0xc7
239   public static final int _goto_w               = 200; // 0xc8
240   public static final int _jsr_w                = 201; // 0xc9
241   public static final int _breakpoint           = 202; // 0xca
242 
243   public static final int number_of_java_codes  = 203;
244 
245   // JVM bytecodes
246   public static final int _fast_agetfield       = number_of_java_codes;
247   public static final int _fast_bgetfield       = 204;
248   public static final int _fast_cgetfield       = 205;
249   public static final int _fast_dgetfield       = 206;
250   public static final int _fast_fgetfield       = 207;
251   public static final int _fast_igetfield       = 208;
252   public static final int _fast_lgetfield       = 209;
253   public static final int _fast_sgetfield       = 210;
254   public static final int _fast_aputfield       = 211;
255   public static final int _fast_bputfield       = 212;
256   public static final int _fast_zputfield       = 213;
257   public static final int _fast_cputfield       = 214;
258   public static final int _fast_dputfield       = 215;
259   public static final int _fast_fputfield       = 216;
260   public static final int _fast_iputfield       = 217;
261   public static final int _fast_lputfield       = 218;
262   public static final int _fast_sputfield       = 219;
263   public static final int _fast_aload_0         = 220;
264   public static final int _fast_iaccess_0       = 221;
265   public static final int _fast_aaccess_0       = 222;
266   public static final int _fast_faccess_0       = 223;
267   public static final int _fast_iload           = 224;
268   public static final int _fast_iload2          = 225;
269   public static final int _fast_icaload         = 226;
270   public static final int _fast_invokevfinal    = 227;
271   public static final int _fast_linearswitch    = 228;
272   public static final int _fast_binaryswitch    = 229;
273   public static final int _fast_aldc            = 230;
274   public static final int _fast_aldc_w          = 231;
275   public static final int _return_register_finalizer = 232;
276   public static final int _invokehandle         = 233;
277 
278   // Bytecodes rewritten at CDS dump time
279   public static final int _nofast_getfield      = 234;
280   public static final int _nofast_putfield      = 235;
281   public static final int _nofast_aload_0       = 236;
282   public static final int _nofast_iload         = 237;
283   public static final int _shouldnotreachhere   = 238; // For debugging
284 
285   public static final int number_of_codes       = 239;
286 
287   // Flag bits derived from format strings, can_trap, can_rewrite, etc.:
288   // semantic flags:
289   static final int  _bc_can_trap      = 1<<0;     // bytecode execution can trap or block
290   static final int  _bc_can_rewrite   = 1<<1;     // bytecode execution has an alternate form
291 
292   // format bits (determined only by the format string):
293   static final int  _fmt_has_c        = 1<<2;     // constant, such as sipush "bcc"
294   static final int  _fmt_has_j        = 1<<3;     // constant pool cache index, such as getfield "bjj"
295   static final int  _fmt_has_k        = 1<<4;     // constant pool index, such as ldc "bk"
296   static final int  _fmt_has_i        = 1<<5;     // local index, such as iload
297   static final int  _fmt_has_o        = 1<<6;     // offset, such as ifeq
298   static final int  _fmt_has_nbo      = 1<<7;     // contains native-order field(s)
299   static final int  _fmt_has_u2       = 1<<8;     // contains double-byte field(s)
300   static final int  _fmt_has_u4       = 1<<9;     // contains quad-byte field
301   static final int  _fmt_not_variable = 1<<10;    // not of variable length (simple or wide)
302   static final int  _fmt_not_simple   = 1<<11;    // either wide or variable length
303   static final int  _all_fmt_bits     = (_fmt_not_simple*2 - _fmt_has_c);
304 
305   // Example derived format syndromes:
306   static final int  _fmt_b      = _fmt_not_variable;
307   static final int  _fmt_bc     = _fmt_b | _fmt_has_c;
308   static final int  _fmt_bi     = _fmt_b | _fmt_has_i;
309   static final int  _fmt_bkk    = _fmt_b | _fmt_has_k | _fmt_has_u2;
310   static final int  _fmt_bJJ    = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo;
311   static final int  _fmt_bo2    = _fmt_b | _fmt_has_o | _fmt_has_u2;
312   static final int  _fmt_bo4    = _fmt_b | _fmt_has_o | _fmt_has_u4;
313 
314 
specialLengthAt(Method method, int bci)315   public static int specialLengthAt(Method method, int bci) {
316     int code = codeAt(method, bci);
317     switch (code) {
318     case _wide:
319       return wideLengthFor(method.getBytecodeOrBPAt(bci + 1));
320     case _tableswitch:
321       {
322         int alignedBCI = Bits.roundTo(bci + 1, jintSize);
323         int lo = method.getBytecodeIntArg(alignedBCI + 1*jintSize);
324         int hi = method.getBytecodeIntArg(alignedBCI + 2*jintSize);
325         return (alignedBCI - bci) + (3 + hi - lo + 1)*jintSize;
326       }
327 
328     case _lookupswitch:      // fall through
329     case _fast_binaryswitch: // fall through
330     case _fast_linearswitch:
331       {
332         int alignedBCI = Bits.roundTo(bci + 1, jintSize);
333         int npairs = method.getBytecodeIntArg(alignedBCI + jintSize);
334         return (alignedBCI - bci) + (2 + 2*npairs)*jintSize;
335       }
336 
337     }
338     throw new RuntimeException("should not reach here");
339   }
340 
341   // Conversion
check(int code)342   public static void check(int code) {
343     if (Assert.ASSERTS_ENABLED) {
344       Assert.that(isDefined(code), "illegal code " + code);
345     }
346   }
wideCheck(int code)347   public static void wideCheck(int code) {
348     if (Assert.ASSERTS_ENABLED) {
349       Assert.that(wideIsDefined(code), "illegal code " + code);
350     }
351   }
352 
353   /** Fetches a bytecode, hiding breakpoints as necessary */
codeAt(Method method, int bci)354   public static int codeAt(Method method, int bci) {
355     int res = codeOrBPAt(method, bci);
356     if (res == _breakpoint) {
357       res = method.getOrigBytecodeAt(bci);
358     }
359     return res;
360   }
361 
362   /** Fetches a bytecode or a breakpoint */
codeOrBPAt(Method method, int bci)363   public static int codeOrBPAt(Method method, int bci) {
364     return method.getBytecodeOrBPAt(bci);
365   }
366 
isActiveBreakpointAt(Method method, int bci)367   public static boolean isActiveBreakpointAt(Method method, int bci) {
368     return (codeOrBPAt(method, bci) == _breakpoint);
369   }
370 
371   // find a bytecode, behind a breakpoint if necessary:
372   // FIXME: not yet implementable
373   //   static Code       non_breakpoint_code_at(address bcp, Method* method = null);
374 
375   // Bytecode attributes
isDefined(int code)376   public static boolean   isDefined    (int code) { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
wideIsDefined(int code)377   public static boolean   wideIsDefined(int code) { return isDefined(code) && flags(code, true) != 0; }
name(int code)378   public static String    name         (int code) { check(code);      return _name          [code]; }
format(int code)379   public static String    format       (int code) { check(code);      return _format        [code]; }
wideFormat(int code)380   public static String    wideFormat   (int code) { wideCheck(code);  return _wide_format   [code]; }
resultType(int code)381   public static int       resultType   (int code) { check(code);      return _result_type   [code]; }
depth(int code)382   public static int       depth        (int code) { check(code);      return _depth         [code]; }
lengthFor(int code)383   public static int       lengthFor    (int code) { check(code);      return _lengths       [code] & 0xF; }
wideLengthFor(int code)384   public static int       wideLengthFor(int code) { check(code);      return _lengths       [code] >> 4; }
canTrap(int code)385   public static boolean   canTrap      (int code) { check(code);      return has_all_flags(code, _bc_can_trap, false); }
javaCode(int code)386   public static int       javaCode     (int code) { check(code);      return _java_code     [code]; }
canRewrite(int code)387   public static boolean   canRewrite   (int code) { check(code);      return has_all_flags(code, _bc_can_rewrite, false); }
native_byte_order(int code)388   public static boolean   native_byte_order(int code)  { check(code);      return has_all_flags(code, _fmt_has_nbo, false); }
uses_cp_cache(int code)389   public static boolean   uses_cp_cache  (int code)    { check(code);      return has_all_flags(code, _fmt_has_j, false); }
lengthAt(Method method, int bci)390   public static int       lengthAt     (Method method, int bci) { int l = lengthFor(codeAt(method, bci)); return l > 0 ? l : specialLengthAt(method, bci); }
javaLengthAt(Method method, int bci)391   public static int       javaLengthAt (Method method, int bci) { int l = lengthFor(javaCode(codeAt(method, bci))); return l > 0 ? l : specialLengthAt(method, bci); }
isJavaCode(int code)392   public static boolean   isJavaCode   (int code) { return 0 <= code && code < number_of_java_codes; }
isFastCode(int code)393   public static boolean   isFastCode   (int code) { return number_of_java_codes <= code && code < number_of_codes; }
394 
isAload(int code)395   public static boolean   isAload      (int code) { return (code == _aload  || code == _aload_0  || code == _aload_1
396                                                                             || code == _aload_2  || code == _aload_3); }
isAstore(int code)397   public static boolean   isAstore     (int code) { return (code == _astore || code == _astore_0 || code == _astore_1
398                                                                             || code == _astore_2 || code == _astore_3); }
399 
isZeroConst(int code)400   public static boolean   isZeroConst  (int code) { return (code == _aconst_null || code == _iconst_0
401                                                                                  || code == _fconst_0 || code == _dconst_0); }
402 
flags(int code, boolean is_wide)403   static int         flags          (int code, boolean is_wide) {
404     assert code == (code & 0xff) : "must be a byte";
405     return _flags[code + (is_wide ? 256 : 0)];
406   }
format_bits(int code, boolean is_wide)407   static int         format_bits    (int code, boolean is_wide) { return flags(code, is_wide) & _all_fmt_bits; }
has_all_flags(int code, int test_flags, boolean is_wide)408   static boolean     has_all_flags  (int code, int test_flags, boolean is_wide) {
409     return (flags(code, is_wide) & test_flags) == test_flags;
410   }
411 
compute_flags(String format)412   static char compute_flags(String format) {
413     return compute_flags(format, 0);
414   }
compute_flags(String format, int more_flags)415   static char compute_flags(String format, int more_flags) {
416     if (format == null)  return 0;  // not even more_flags
417     int flags = more_flags;
418     int fp = 0;
419     if (format.length() == 0) {
420       flags |= _fmt_not_simple; // but variable
421     } else {
422       switch (format.charAt(fp)) {
423       case 'b':
424         flags |= _fmt_not_variable;  // but simple
425         ++fp;  // skip 'b'
426         break;
427       case 'w':
428         flags |= _fmt_not_variable | _fmt_not_simple;
429         ++fp;  // skip 'w'
430       assert(format.charAt(fp) == 'b') : "wide format must start with 'wb'";
431         ++fp;  // skip 'b'
432         break;
433       }
434     }
435 
436     boolean has_nbo = false, has_jbo = false;
437     int has_size = 0;
438     while (fp < format.length()) {
439       int this_flag = 0;
440       char fc = format.charAt(fp++);
441       switch (fc) {
442       case '_': continue;         // ignore these
443 
444       case 'j': this_flag = _fmt_has_j; has_jbo = true; break;
445       case 'k': this_flag = _fmt_has_k; has_jbo = true; break;
446       case 'i': this_flag = _fmt_has_i; has_jbo = true; break;
447       case 'c': this_flag = _fmt_has_c; has_jbo = true; break;
448       case 'o': this_flag = _fmt_has_o; has_jbo = true; break;
449 
450         // uppercase versions mark native byte order (from Rewriter)
451         // actually, only the 'J' case happens currently
452       case 'J': this_flag = _fmt_has_j; has_nbo = true; break;
453       case 'K': this_flag = _fmt_has_k; has_nbo = true; break;
454       case 'I': this_flag = _fmt_has_i; has_nbo = true; break;
455       case 'C': this_flag = _fmt_has_c; has_nbo = true; break;
456       case 'O': this_flag = _fmt_has_o; has_nbo = true; break;
457       default:  assert false : "bad char in format";
458       }
459 
460       flags |= this_flag;
461 
462       assert !(has_jbo && has_nbo) : "mixed byte orders in format";
463       if (has_nbo)
464         flags |= _fmt_has_nbo;
465 
466       int this_size = 1;
467       if (fp < format.length() && format.charAt(fp) == fc) {
468         // advance beyond run of the same characters
469         this_size = 2;
470         while (fp  + 1 < format.length() && format.charAt(++fp) == fc)  this_size++;
471         switch (this_size) {
472         case 2: flags |= _fmt_has_u2; break;
473         case 4: flags |= _fmt_has_u4; break;
474         default: assert false : "bad rep count in format";
475         }
476       }
477       assert has_size == 0 ||                     // no field yet
478         this_size == has_size ||             // same size
479         this_size < has_size && fp == format.length() : // last field can be short
480              "mixed field sizes in format";
481       has_size = this_size;
482     }
483 
484     assert flags == (char)flags : "change _format_flags";
485     return (char)flags;
486   }
487 
488 
489   //----------------------------------------------------------------------
490   // Internals only below this point
491   //
492 
493   private static String[]    _name;
494   private static String[]    _format;
495   private static String[]    _wide_format;
496   private static int[]       _result_type;
497   private static byte[]      _depth;
498   private static byte[]      _lengths;
499   private static int[]       _java_code;
500   private static char[]      _flags;
501 
502   static {
503     _name           = new String [number_of_codes];
504     _format         = new String [number_of_codes];
505     _wide_format    = new String [number_of_codes];
506     _result_type    = new int    [number_of_codes]; // See BasicType.java
507     _depth          = new byte   [number_of_codes];
508     _lengths        = new byte   [number_of_codes];
509     _java_code      = new int    [number_of_codes];
510     _flags          = new char[256 * 2]; // all second page for wide formats
511 
512     // In case we want to fetch this information from the VM in the
513     // future
514     VM.registerVMInitializedObserver(new Observer() {
515         public void update(Observable o, Object data) {
516           initialize();
517         }
518       });
519   }
520 
521   private static final int jintSize    =   4;
522 
523   //  private static String[]    _name           = new String [number_of_codes];
524   //  private static String[]    _format         = new String [number_of_codes];
525   //  private static String[]    _wide_format    = new String [number_of_codes];
526   //  private static int[]       _result_type    = new int    [number_of_codes]; // See BasicType.java
527   //  private static byte[]      _depth          = new byte   [number_of_codes];
528   //  private static byte[]      _length         = new byte   [number_of_codes];
529   //  private static boolean[]   _can_trap       = new boolean[number_of_codes];
530   //  private static int[]       _java_code      = new int    [number_of_codes];
531   //  private static boolean[]   _can_rewrite    = new boolean[number_of_codes];
532 
533   // Initialization
534   private static void initialize() {
535     if (Assert.ASSERTS_ENABLED) {
536       Assert.that(number_of_codes <= 256, "too many bytecodes");
537     }
538 
539     // Format strings interpretation:
540     //
541     // b: bytecode
542     // c: signed constant, Java byte-ordering
543     // i: unsigned index , Java byte-ordering
544     // j: unsigned index , native byte-ordering
545     // o: branch offset  , Java byte-ordering
546     // _: unused/ignored
547     // w: wide bytecode
548     //
549     // Note: Right now the format strings are used for 2 purposes:
550     //       1. to specify the length of the bytecode
551     //          (= number of characters in format string)
552     //       2. to specify the bytecode attributes
553     //
554     //       The bytecode attributes are currently used only for bytecode tracing
555     //       (see BytecodeTracer); thus if more specific format information is
556     //       used, one would also have to adjust the bytecode tracer.
557     //
558     // Note: For bytecodes with variable length, the format string is the empty string.
559 
560     // Note 1: null for the format string means the bytecode doesn't exist
561     //         in that form.
562     //
563     // Note 2: The result type is T_ILLEGAL for bytecodes where the top of stack
564     //         type after execution is not only determined by the bytecode itself.
565 
566     //  Java bytecodes
567     //  bytecode               bytecode name           format   wide f.   result tp                stk traps
568     def(_nop                 , "nop"                 , "b"    , null    , BasicType.getTVoid()   ,  0, false);
569     def(_aconst_null         , "aconst_null"         , "b"    , null    , BasicType.getTObject() ,  1, false);
570     def(_iconst_m1           , "iconst_m1"           , "b"    , null    , BasicType.getTInt()    ,  1, false);
571     def(_iconst_0            , "iconst_0"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
572     def(_iconst_1            , "iconst_1"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
573     def(_iconst_2            , "iconst_2"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
574     def(_iconst_3            , "iconst_3"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
575     def(_iconst_4            , "iconst_4"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
576     def(_iconst_5            , "iconst_5"            , "b"    , null    , BasicType.getTInt()    ,  1, false);
577     def(_lconst_0            , "lconst_0"            , "b"    , null    , BasicType.getTLong()   ,  2, false);
578     def(_lconst_1            , "lconst_1"            , "b"    , null    , BasicType.getTLong()   ,  2, false);
579     def(_fconst_0            , "fconst_0"            , "b"    , null    , BasicType.getTFloat()  ,  1, false);
580     def(_fconst_1            , "fconst_1"            , "b"    , null    , BasicType.getTFloat()  ,  1, false);
581     def(_fconst_2            , "fconst_2"            , "b"    , null    , BasicType.getTFloat()  ,  1, false);
582     def(_dconst_0            , "dconst_0"            , "b"    , null    , BasicType.getTDouble() ,  2, false);
583     def(_dconst_1            , "dconst_1"            , "b"    , null    , BasicType.getTDouble() ,  2, false);
584     def(_bipush              , "bipush"              , "bc"   , null    , BasicType.getTInt()    ,  1, false);
585     def(_sipush              , "sipush"              , "bcc"  , null    , BasicType.getTInt()    ,  1, false);
586     def(_ldc                 , "ldc"                 , "bk"   , null    , BasicType.getTIllegal(),  1, true );
587     def(_ldc_w               , "ldc_w"               , "bkk"  , null    , BasicType.getTIllegal(),  1, true );
588     def(_ldc2_w              , "ldc2_w"              , "bkk"  , null    , BasicType.getTIllegal(),  2, true );
589     def(_iload               , "iload"               , "bi"   , "wbii"  , BasicType.getTInt()    ,  1, false);
590     def(_lload               , "lload"               , "bi"   , "wbii"  , BasicType.getTLong()   ,  2, false);
591     def(_fload               , "fload"               , "bi"   , "wbii"  , BasicType.getTFloat()  ,  1, false);
592     def(_dload               , "dload"               , "bi"   , "wbii"  , BasicType.getTDouble() ,  2, false);
593     def(_aload               , "aload"               , "bi"   , "wbii"  , BasicType.getTObject() ,  1, false);
594     def(_iload_0             , "iload_0"             , "b"    , null    , BasicType.getTInt()    ,  1, false);
595     def(_iload_1             , "iload_1"             , "b"    , null    , BasicType.getTInt()    ,  1, false);
596     def(_iload_2             , "iload_2"             , "b"    , null    , BasicType.getTInt()    ,  1, false);
597     def(_iload_3             , "iload_3"             , "b"    , null    , BasicType.getTInt()    ,  1, false);
598     def(_lload_0             , "lload_0"             , "b"    , null    , BasicType.getTLong()   ,  2, false);
599     def(_lload_1             , "lload_1"             , "b"    , null    , BasicType.getTLong()   ,  2, false);
600     def(_lload_2             , "lload_2"             , "b"    , null    , BasicType.getTLong()   ,  2, false);
601     def(_lload_3             , "lload_3"             , "b"    , null    , BasicType.getTLong()   ,  2, false);
602     def(_fload_0             , "fload_0"             , "b"    , null    , BasicType.getTFloat()  ,  1, false);
603     def(_fload_1             , "fload_1"             , "b"    , null    , BasicType.getTFloat()  ,  1, false);
604     def(_fload_2             , "fload_2"             , "b"    , null    , BasicType.getTFloat()  ,  1, false);
605     def(_fload_3             , "fload_3"             , "b"    , null    , BasicType.getTFloat()  ,  1, false);
606     def(_dload_0             , "dload_0"             , "b"    , null    , BasicType.getTDouble() ,  2, false);
607     def(_dload_1             , "dload_1"             , "b"    , null    , BasicType.getTDouble() ,  2, false);
608     def(_dload_2             , "dload_2"             , "b"    , null    , BasicType.getTDouble() ,  2, false);
609     def(_dload_3             , "dload_3"             , "b"    , null    , BasicType.getTDouble() ,  2, false);
610     def(_aload_0             , "aload_0"             , "b"    , null    , BasicType.getTObject() ,  1, true ); // rewriting in interpreter
611     def(_aload_1             , "aload_1"             , "b"    , null    , BasicType.getTObject() ,  1, false);
612     def(_aload_2             , "aload_2"             , "b"    , null    , BasicType.getTObject() ,  1, false);
613     def(_aload_3             , "aload_3"             , "b"    , null    , BasicType.getTObject() ,  1, false);
614     def(_iaload              , "iaload"              , "b"    , null    , BasicType.getTInt()    , -1, true );
615     def(_laload              , "laload"              , "b"    , null    , BasicType.getTLong()   ,  0, true );
616     def(_faload              , "faload"              , "b"    , null    , BasicType.getTFloat()  , -1, true );
617     def(_daload              , "daload"              , "b"    , null    , BasicType.getTDouble() ,  0, true );
618     def(_aaload              , "aaload"              , "b"    , null    , BasicType.getTObject() , -1, true );
619     def(_baload              , "baload"              , "b"    , null    , BasicType.getTInt()    , -1, true );
620     def(_caload              , "caload"              , "b"    , null    , BasicType.getTInt()    , -1, true );
621     def(_saload              , "saload"              , "b"    , null    , BasicType.getTInt()    , -1, true );
622     def(_istore              , "istore"              , "bi"   , "wbii"  , BasicType.getTVoid()   , -1, false);
623     def(_lstore              , "lstore"              , "bi"   , "wbii"  , BasicType.getTVoid()   , -2, false);
624     def(_fstore              , "fstore"              , "bi"   , "wbii"  , BasicType.getTVoid()   , -1, false);
625     def(_dstore              , "dstore"              , "bi"   , "wbii"  , BasicType.getTVoid()   , -2, false);
626     def(_astore              , "astore"              , "bi"   , "wbii"  , BasicType.getTVoid()   , -1, false);
627     def(_istore_0            , "istore_0"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
628     def(_istore_1            , "istore_1"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
629     def(_istore_2            , "istore_2"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
630     def(_istore_3            , "istore_3"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
631     def(_lstore_0            , "lstore_0"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
632     def(_lstore_1            , "lstore_1"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
633     def(_lstore_2            , "lstore_2"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
634     def(_lstore_3            , "lstore_3"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
635     def(_fstore_0            , "fstore_0"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
636     def(_fstore_1            , "fstore_1"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
637     def(_fstore_2            , "fstore_2"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
638     def(_fstore_3            , "fstore_3"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
639     def(_dstore_0            , "dstore_0"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
640     def(_dstore_1            , "dstore_1"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
641     def(_dstore_2            , "dstore_2"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
642     def(_dstore_3            , "dstore_3"            , "b"    , null    , BasicType.getTVoid()   , -2, false);
643     def(_astore_0            , "astore_0"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
644     def(_astore_1            , "astore_1"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
645     def(_astore_2            , "astore_2"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
646     def(_astore_3            , "astore_3"            , "b"    , null    , BasicType.getTVoid()   , -1, false);
647     def(_iastore             , "iastore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
648     def(_lastore             , "lastore"             , "b"    , null    , BasicType.getTVoid()   , -4, true );
649     def(_fastore             , "fastore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
650     def(_dastore             , "dastore"             , "b"    , null    , BasicType.getTVoid()   , -4, true );
651     def(_aastore             , "aastore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
652     def(_bastore             , "bastore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
653     def(_castore             , "castore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
654     def(_sastore             , "sastore"             , "b"    , null    , BasicType.getTVoid()   , -3, true );
655     def(_pop                 , "pop"                 , "b"    , null    , BasicType.getTVoid()   , -1, false);
656     def(_pop2                , "pop2"                , "b"    , null    , BasicType.getTVoid()   , -2, false);
657     def(_dup                 , "dup"                 , "b"    , null    , BasicType.getTVoid()   ,  1, false);
658     def(_dup_x1              , "dup_x1"              , "b"    , null    , BasicType.getTVoid()   ,  1, false);
659     def(_dup_x2              , "dup_x2"              , "b"    , null    , BasicType.getTVoid()   ,  1, false);
660     def(_dup2                , "dup2"                , "b"    , null    , BasicType.getTVoid()   ,  2, false);
661     def(_dup2_x1             , "dup2_x1"             , "b"    , null    , BasicType.getTVoid()   ,  2, false);
662     def(_dup2_x2             , "dup2_x2"             , "b"    , null    , BasicType.getTVoid()   ,  2, false);
663     def(_swap                , "swap"                , "b"    , null    , BasicType.getTVoid()   ,  0, false);
664     def(_iadd                , "iadd"                , "b"    , null    , BasicType.getTInt()    , -1, false);
665     def(_ladd                , "ladd"                , "b"    , null    , BasicType.getTLong()   , -2, false);
666     def(_fadd                , "fadd"                , "b"    , null    , BasicType.getTFloat()  , -1, false);
667     def(_dadd                , "dadd"                , "b"    , null    , BasicType.getTDouble() , -2, false);
668     def(_isub                , "isub"                , "b"    , null    , BasicType.getTInt()    , -1, false);
669     def(_lsub                , "lsub"                , "b"    , null    , BasicType.getTLong()   , -2, false);
670     def(_fsub                , "fsub"                , "b"    , null    , BasicType.getTFloat()  , -1, false);
671     def(_dsub                , "dsub"                , "b"    , null    , BasicType.getTDouble() , -2, false);
672     def(_imul                , "imul"                , "b"    , null    , BasicType.getTInt()    , -1, false);
673     def(_lmul                , "lmul"                , "b"    , null    , BasicType.getTLong()   , -2, false);
674     def(_fmul                , "fmul"                , "b"    , null    , BasicType.getTFloat()  , -1, false);
675     def(_dmul                , "dmul"                , "b"    , null    , BasicType.getTDouble() , -2, false);
676     def(_idiv                , "idiv"                , "b"    , null    , BasicType.getTInt()    , -1, true );
677     def(_ldiv                , "ldiv"                , "b"    , null    , BasicType.getTLong()   , -2, true );
678     def(_fdiv                , "fdiv"                , "b"    , null    , BasicType.getTFloat()  , -1, false);
679     def(_ddiv                , "ddiv"                , "b"    , null    , BasicType.getTDouble() , -2, false);
680     def(_irem                , "irem"                , "b"    , null    , BasicType.getTInt()    , -1, true );
681     def(_lrem                , "lrem"                , "b"    , null    , BasicType.getTLong()   , -2, true );
682     def(_frem                , "frem"                , "b"    , null    , BasicType.getTFloat()  , -1, false);
683     def(_drem                , "drem"                , "b"    , null    , BasicType.getTDouble() , -2, false);
684     def(_ineg                , "ineg"                , "b"    , null    , BasicType.getTInt()    ,  0, false);
685     def(_lneg                , "lneg"                , "b"    , null    , BasicType.getTLong()   ,  0, false);
686     def(_fneg                , "fneg"                , "b"    , null    , BasicType.getTFloat()  ,  0, false);
687     def(_dneg                , "dneg"                , "b"    , null    , BasicType.getTDouble() ,  0, false);
688     def(_ishl                , "ishl"                , "b"    , null    , BasicType.getTInt()    , -1, false);
689     def(_lshl                , "lshl"                , "b"    , null    , BasicType.getTLong()   , -1, false);
690     def(_ishr                , "ishr"                , "b"    , null    , BasicType.getTInt()    , -1, false);
691     def(_lshr                , "lshr"                , "b"    , null    , BasicType.getTLong()   , -1, false);
692     def(_iushr               , "iushr"               , "b"    , null    , BasicType.getTInt()    , -1, false);
693     def(_lushr               , "lushr"               , "b"    , null    , BasicType.getTLong()   , -1, false);
694     def(_iand                , "iand"                , "b"    , null    , BasicType.getTInt()    , -1, false);
695     def(_land                , "land"                , "b"    , null    , BasicType.getTLong()   , -2, false);
696     def(_ior                 , "ior"                 , "b"    , null    , BasicType.getTInt()    , -1, false);
697     def(_lor                 , "lor"                 , "b"    , null    , BasicType.getTLong()   , -2, false);
698     def(_ixor                , "ixor"                , "b"    , null    , BasicType.getTInt()    , -1, false);
699     def(_lxor                , "lxor"                , "b"    , null    , BasicType.getTLong()   , -2, false);
700     def(_iinc                , "iinc"                , "bic"  , "wbiicc", BasicType.getTVoid()   ,  0, false);
701     def(_i2l                 , "i2l"                 , "b"    , null    , BasicType.getTLong()   ,  1, false);
702     def(_i2f                 , "i2f"                 , "b"    , null    , BasicType.getTFloat()  ,  0, false);
703     def(_i2d                 , "i2d"                 , "b"    , null    , BasicType.getTDouble() ,  1, false);
704     def(_l2i                 , "l2i"                 , "b"    , null    , BasicType.getTInt()    , -1, false);
705     def(_l2f                 , "l2f"                 , "b"    , null    , BasicType.getTFloat()  , -1, false);
706     def(_l2d                 , "l2d"                 , "b"    , null    , BasicType.getTDouble() ,  0, false);
707     def(_f2i                 , "f2i"                 , "b"    , null    , BasicType.getTInt()    ,  0, false);
708     def(_f2l                 , "f2l"                 , "b"    , null    , BasicType.getTLong()   ,  1, false);
709     def(_f2d                 , "f2d"                 , "b"    , null    , BasicType.getTDouble() ,  1, false);
710     def(_d2i                 , "d2i"                 , "b"    , null    , BasicType.getTInt()    , -1, false);
711     def(_d2l                 , "d2l"                 , "b"    , null    , BasicType.getTLong()   ,  0, false);
712     def(_d2f                 , "d2f"                 , "b"    , null    , BasicType.getTFloat()  , -1, false);
713     def(_i2b                 , "i2b"                 , "b"    , null    , BasicType.getTByte()   ,  0, false);
714     def(_i2c                 , "i2c"                 , "b"    , null    , BasicType.getTChar()   ,  0, false);
715     def(_i2s                 , "i2s"                 , "b"    , null    , BasicType.getTShort()  ,  0, false);
716     def(_lcmp                , "lcmp"                , "b"    , null    , BasicType.getTVoid()   , -3, false);
717     def(_fcmpl               , "fcmpl"               , "b"    , null    , BasicType.getTVoid()   , -1, false);
718     def(_fcmpg               , "fcmpg"               , "b"    , null    , BasicType.getTVoid()   , -1, false);
719     def(_dcmpl               , "dcmpl"               , "b"    , null    , BasicType.getTVoid()   , -3, false);
720     def(_dcmpg               , "dcmpg"               , "b"    , null    , BasicType.getTVoid()   , -3, false);
721     def(_ifeq                , "ifeq"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
722     def(_ifne                , "ifne"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
723     def(_iflt                , "iflt"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
724     def(_ifge                , "ifge"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
725     def(_ifgt                , "ifgt"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
726     def(_ifle                , "ifle"                , "boo"  , null    , BasicType.getTVoid()   , -1, false);
727     def(_if_icmpeq           , "if_icmpeq"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
728     def(_if_icmpne           , "if_icmpne"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
729     def(_if_icmplt           , "if_icmplt"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
730     def(_if_icmpge           , "if_icmpge"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
731     def(_if_icmpgt           , "if_icmpgt"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
732     def(_if_icmple           , "if_icmple"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
733     def(_if_acmpeq           , "if_acmpeq"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
734     def(_if_acmpne           , "if_acmpne"           , "boo"  , null    , BasicType.getTVoid()   , -2, false);
735     def(_goto                , "goto"                , "boo"  , null    , BasicType.getTVoid()   ,  0, false);
736     def(_jsr                 , "jsr"                 , "boo"  , null    , BasicType.getTInt()    ,  0, false);
737     def(_ret                 , "ret"                 , "bi"   , "wbii"  , BasicType.getTVoid()   ,  0, false);
738     def(_tableswitch         , "tableswitch"         , ""     , null    , BasicType.getTVoid()   , -1, false); // may have backward branches
739     def(_lookupswitch        , "lookupswitch"        , ""     , null    , BasicType.getTVoid()   , -1, false); // rewriting in interpreter
740     def(_ireturn             , "ireturn"             , "b"    , null    , BasicType.getTInt()    , -1, true );
741     def(_lreturn             , "lreturn"             , "b"    , null    , BasicType.getTLong()   , -2, true );
742     def(_freturn             , "freturn"             , "b"    , null    , BasicType.getTFloat()  , -1, true );
743     def(_dreturn             , "dreturn"             , "b"    , null    , BasicType.getTDouble() , -2, true );
744     def(_areturn             , "areturn"             , "b"    , null    , BasicType.getTObject() , -1, true );
745     def(_return              , "return"              , "b"    , null    , BasicType.getTVoid()   ,  0, true );
746     def(_getstatic           , "getstatic"           , "bJJ"  , null    , BasicType.getTIllegal(),  1, true );
747     def(_putstatic           , "putstatic"           , "bJJ"  , null    , BasicType.getTIllegal(), -1, true );
748     def(_getfield            , "getfield"            , "bJJ"  , null    , BasicType.getTIllegal(),  0, true );
749     def(_putfield            , "putfield"            , "bJJ"  , null    , BasicType.getTIllegal(), -2, true );
750     def(_invokevirtual       , "invokevirtual"       , "bJJ"  , null    , BasicType.getTIllegal(), -1, true );
751     def(_invokespecial       , "invokespecial"       , "bJJ"  , null    , BasicType.getTIllegal(), -1, true );
752     def(_invokestatic        , "invokestatic"        , "bJJ"  , null    , BasicType.getTIllegal(),  0, true );
753     def(_invokeinterface     , "invokeinterface"     , "bJJ__", null    , BasicType.getTIllegal(), -1, true );
754     def(_invokedynamic       , "invokedynamic"       , "bJJJJ", null    , BasicType.getTIllegal(),  0, true );
755     def(_new                 , "new"                 , "bkk"  , null    , BasicType.getTObject() ,  1, true );
756     def(_newarray            , "newarray"            , "bc"   , null    , BasicType.getTObject() ,  0, true );
757     def(_anewarray           , "anewarray"           , "bkk"  , null    , BasicType.getTObject() ,  0, true );
758     def(_arraylength         , "arraylength"         , "b"    , null    , BasicType.getTVoid()   ,  0, true );
759     def(_athrow              , "athrow"              , "b"    , null    , BasicType.getTVoid()   , -1, true );
760     def(_checkcast           , "checkcast"           , "bkk"  , null    , BasicType.getTObject() ,  0, true );
761     def(_instanceof          , "instanceof"          , "bkk"  , null    , BasicType.getTInt()    ,  0, true );
762     def(_monitorenter        , "monitorenter"        , "b"    , null    , BasicType.getTVoid()   , -1, true );
763     def(_monitorexit         , "monitorexit"         , "b"    , null    , BasicType.getTVoid()   , -1, true );
764     def(_wide                , "wide"                , ""     , null    , BasicType.getTVoid()   ,  0, false);
765     def(_multianewarray      , "multianewarray"      , "bkkc" , null    , BasicType.getTObject() ,  1, true );
766     def(_ifnull              , "ifnull"              , "boo"  , null    , BasicType.getTVoid()   , -1, false);
767     def(_ifnonnull           , "ifnonnull"           , "boo"  , null    , BasicType.getTVoid()   , -1, false);
768     def(_goto_w              , "goto_w"              , "boooo", null    , BasicType.getTVoid()   ,  0, false);
769     def(_jsr_w               , "jsr_w"               , "boooo", null    , BasicType.getTInt()    ,  0, false);
770     def(_breakpoint          , "breakpoint"          , ""     , null    , BasicType.getTVoid()   ,  0, true );
771 
772     //  JVM bytecodes
773     //  bytecode               bytecode name           format   wide f.   result tp               stk traps  std code
774 
775     def(_fast_agetfield      , "fast_agetfield"      , "bJJ"  , null    , BasicType.getTObject() ,  0, true , _getfield       );
776     def(_fast_bgetfield      , "fast_bgetfield"      , "bJJ"  , null    , BasicType.getTInt()    ,  0, true , _getfield       );
777     def(_fast_cgetfield      , "fast_cgetfield"      , "bJJ"  , null    , BasicType.getTChar()   ,  0, true , _getfield       );
778     def(_fast_dgetfield      , "fast_dgetfield"      , "bJJ"  , null    , BasicType.getTDouble() ,  0, true , _getfield       );
779     def(_fast_fgetfield      , "fast_fgetfield"      , "bJJ"  , null    , BasicType.getTFloat()  ,  0, true , _getfield       );
780     def(_fast_igetfield      , "fast_igetfield"      , "bJJ"  , null    , BasicType.getTInt()    ,  0, true , _getfield       );
781     def(_fast_lgetfield      , "fast_lgetfield"      , "bJJ"  , null    , BasicType.getTLong()   ,  0, true , _getfield       );
782     def(_fast_sgetfield      , "fast_sgetfield"      , "bJJ"  , null    , BasicType.getTShort()  ,  0, true , _getfield       );
783 
784     def(_fast_aputfield      , "fast_aputfield"      , "bJJ"  , null    , BasicType.getTObject() ,  0, true , _putfield       );
785     def(_fast_bputfield      , "fast_bputfield"      , "bJJ"  , null    , BasicType.getTInt()    ,  0, true , _putfield       );
786     def(_fast_zputfield      , "fast_zputfield"      , "bJJ"  , null    , BasicType.getTInt()    ,  0, true , _putfield       );
787     def(_fast_cputfield      , "fast_cputfield"      , "bJJ"  , null    , BasicType.getTChar()   ,  0, true , _putfield       );
788     def(_fast_dputfield      , "fast_dputfield"      , "bJJ"  , null    , BasicType.getTDouble() ,  0, true , _putfield       );
789     def(_fast_fputfield      , "fast_fputfield"      , "bJJ"  , null    , BasicType.getTFloat()  ,  0, true , _putfield       );
790     def(_fast_iputfield      , "fast_iputfield"      , "bJJ"  , null    , BasicType.getTInt()    ,  0, true , _putfield       );
791     def(_fast_lputfield      , "fast_lputfield"      , "bJJ"  , null    , BasicType.getTLong()   ,  0, true , _putfield       );
792     def(_fast_sputfield      , "fast_sputfield"      , "bJJ"  , null    , BasicType.getTShort()  ,  0, true , _putfield       );
793 
794     def(_fast_aload_0        , "fast_aload_0"        , "b"    , null    , BasicType.getTObject() ,  1, true , _aload_0        );
795     def(_fast_iaccess_0      , "fast_iaccess_0"      , "b_JJ" , null    , BasicType.getTInt()    ,  1, true , _aload_0        );
796     def(_fast_aaccess_0      , "fast_aaccess_0"      , "b_JJ" , null    , BasicType.getTObject() ,  1, true , _aload_0        );
797     def(_fast_faccess_0      , "fast_faccess_0"      , "b_JJ" , null    , BasicType.getTObject() ,  1, true , _aload_0        );
798 
799     def(_fast_iload          , "fast_iload"          , "bi"   , null    , BasicType.getTInt()    ,  1, false, _iload          );
800     def(_fast_iload2         , "fast_iload2"         , "bi_i" , null    , BasicType.getTInt()    ,  2, false, _iload          );
801     def(_fast_icaload        , "fast_icaload"        , "bi_"  , null    , BasicType.getTInt()    ,  0, false, _iload          );
802 
803     // Faster method invocation.
804     def(_fast_invokevfinal   , "fast_invokevfinal"   , "bJJ"  , null    , BasicType.getTIllegal(), -1, true, _invokevirtual   );
805 
806     def(_fast_linearswitch   , "fast_linearswitch"   , ""     , null    , BasicType.getTVoid()   , -1, false, _lookupswitch   );
807     def(_fast_binaryswitch   , "fast_binaryswitch"   , ""     , null    , BasicType.getTVoid()   , -1, false, _lookupswitch   );
808     def(_fast_aldc           , "fast_aldc"           , "bj"   , null    , BasicType.getTObject(),   1, true,  _ldc            );
809     def(_fast_aldc_w         , "fast_aldc_w"         , "bJJ"  , null    , BasicType.getTObject(),   1, true,  _ldc_w          );
810 
811     def(_return_register_finalizer, "return_register_finalizer", "b"    , null    , BasicType.getTVoid()   , 0, true, _return );
812 
813     // special handling of signature-polymorphic methods
814     def(_invokehandle        , "invokehandle"        , "bJJ"  , null    , BasicType.getTIllegal(), -1, true, _invokevirtual   );
815 
816     // CDS specific. Bytecodes rewritten at CDS dump time
817     def(_nofast_getfield     , "_nofast_getfield"    , "bJJ"  , null    , BasicType.getTIllegal() , 0, true,  _getfield );
818     def(_nofast_putfield     , "_nofast_putfield"    , "bJJ"  , null    , BasicType.getTIllegal() ,-2, true,  _putfield );
819     def(_nofast_aload_0      , "_nofast_aload_0"     , "b"    , null    , BasicType.getTIllegal() , 1, true,  _aload_0  );
820     def(_nofast_iload        , "_nofast_iload"       , "bi"   , null    , BasicType.getTIllegal() , 1, false, _iload    );
821 
822     def(_shouldnotreachhere  , "_shouldnotreachhere" , "b"    , null    , BasicType.getTVoid()   ,  0, false);
823 
824     if (Assert.ASSERTS_ENABLED) {
825       // compare can_trap information for each bytecode with the
826       // can_trap information for the corresponding base bytecode
827       // (if a rewritten bytecode can trap, so must the base bytecode)
828       for (int i = 0; i < number_of_codes; i++) {
829         if (isDefined(i)) {
830           int j = javaCode(i);
831           if (canTrap(i) && !canTrap(j)) {
832             Assert.that(false, name(i) + " can trap => " + name(j) + " can trap, too");
833           }
834         }
835       }
836     }
837   }
838 
839   private static void def(int code, String name, String format, String wide_format, int result_type, int depth, boolean can_trap) {
840     def(code, name, format, wide_format, result_type, depth, can_trap, code);
841   }
842 
843   private static void def(int code, String name, String format, String wide_format, int result_type, int depth, boolean can_trap, int java_code) {
844     if (Assert.ASSERTS_ENABLED) {
845       Assert.that(wide_format == null || format != null, "short form must exist if there's a wide form");
846     }
847     int len  = (format      != null ? format.length()      : 0);
848     int wlen = (wide_format != null ? wide_format.length() : 0);
849     _name          [code] = name;
850     _result_type   [code] = result_type;
851     _depth         [code] = (byte) depth;
852     _lengths       [code] = (byte)((wlen << 4) | (len & 0xF));
853     _java_code     [code] = java_code;
854     _format        [code] = format;
855     _wide_format   [code] = wide_format;
856     int bc_flags = 0;
857     if (can_trap)           bc_flags |= _bc_can_trap;
858     if (java_code != code)  bc_flags |= _bc_can_rewrite;
859     _flags[code+0*256] = compute_flags(format,      bc_flags);
860     _flags[code+1*256] = compute_flags(wide_format, bc_flags);
861   }
862 }
863