“JVM bytecode list”与“JVM method translate to bytecode”:页面之间的差异

来自WHY42
(页面间差异)
 
 
第1行: 第1行:
= Constants =
= 特殊方法 =
Push constants into the operand stack.
== xxx ==
<syntaxhighlight lang="java">


; iconst_&lt;i&gt;: Push the int constant &lt;i&gt; (-1, 0, 1, 2, 3, 4 or 5) onto the operand stack.
; bipush: Push byte. iconst_&lt;i&gt; is equivalent to bipush &lt;i&gt;
; lconst_&lt;l&gt;: Push long.
; fconst_&lt;f&gt;: Push float.
; dconst_&lt;d&gt;: Push double.
; sipush: Push short
; ldc: Push from constant pool(int, float, or string reference, etc.)
; ldc: Push from constant pool(long, double, etc)
<syntaxhighlight lang="lisp">
00 (0x00)    nop
01 (0x01)    aconst_null
02 (0x02)    iconst_m1
03 (0x03)    iconst_0
04 (0x04)    iconst_1
05 (0x05)    iconst_2
06 (0x06)    iconst_3
07 (0x07)    iconst_4
08 (0x08)    iconst_5
09 (0x09)    lconst_0
10 (0x0a)    lconst_1
11 (0x0b)    fconst_0
12 (0x0c)    fconst_1
13 (0x0d)    fconst_2
14 (0x0e)    dconst_0
15 (0x0f)    dconst_1
16 (0x10)    bipush        (byte)
17 (0x11)    sipush        (byte1 byte2)
18 (0x12)    ldc          (index)
19 (0x13)    ldc_w        (indexbyte1 indexbyte2)
20 (0x14)    ldc2_w        (indexbyte1 indexbyte2)
</syntaxhighlight>
= Loads =
Load value from local variable to operand stack.
; iload_&lt;i&gt;: Load int
; lload_&lt;i&gt;: Load long
; fload_&lt;i&gt;: Load float
; dload_&lt;i&gt;: Load double
; aload_&lt;i&gt;: Load reference
; iaload: Load int from array. ..., arrayref, index → both array ref and index are popped from operand stack
; laload: Load long from array
; faload: Load float from array
; daload: Load double from array
; aaload: Load reference from array
; baload: Load byte from array
; caload: Load char from array
; saload: Load short from array
<syntaxhighlight lang="lisp">
21 (0x15)    iload        (index)
22 (0x16)    lload        (index)
23 (0x17)    fload        (index)
24 (0x18)    dload        (index)
25 (0x19)    aload        (index)
26 (0x1a)    iload_0
27 (0x1b)    iload_1
28 (0x1c)    iload_2
29 (0x1d)    iload_3
30 (0x1e)    lload_0
31 (0x1f)    lload_1
32 (0x20)    lload_2
33 (0x21)    lload_3
34 (0x22)    fload_0
35 (0x23)    fload_1
36 (0x24)    fload_2
37 (0x25)    fload_3
38 (0x26)    dload_0
39 (0x27)    dload_1
40 (0x28)    dload_2
41 (0x29)    dload_3
42 (0x2a)    aload_0
43 (0x2b)    aload_1
44 (0x2c)    aload_2
45 (0x2d)    aload_3
46 (0x2e)    iaload
47 (0x2f)    laload
48 (0x30)    faload
49 (0x31)    daload
50 (0x32)    aaload
51 (0x33)    baload
52 (0x34)    caload
53 (0x35)    saload
</syntaxhighlight>
= Stores =
Store value into local variable.
; istore: Store the value from the top of the operand stack(must be int) into local variable
; iastore: Store into int array. ..., arrayref, index, value → values are popped from operand stack
<syntaxhighlight lang="lisp">
54 (0x36)    istore        (index)
55 (0x37)    lstore        (index)
56 (0x38)    fstore        (index)
57 (0x39)    dstore        (index)
58 (0x3a)    astore        (index)
59 (0x3b)    istore_0
60 (0x3c)    istore_1
61 (0x3d)    istore_2
62 (0x3e)    istore_3
63 (0x3f)    lstore_0
64 (0x40)    lstore_1
65 (0x41)    lstore_2
66 (0x42)    lstore_3
67 (0x43)    fstore_0
68 (0x44)    fstore_1
69 (0x45)    fstore_2
70 (0x46)    fstore_3
71 (0x47)    dstore_0
72 (0x48)    dstore_1
73 (0x49)    dstore_2
74 (0x4a)    dstore_3
75 (0x4b)    astore_0
76 (0x4c)    astore_1
77 (0x4d)    astore_2
78 (0x4e)    astore_3
79 (0x4f)    iastore
80 (0x50)    lastore
81 (0x51)    fastore
82 (0x52)    dastore
83 (0x53)    aastore
84 (0x54)    bastore
85 (0x55)    castore
86 (0x56)    sastore
</syntaxhighlight>
= Stack =
; pop: Pop from the operand stack
; pop2: Pop the top one or two operand stack values
; dup: Duplicate the top value on the operand stack and push the duplicated value onto the operand stack.
; dup2: Duplicate the top one or two operand stack values
; swap: Swap the top two operand stack values
<syntaxhighlight lang="lisp">
87 (0x57)    pop
88 (0x58)    pop2
89 (0x59)    dup
90 (0x5a)    dup_x1
91 (0x5b)    dup_x2
92 (0x5c)    dup2
93 (0x5d)    dup2_x1
94 (0x5e)    dup2_x2
95 (0x5f)    swap
</syntaxhighlight>
= Math =
; %add: Add two values, ..., value1, value2 → ..., result
; %sub: Subtract
; %mul: Multiply
; %div: Divide
; %rem: Remainder (取余)
; %neg: Negate
; %shl: Shift left
; %shr: Arithmetic shift right
; %ushr: Logical shift right
; %and: and
; %or: or
; %xor: xor
; %inc: Increment local variable by constant
<syntaxhighlight lang="lisp">
96 (0x60)    iadd
97 (0x61)    ladd
98 (0x62)    fadd
99 (0x63)    dadd
100 (0x64)    isub
101 (0x65)    lsub
102 (0x66)    fsub
103 (0x67)    dsub
104 (0x68)    imul
105 (0x69)    lmul
106 (0x6a)    fmul
107 (0x6b)    dmul
108 (0x6c)    idiv
109 (0x6d)    ldiv
110 (0x6e)    fdiv
111 (0x6f)    ddiv
112 (0x70)    irem
113 (0x71)    lrem
114 (0x72)    frem
115 (0x73)    drem
116 (0x74)    ineg
117 (0x75)    lneg
118 (0x76)    fneg
119 (0x77)    dneg
120 (0x78)    ishl
121 (0x79)    lshl
122 (0x7a)    ishr
123 (0x7b)    lshr
124 (0x7c)    iushr
125 (0x7d)    lushr
126 (0x7e)    iand
127 (0x7f)    land
128 (0x80)    ior
129 (0x81)    lor
130 (0x82)    ixor
131 (0x83)    lxor
132 (0x84)    iinc      (index const)
</syntaxhighlight>
</syntaxhighlight>


= Conversions =
<syntaxhighlight lang="java">
Conversions between values. .., value → ..., result


<syntaxhighlight lang="lisp">
133 (0x85)    i2l
134 (0x86)    i2f
135 (0x87)    i2d
136 (0x88)    l2i
137 (0x89)    l2f
138 (0x8a)    l2d
139 (0x8b)    f2i
140 (0x8c)    f2l
141 (0x8d)    f2d
142 (0x8e)    d2i
143 (0x8f)    d2l
144 (0x90)    d2f
145 (0x91)    i2b
146 (0x92)    i2c
147 (0x93)    i2s
</syntaxhighlight>
</syntaxhighlight>


= Comparisons =
== 默认构造函数 ==
Compare values.
 
; %cmp: If value1 is greater than value2, the int value 1 is pushed onto the operand stack. If value1 is equal to value2, the int value 0 is pushed onto the operand stack. If value1 is less than value2, the int value -1 is pushed onto the operand stack.
; %cmplg: The fcmpg and fcmpl instructions differ only in their treatment of a comparison involving NaN.
; if&lt;cond&gt;: Compared with the value popped from the operand stack and compared against zero. If success, the branch offset will be executed.
; if_icmp&lt;cond&gt;: Compare values in stack ..., value1, value2 →
 
<syntaxhighlight lang="lisp">
<syntaxhighlight lang="lisp">
148 (0x94)    lcmp
aload_0
149 (0x95)    fcmpl
invokespecial #1                  // Method java/lang/Object."<init>":()V
150 (0x96)    fcmpg
return
151 (0x97)    dcmpl
152 (0x98)    dcmpg
153 (0x99)    ifeq        (branchbyte1, branchbyte2)
154 (0x9a)    ifne        (branchbyte1, branchbyte2)
155 (0x9b)    iflt        (branchbyte1, branchbyte2)
156 (0x9c)    ifge        (branchbyte1, branchbyte2)
157 (0x9d)    ifgt        (branchbyte1, branchbyte2)
158 (0x9e)    ifle        (branchbyte1, branchbyte2)
159 (0x9f)    if_icmpeq    (branchbyte1, branchbyte2)
160 (0xa0)    if_icmpne    (branchbyte1, branchbyte2)
161 (0xa1)    if_icmplt    (branchbyte1, branchbyte2)
162 (0xa2)    if_icmpge    (branchbyte1, branchbyte2)
163 (0xa3)    if_icmpgt    (branchbyte1, branchbyte2)
164 (0xa4)    if_icmple    (branchbyte1, branchbyte2)
165 (0xa5)    if_acmpeq    (branchbyte1, branchbyte2)
166 (0xa6)    if_acmpne    (branchbyte1, branchbyte2)
</syntaxhighlight>
</syntaxhighlight>


= References =
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="lisp">
178 (0xb2)    getstatic        (indexbyte1 indexbyte2)
179 (0xb3)    putstatic        (indexbyte1 indexbyte2)
180 (0xb4)    getfield        (indexbyte1 indexbyte2)
181 (0xb5)    putfield        (indexbyte1 indexbyte2)
182 (0xb6)    invokevirtual    (indexbyte1 indexbyte2)
183 (0xb7)    invokespecial    (indexbyte1 indexbyte2)
184 (0xb8)    invokestatic    (indexbyte1 indexbyte2)
185 (0xb9)    invokeinterface  (indexbyte1 indexbyte2 count 0)
186 (0xba)    invokedynamic    (indexbyte1 indexbyte2 0 0)
187 (0xbb)    new              (indexbyte1 indexbyte2)
188 (0xbc)    newarray        (acode)
189 (0xbd)    anewarray        (indexbyte1 indexbyte2)
190 (0xbe)    arraylength
191 (0xbf)    athrow
192 (0xc0)    checkcast        (indexbyte1 indexbyte2)
193 (0xc1)    instanceof      (indexbyte1 indexbyte2)
194 (0xc2)    monitorenter
195 (0xc3)    monitorexit
</syntaxhighlight>


= Control =
<syntaxhighlight lang="lisp">
167 (0xa7)    goto          (branchbyte1 branchbyte2)
168 (0xa8)    jsr          (branchbyte1 branchbyte2)
169 (0xa9)    ret          (index)
170 (0xaa)    tableswitch   
171 (0xab)    lookupswitch
172 (0xac)    ireturn
173 (0xad)    lreturn
174 (0xae)    freturn
175 (0xaf)    dreturn
176 (0xb0)    areturn
177 (0xb1)    return
</syntaxhighlight>
</syntaxhighlight>


= Extended =
= statements =
<syntaxhighlight lang="lisp">
== 创建对象==
196 (0xc4)    wide
<syntaxhighlight lang="java">
197 (0xc5)    multianewarray
HelloWorld s = new HelloWorld();
198 (0xc6)    ifnull
199 (0xc7)    ifnonnull
200 (0xc8)    goto_w
201 (0xc9)   jsr_w
</syntaxhighlight>
</syntaxhighlight>


= Reserved =
<syntaxhighlight lang="lisp">
<syntaxhighlight lang="lisp">
202 (0xca)    breakpoint
new          #5                  // class HelloWorld
254 (0xfe)    impdep1
dup
255 (0xff)   impdep2
invokespecial #6                  // Method "<init>":()V
</syntaxhighlight>
</syntaxhighlight>
* [https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-7.html|Chapter 7. Opcode Mnemonics by Opcode]


[[Category:JVM]]
[[Category:JVM]]

2021年4月20日 (二) 02:00的版本

特殊方法

xxx

默认构造函数

aload_0
invokespecial #1                  // Method java/lang/Object."<init>":()V
return

statements

创建对象

HelloWorld s = new HelloWorld();
new           #5                  // class HelloWorld
dup
invokespecial #6                  // Method "<init>":()V