bytecodes.hpp revision 3602:da91efe96a93
1215976Sjmallett/*
2232812Sjmallett * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3215976Sjmallett * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4215976Sjmallett *
5215976Sjmallett * This code is free software; you can redistribute it and/or modify it
6215976Sjmallett * under the terms of the GNU General Public License version 2 only, as
7215976Sjmallett * published by the Free Software Foundation.
8215976Sjmallett *
9215976Sjmallett * This code is distributed in the hope that it will be useful, but WITHOUT
10215976Sjmallett * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11215976Sjmallett * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12215976Sjmallett * version 2 for more details (a copy is included in the LICENSE file that
13215976Sjmallett * accompanied this code).
14215976Sjmallett *
15215976Sjmallett * You should have received a copy of the GNU General Public License version
16215976Sjmallett * 2 along with this work; if not, write to the Free Software Foundation,
17215976Sjmallett * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18232812Sjmallett *
19215976Sjmallett * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20215976Sjmallett * or visit www.oracle.com if you need additional information or have any
21215976Sjmallett * questions.
22215976Sjmallett *
23215976Sjmallett */
24215976Sjmallett
25215976Sjmallett#ifndef SHARE_VM_INTERPRETER_BYTECODES_HPP
26215976Sjmallett#define SHARE_VM_INTERPRETER_BYTECODES_HPP
27215976Sjmallett
28215976Sjmallett#include "memory/allocation.hpp"
29232812Sjmallett#include "utilities/top.hpp"
30215976Sjmallett
31215976Sjmallett// Bytecodes specifies all bytecodes used in the VM and
32215976Sjmallett// provides utility functions to get bytecode attributes.
33215976Sjmallett
34215976Sjmallett// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/interpreter/Bytecodes.java
35215976Sjmallettclass Bytecodes: AllStatic {
36215976Sjmallett public:
37215976Sjmallett  enum Code {
38215976Sjmallett    _illegal              =  -1,
39215976Sjmallett
40215976Sjmallett    // Java bytecodes
41215976Sjmallett    _nop                  =   0, // 0x00
42215976Sjmallett    _aconst_null          =   1, // 0x01
43215976Sjmallett    _iconst_m1            =   2, // 0x02
44215976Sjmallett    _iconst_0             =   3, // 0x03
45215976Sjmallett    _iconst_1             =   4, // 0x04
46215976Sjmallett    _iconst_2             =   5, // 0x05
47215976Sjmallett    _iconst_3             =   6, // 0x06
48215976Sjmallett    _iconst_4             =   7, // 0x07
49215976Sjmallett    _iconst_5             =   8, // 0x08
50215976Sjmallett    _lconst_0             =   9, // 0x09
51215976Sjmallett    _lconst_1             =  10, // 0x0a
52232812Sjmallett    _fconst_0             =  11, // 0x0b
53232812Sjmallett    _fconst_1             =  12, // 0x0c
54215976Sjmallett    _fconst_2             =  13, // 0x0d
55215976Sjmallett    _dconst_0             =  14, // 0x0e
56215976Sjmallett    _dconst_1             =  15, // 0x0f
57215976Sjmallett    _bipush               =  16, // 0x10
58215976Sjmallett    _sipush               =  17, // 0x11
59215976Sjmallett    _ldc                  =  18, // 0x12
60215976Sjmallett    _ldc_w                =  19, // 0x13
61215976Sjmallett    _ldc2_w               =  20, // 0x14
62215976Sjmallett    _iload                =  21, // 0x15
63215976Sjmallett    _lload                =  22, // 0x16
64215976Sjmallett    _fload                =  23, // 0x17
65215976Sjmallett    _dload                =  24, // 0x18
66215976Sjmallett    _aload                =  25, // 0x19
67215976Sjmallett    _iload_0              =  26, // 0x1a
68215976Sjmallett    _iload_1              =  27, // 0x1b
69215976Sjmallett    _iload_2              =  28, // 0x1c
70215976Sjmallett    _iload_3              =  29, // 0x1d
71215976Sjmallett    _lload_0              =  30, // 0x1e
72215976Sjmallett    _lload_1              =  31, // 0x1f
73215976Sjmallett    _lload_2              =  32, // 0x20
74215976Sjmallett    _lload_3              =  33, // 0x21
75215976Sjmallett    _fload_0              =  34, // 0x22
76215976Sjmallett    _fload_1              =  35, // 0x23
77215976Sjmallett    _fload_2              =  36, // 0x24
78215976Sjmallett    _fload_3              =  37, // 0x25
79215976Sjmallett    _dload_0              =  38, // 0x26
80215976Sjmallett    _dload_1              =  39, // 0x27
81215976Sjmallett    _dload_2              =  40, // 0x28
82215976Sjmallett    _dload_3              =  41, // 0x29
83215976Sjmallett    _aload_0              =  42, // 0x2a
84215976Sjmallett    _aload_1              =  43, // 0x2b
85215976Sjmallett    _aload_2              =  44, // 0x2c
86215976Sjmallett    _aload_3              =  45, // 0x2d
87215976Sjmallett    _iaload               =  46, // 0x2e
88215976Sjmallett    _laload               =  47, // 0x2f
89215976Sjmallett    _faload               =  48, // 0x30
90215976Sjmallett    _daload               =  49, // 0x31
91215976Sjmallett    _aaload               =  50, // 0x32
92215976Sjmallett    _baload               =  51, // 0x33
93215976Sjmallett    _caload               =  52, // 0x34
94215976Sjmallett    _saload               =  53, // 0x35
95215976Sjmallett    _istore               =  54, // 0x36
96215976Sjmallett    _lstore               =  55, // 0x37
97215976Sjmallett    _fstore               =  56, // 0x38
98215976Sjmallett    _dstore               =  57, // 0x39
99215976Sjmallett    _astore               =  58, // 0x3a
100215976Sjmallett    _istore_0             =  59, // 0x3b
101215976Sjmallett    _istore_1             =  60, // 0x3c
102215976Sjmallett    _istore_2             =  61, // 0x3d
103215976Sjmallett    _istore_3             =  62, // 0x3e
104215976Sjmallett    _lstore_0             =  63, // 0x3f
105215976Sjmallett    _lstore_1             =  64, // 0x40
106215976Sjmallett    _lstore_2             =  65, // 0x41
107215976Sjmallett    _lstore_3             =  66, // 0x42
108215976Sjmallett    _fstore_0             =  67, // 0x43
109215976Sjmallett    _fstore_1             =  68, // 0x44
110215976Sjmallett    _fstore_2             =  69, // 0x45
111215976Sjmallett    _fstore_3             =  70, // 0x46
112215976Sjmallett    _dstore_0             =  71, // 0x47
113215976Sjmallett    _dstore_1             =  72, // 0x48
114215976Sjmallett    _dstore_2             =  73, // 0x49
115215976Sjmallett    _dstore_3             =  74, // 0x4a
116215976Sjmallett    _astore_0             =  75, // 0x4b
117215976Sjmallett    _astore_1             =  76, // 0x4c
118215976Sjmallett    _astore_2             =  77, // 0x4d
119215976Sjmallett    _astore_3             =  78, // 0x4e
120215976Sjmallett    _iastore              =  79, // 0x4f
121215976Sjmallett    _lastore              =  80, // 0x50
122215976Sjmallett    _fastore              =  81, // 0x51
123215976Sjmallett    _dastore              =  82, // 0x52
124215976Sjmallett    _aastore              =  83, // 0x53
125215976Sjmallett    _bastore              =  84, // 0x54
126215976Sjmallett    _castore              =  85, // 0x55
127215976Sjmallett    _sastore              =  86, // 0x56
128215976Sjmallett    _pop                  =  87, // 0x57
129215976Sjmallett    _pop2                 =  88, // 0x58
130215976Sjmallett    _dup                  =  89, // 0x59
131215976Sjmallett    _dup_x1               =  90, // 0x5a
132215976Sjmallett    _dup_x2               =  91, // 0x5b
133215976Sjmallett    _dup2                 =  92, // 0x5c
134215976Sjmallett    _dup2_x1              =  93, // 0x5d
135215976Sjmallett    _dup2_x2              =  94, // 0x5e
136215976Sjmallett    _swap                 =  95, // 0x5f
137215976Sjmallett    _iadd                 =  96, // 0x60
138215976Sjmallett    _ladd                 =  97, // 0x61
139215976Sjmallett    _fadd                 =  98, // 0x62
140215976Sjmallett    _dadd                 =  99, // 0x63
141215976Sjmallett    _isub                 = 100, // 0x64
142215976Sjmallett    _lsub                 = 101, // 0x65
143215976Sjmallett    _fsub                 = 102, // 0x66
144215976Sjmallett    _dsub                 = 103, // 0x67
145215976Sjmallett    _imul                 = 104, // 0x68
146215976Sjmallett    _lmul                 = 105, // 0x69
147215976Sjmallett    _fmul                 = 106, // 0x6a
148215976Sjmallett    _dmul                 = 107, // 0x6b
149215976Sjmallett    _idiv                 = 108, // 0x6c
150215976Sjmallett    _ldiv                 = 109, // 0x6d
151215976Sjmallett    _fdiv                 = 110, // 0x6e
152215976Sjmallett    _ddiv                 = 111, // 0x6f
153215976Sjmallett    _irem                 = 112, // 0x70
154215976Sjmallett    _lrem                 = 113, // 0x71
155215976Sjmallett    _frem                 = 114, // 0x72
156215976Sjmallett    _drem                 = 115, // 0x73
157215976Sjmallett    _ineg                 = 116, // 0x74
158215976Sjmallett    _lneg                 = 117, // 0x75
159215976Sjmallett    _fneg                 = 118, // 0x76
160215976Sjmallett    _dneg                 = 119, // 0x77
161215976Sjmallett    _ishl                 = 120, // 0x78
162215976Sjmallett    _lshl                 = 121, // 0x79
163215976Sjmallett    _ishr                 = 122, // 0x7a
164215976Sjmallett    _lshr                 = 123, // 0x7b
165215976Sjmallett    _iushr                = 124, // 0x7c
166215976Sjmallett    _lushr                = 125, // 0x7d
167215976Sjmallett    _iand                 = 126, // 0x7e
168215976Sjmallett    _land                 = 127, // 0x7f
169215976Sjmallett    _ior                  = 128, // 0x80
170215976Sjmallett    _lor                  = 129, // 0x81
171215976Sjmallett    _ixor                 = 130, // 0x82
172215976Sjmallett    _lxor                 = 131, // 0x83
173215976Sjmallett    _iinc                 = 132, // 0x84
174215976Sjmallett    _i2l                  = 133, // 0x85
175215976Sjmallett    _i2f                  = 134, // 0x86
176215976Sjmallett    _i2d                  = 135, // 0x87
177215976Sjmallett    _l2i                  = 136, // 0x88
178215976Sjmallett    _l2f                  = 137, // 0x89
179215976Sjmallett    _l2d                  = 138, // 0x8a
180215976Sjmallett    _f2i                  = 139, // 0x8b
181215976Sjmallett    _f2l                  = 140, // 0x8c
182215976Sjmallett    _f2d                  = 141, // 0x8d
183215976Sjmallett    _d2i                  = 142, // 0x8e
184215976Sjmallett    _d2l                  = 143, // 0x8f
185215976Sjmallett    _d2f                  = 144, // 0x90
186215976Sjmallett    _i2b                  = 145, // 0x91
187215976Sjmallett    _i2c                  = 146, // 0x92
188215976Sjmallett    _i2s                  = 147, // 0x93
189215976Sjmallett    _lcmp                 = 148, // 0x94
190215976Sjmallett    _fcmpl                = 149, // 0x95
191215976Sjmallett    _fcmpg                = 150, // 0x96
192215976Sjmallett    _dcmpl                = 151, // 0x97
193215976Sjmallett    _dcmpg                = 152, // 0x98
194232812Sjmallett    _ifeq                 = 153, // 0x99
195215976Sjmallett    _ifne                 = 154, // 0x9a
196232812Sjmallett    _iflt                 = 155, // 0x9b
197232812Sjmallett    _ifge                 = 156, // 0x9c
198215976Sjmallett    _ifgt                 = 157, // 0x9d
199215976Sjmallett    _ifle                 = 158, // 0x9e
200215976Sjmallett    _if_icmpeq            = 159, // 0x9f
201215976Sjmallett    _if_icmpne            = 160, // 0xa0
202215976Sjmallett    _if_icmplt            = 161, // 0xa1
203215976Sjmallett    _if_icmpge            = 162, // 0xa2
204215976Sjmallett    _if_icmpgt            = 163, // 0xa3
205215976Sjmallett    _if_icmple            = 164, // 0xa4
206215976Sjmallett    _if_acmpeq            = 165, // 0xa5
207215976Sjmallett    _if_acmpne            = 166, // 0xa6
208215976Sjmallett    _goto                 = 167, // 0xa7
209215976Sjmallett    _jsr                  = 168, // 0xa8
210215976Sjmallett    _ret                  = 169, // 0xa9
211215976Sjmallett    _tableswitch          = 170, // 0xaa
212215976Sjmallett    _lookupswitch         = 171, // 0xab
213215976Sjmallett    _ireturn              = 172, // 0xac
214215976Sjmallett    _lreturn              = 173, // 0xad
215215976Sjmallett    _freturn              = 174, // 0xae
216215976Sjmallett    _dreturn              = 175, // 0xaf
217215976Sjmallett    _areturn              = 176, // 0xb0
218215976Sjmallett    _return               = 177, // 0xb1
219215976Sjmallett    _getstatic            = 178, // 0xb2
220215976Sjmallett    _putstatic            = 179, // 0xb3
221215976Sjmallett    _getfield             = 180, // 0xb4
222215976Sjmallett    _putfield             = 181, // 0xb5
223215976Sjmallett    _invokevirtual        = 182, // 0xb6
224215976Sjmallett    _invokespecial        = 183, // 0xb7
225215976Sjmallett    _invokestatic         = 184, // 0xb8
226215976Sjmallett    _invokeinterface      = 185, // 0xb9
227215976Sjmallett    _invokedynamic        = 186, // 0xba     // if EnableInvokeDynamic
228215976Sjmallett    _new                  = 187, // 0xbb
229215976Sjmallett    _newarray             = 188, // 0xbc
230215976Sjmallett    _anewarray            = 189, // 0xbd
231215976Sjmallett    _arraylength          = 190, // 0xbe
232215976Sjmallett    _athrow               = 191, // 0xbf
233215976Sjmallett    _checkcast            = 192, // 0xc0
234215976Sjmallett    _instanceof           = 193, // 0xc1
235215976Sjmallett    _monitorenter         = 194, // 0xc2
236215976Sjmallett    _monitorexit          = 195, // 0xc3
237215976Sjmallett    _wide                 = 196, // 0xc4
238215976Sjmallett    _multianewarray       = 197, // 0xc5
239215976Sjmallett    _ifnull               = 198, // 0xc6
240215976Sjmallett    _ifnonnull            = 199, // 0xc7
241215976Sjmallett    _goto_w               = 200, // 0xc8
242215976Sjmallett    _jsr_w                = 201, // 0xc9
243215976Sjmallett    _breakpoint           = 202, // 0xca
244215976Sjmallett
245232812Sjmallett    number_of_java_codes,
246215976Sjmallett
247232812Sjmallett    // JVM bytecodes
248232812Sjmallett    _fast_agetfield       = number_of_java_codes,
249215976Sjmallett    _fast_bgetfield       ,
250215976Sjmallett    _fast_cgetfield       ,
251215976Sjmallett    _fast_dgetfield       ,
252215976Sjmallett    _fast_fgetfield       ,
253215976Sjmallett    _fast_igetfield       ,
254215976Sjmallett    _fast_lgetfield       ,
255215976Sjmallett    _fast_sgetfield       ,
256215976Sjmallett
257215976Sjmallett    _fast_aputfield       ,
258215976Sjmallett    _fast_bputfield       ,
259215976Sjmallett    _fast_cputfield       ,
260215976Sjmallett    _fast_dputfield       ,
261215976Sjmallett    _fast_fputfield       ,
262215976Sjmallett    _fast_iputfield       ,
263215976Sjmallett    _fast_lputfield       ,
264215976Sjmallett    _fast_sputfield       ,
265215976Sjmallett
266215976Sjmallett    _fast_aload_0         ,
267215976Sjmallett    _fast_iaccess_0       ,
268215976Sjmallett    _fast_aaccess_0       ,
269215976Sjmallett    _fast_faccess_0       ,
270215976Sjmallett
271215976Sjmallett    _fast_iload           ,
272215976Sjmallett    _fast_iload2          ,
273215976Sjmallett    _fast_icaload         ,
274215976Sjmallett
275215976Sjmallett    _fast_invokevfinal    ,
276215976Sjmallett    _fast_linearswitch    ,
277215976Sjmallett    _fast_binaryswitch    ,
278215976Sjmallett
279215976Sjmallett    // special handling of oop constants:
280215976Sjmallett    _fast_aldc            ,
281215976Sjmallett    _fast_aldc_w          ,
282215976Sjmallett
283215976Sjmallett    _return_register_finalizer    ,
284215976Sjmallett
285215976Sjmallett    // special handling of signature-polymorphic methods:
286215976Sjmallett    _invokehandle         ,
287215976Sjmallett
288215976Sjmallett    _shouldnotreachhere,      // For debugging
289215976Sjmallett
290232812Sjmallett    // Platform specific JVM bytecodes
291215976Sjmallett#ifdef TARGET_ARCH_x86
292232812Sjmallett# include "bytecodes_x86.hpp"
293232812Sjmallett#endif
294215976Sjmallett#ifdef TARGET_ARCH_sparc
295215976Sjmallett# include "bytecodes_sparc.hpp"
296215976Sjmallett#endif
297215976Sjmallett#ifdef TARGET_ARCH_zero
298215976Sjmallett# include "bytecodes_zero.hpp"
299215976Sjmallett#endif
300215976Sjmallett#ifdef TARGET_ARCH_arm
301215976Sjmallett# include "bytecodes_arm.hpp"
302215976Sjmallett#endif
303215976Sjmallett#ifdef TARGET_ARCH_ppc
304215976Sjmallett# include "bytecodes_ppc.hpp"
305215976Sjmallett#endif
306215976Sjmallett
307215976Sjmallett
308215976Sjmallett    number_of_codes
309215976Sjmallett  };
310215976Sjmallett
311215976Sjmallett  // Flag bits derived from format strings, can_trap, can_rewrite, etc.:
312215976Sjmallett  enum Flags {
313215976Sjmallett    // semantic flags:
314215976Sjmallett    _bc_can_trap      = 1<<0,     // bytecode execution can trap or block
315215976Sjmallett    _bc_can_rewrite   = 1<<1,     // bytecode execution has an alternate form
316215976Sjmallett
317215976Sjmallett    // format bits (determined only by the format string):
318215976Sjmallett    _fmt_has_c        = 1<<2,     // constant, such as sipush "bcc"
319215976Sjmallett    _fmt_has_j        = 1<<3,     // constant pool cache index, such as getfield "bjj"
320215976Sjmallett    _fmt_has_k        = 1<<4,     // constant pool index, such as ldc "bk"
321215976Sjmallett    _fmt_has_i        = 1<<5,     // local index, such as iload
322215976Sjmallett    _fmt_has_o        = 1<<6,     // offset, such as ifeq
323215976Sjmallett    _fmt_has_nbo      = 1<<7,     // contains native-order field(s)
324215976Sjmallett    _fmt_has_u2       = 1<<8,     // contains double-byte field(s)
325215976Sjmallett    _fmt_has_u4       = 1<<9,     // contains quad-byte field
326215976Sjmallett    _fmt_not_variable = 1<<10,    // not of variable length (simple or wide)
327215976Sjmallett    _fmt_not_simple   = 1<<11,    // either wide or variable length
328215976Sjmallett    _all_fmt_bits     = (_fmt_not_simple*2 - _fmt_has_c),
329215976Sjmallett
330215976Sjmallett    // Example derived format syndromes:
331215976Sjmallett    _fmt_b      = _fmt_not_variable,
332215976Sjmallett    _fmt_bc     = _fmt_b | _fmt_has_c,
333215976Sjmallett    _fmt_bi     = _fmt_b | _fmt_has_i,
334215976Sjmallett    _fmt_bkk    = _fmt_b | _fmt_has_k | _fmt_has_u2,
335232812Sjmallett    _fmt_bJJ    = _fmt_b | _fmt_has_j | _fmt_has_u2 | _fmt_has_nbo,
336215976Sjmallett    _fmt_bo2    = _fmt_b | _fmt_has_o | _fmt_has_u2,
337232812Sjmallett    _fmt_bo4    = _fmt_b | _fmt_has_o | _fmt_has_u4
338232812Sjmallett  };
339215976Sjmallett
340215976Sjmallett private:
341215976Sjmallett  static bool        _is_initialized;
342215976Sjmallett  static const char* _name          [number_of_codes];
343215976Sjmallett  static BasicType   _result_type   [number_of_codes];
344215976Sjmallett  static s_char      _depth         [number_of_codes];
345215976Sjmallett  static u_char      _lengths       [number_of_codes];
346215976Sjmallett  static Code        _java_code     [number_of_codes];
347215976Sjmallett  static jchar       _flags         [(1<<BitsPerByte)*2]; // all second page for wide formats
348215976Sjmallett
349215976Sjmallett  static void        def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap);
350215976Sjmallett  static void        def(Code code, const char* name, const char* format, const char* wide_format, BasicType result_type, int depth, bool can_trap, Code java_code);
351215976Sjmallett  static void        pd_initialize();              // platform specific initialization
352215976Sjmallett  static Code        pd_base_code_for(Code code);  // platform specific base_code_for implementation
353215976Sjmallett
354215976Sjmallett  // Verify that bcp points into method
355215976Sjmallett#ifdef ASSERT
356215976Sjmallett  static bool        check_method(const Method* method, address bcp);
357215976Sjmallett#endif
358215976Sjmallett  static bool check_must_rewrite(Bytecodes::Code bc);
359215976Sjmallett
360215976Sjmallett public:
361215976Sjmallett  // Conversion
362215976Sjmallett  static void        check          (Code code)    { assert(is_defined(code),      err_msg("illegal code: %d", (int)code)); }
363215976Sjmallett  static void        wide_check     (Code code)    { assert(wide_is_defined(code), err_msg("illegal code: %d", (int)code)); }
364215976Sjmallett  static Code        cast           (int  code)    { return (Code)code; }
365215976Sjmallett
366215976Sjmallett
367215976Sjmallett  // Fetch a bytecode, hiding breakpoints as necessary.  The method
368215976Sjmallett  // argument is used for conversion of breakpoints into the original
369215976Sjmallett  // bytecode.  The CI uses these methods but guarantees that
370215976Sjmallett  // breakpoints are hidden so the method argument should be passed as
371215976Sjmallett  // NULL since in that case the bcp and Method* are unrelated
372215976Sjmallett  // memory.
373215976Sjmallett  static Code       code_at(const Method* method, address bcp) {
374215976Sjmallett    assert(method == NULL || check_method(method, bcp), "bcp must point into method");
375215976Sjmallett    Code code = cast(*bcp);
376215976Sjmallett    assert(code != _breakpoint || method != NULL, "need Method* to decode breakpoint");
377215976Sjmallett    return (code != _breakpoint) ? code : non_breakpoint_code_at(method, bcp);
378215976Sjmallett  }
379215976Sjmallett  static Code       java_code_at(const Method* method, address bcp) {
380215976Sjmallett    return java_code(code_at(method, bcp));
381232812Sjmallett  }
382215976Sjmallett
383232812Sjmallett  // Fetch a bytecode or a breakpoint:
384232812Sjmallett  static Code       code_or_bp_at(address bcp)    { return (Code)cast(*bcp); }
385215976Sjmallett
386215976Sjmallett  static Code       code_at(Method* method, int bci);
387215976Sjmallett  static bool       is_active_breakpoint_at(address bcp) { return (Code)*bcp == _breakpoint; }
388215976Sjmallett
389215976Sjmallett  // find a bytecode, behind a breakpoint if necessary:
390215976Sjmallett  static Code       non_breakpoint_code_at(const Method* method, address bcp);
391215976Sjmallett
392215976Sjmallett  // Bytecode attributes
393215976Sjmallett  static bool        is_defined     (int  code)    { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
394215976Sjmallett  static bool        wide_is_defined(int  code)    { return is_defined(code) && flags(code, true) != 0; }
395215976Sjmallett  static const char* name           (Code code)    { check(code);      return _name          [code]; }
396215976Sjmallett  static BasicType   result_type    (Code code)    { check(code);      return _result_type   [code]; }
397215976Sjmallett  static int         depth          (Code code)    { check(code);      return _depth         [code]; }
398215976Sjmallett  // Note: Length functions must return <=0 for invalid bytecodes.
399215976Sjmallett  // Calling check(code) in length functions would throw an unwanted assert.
400215976Sjmallett  static int         length_for     (Code code)    { /*no check*/      return _lengths       [code] & 0xF; }
401215976Sjmallett  static int         wide_length_for(Code code)    { /*no check*/      return _lengths       [code] >> 4; }
402215976Sjmallett  static bool        can_trap       (Code code)    { check(code);      return has_all_flags(code, _bc_can_trap, false); }
403215976Sjmallett  static Code        java_code      (Code code)    { check(code);      return _java_code     [code]; }
404215976Sjmallett  static bool        can_rewrite    (Code code)    { check(code);      return has_all_flags(code, _bc_can_rewrite, false); }
405215976Sjmallett  static bool        must_rewrite(Bytecodes::Code code) { return can_rewrite(code) && check_must_rewrite(code); }
406215976Sjmallett  static bool        native_byte_order(Code code)  { check(code);      return has_all_flags(code, _fmt_has_nbo, false); }
407215976Sjmallett  static bool        uses_cp_cache  (Code code)    { check(code);      return has_all_flags(code, _fmt_has_j, false); }
408215976Sjmallett  // if 'end' is provided, it indicates the end of the code buffer which
409215976Sjmallett  // should not be read past when parsing.
410215976Sjmallett  static int         special_length_at(Bytecodes::Code code, address bcp, address end = NULL);
411215976Sjmallett  static int         special_length_at(Method* method, address bcp, address end = NULL) { return special_length_at(code_at(method, bcp), bcp, end); }
412215976Sjmallett  static int         raw_special_length_at(address bcp, address end = NULL);
413215976Sjmallett  static int         length_for_code_at(Bytecodes::Code code, address bcp)  { int l = length_for(code); return l > 0 ? l : special_length_at(code, bcp); }
414215976Sjmallett  static int         length_at      (Method* method, address bcp)  { return length_for_code_at(code_at(method, bcp), bcp); }
415215976Sjmallett  static int         java_length_at (Method* method, address bcp)  { return length_for_code_at(java_code_at(method, bcp), bcp); }
416215976Sjmallett  static bool        is_java_code   (Code code)    { return 0 <= code && code < number_of_java_codes; }
417215976Sjmallett
418215976Sjmallett  static bool        is_aload       (Code code)    { return (code == _aload  || code == _aload_0  || code == _aload_1
419215976Sjmallett                                                                             || code == _aload_2  || code == _aload_3); }
420215976Sjmallett  static bool        is_astore      (Code code)    { return (code == _astore || code == _astore_0 || code == _astore_1
421215976Sjmallett                                                                             || code == _astore_2 || code == _astore_3); }
422215976Sjmallett
423215976Sjmallett  static bool        is_zero_const  (Code code)    { return (code == _aconst_null || code == _iconst_0
424215976Sjmallett                                                           || code == _fconst_0 || code == _dconst_0); }
425215976Sjmallett  static bool        is_invoke      (Code code)    { return (_invokevirtual <= code && code <= _invokedynamic); }
426215976Sjmallett
427215976Sjmallett  static bool        has_optional_appendix(Code code) { return code == _invokedynamic || code == _invokehandle; }
428215976Sjmallett
429215976Sjmallett  static int         compute_flags  (const char* format, int more_flags = 0);  // compute the flags
430215976Sjmallett  static int         flags          (int code, bool is_wide) {
431215976Sjmallett    assert(code == (u_char)code, "must be a byte");
432215976Sjmallett    return _flags[code + (is_wide ? (1<<BitsPerByte) : 0)];
433215976Sjmallett  }
434215976Sjmallett  static int         format_bits    (Code code, bool is_wide) { return flags(code, is_wide) & _all_fmt_bits; }
435215976Sjmallett  static bool        has_all_flags  (Code code, int test_flags, bool is_wide) {
436215976Sjmallett    return (flags(code, is_wide) & test_flags) == test_flags;
437215976Sjmallett  }
438215976Sjmallett
439215976Sjmallett  // Initialization
440215976Sjmallett  static void        initialize     ();
441215976Sjmallett};
442215976Sjmallett
443232812Sjmallett#endif // SHARE_VM_INTERPRETER_BYTECODES_HPP
444215976Sjmallett