List of common JVM instructions

Bytecode instructions are based on the stack (operand stack in the stack frame). Many problems that cannot be explained from the source code can be explained at the bytecode level. The following are common bytecode instruction
stacks and local variable operations

The instruction to
push the constant onto the stack aconst_null pushes the null object reference onto the stack
iconst_m1 pushes the int type constant -1 onto the stack
iconst_0 pushes the int type constant 0 onto the stack
iconst_1 pushes the int type constant 1 onto the stack
iconst_2 pushes the int type constant 2
Push on the stack iconst_3 Push the int type constant 3 onto the stack
iconst_4 Push the int type constant 4 onto the stack
iconst_5 Push the int type constant 5 onto the stack
lconst_0 Push the long type constant 0 onto the stack
lconst_1 Push the long type constant 1 onto the stack
fconst_0 Push the float Push type constant 0 onto the stack
fconst_1 push float type constant 1 onto the stack
dconst_0 push double type constant 0 onto the stack
dconst_1 push double type constant 1 onto the stack
bipush push an 8-bit signed integer onto the stack
sipush push 16-bit signed Integer is pushed onto the stack
ldc Push the items in the constant pool onto the stack ldc_w Push the items in
the constant pool onto the stack (using wide index)
ldc2_w Push the items in the constant pool of type long or double onto the stack (using wide index)
from The instruction to load values ​​in local variables in the stack
iload loads int type values
from local variables lload loads long type values
from local variables fload loads float type values ​​from local variables
dload loads the double type value
from the local variable aload loads the reference type value
from the local variable (refernce) iload_0 loads the int type value from the local variable 0
iload_1 loads the int type value from the local variable 1
iload_2 loads the int type from the local variable 2 The value
iload_3 loads the int type value
lload_0 from the local variable 3 loads the long type value lload_1 from the local variable 0 loads the long type value
lload_2 from the local variable 1 loads the long type value
from the local variable 2
lload_3 loads the long type from the local variable 3 The value
fload_0 loads the float type value from the local variable 0 fload_1 loads the float type value
from the local variable 1 fload_2 loads the float type value
from the local variable 2
fload_3 loads the float type value from the local variable 3
dload_0 loads the double type from the local variable 0 The value
dload_1 loads the double type value from local variable 1 dload_2 loads the double type value
from local variable 2 dload_3 loads the double type value
from local variable 3
aload_0 loads the reference type value from local variable 0
aload_1 loads the reference type from local variable 1 The value
aload_2 loads the reference type value
aload_3 from the local variable 2 Load reference type value from local variable 3
iaload loads int type values
from the array laload loads long type values
from the array faload loads float type values
from the array daload loads double type values
from the array aaload loads reference type values
from the array baload loads byte or boolean types from the array The value
load loads the char type value
from the array saload loads the short type value from the array
instruction to store the value in the stack into the local variable
istore stores the value of the int type into the local variable
lstore stores the value of the long type into the local variable
fstore the float type Store value in local variable
dstore Store double type value in local variable
astore Store reference type or returnAddress type value in local variable
istore_0 Store int type value in local variable 0
istore_1 Store int type value in local variable 1
istore_2 Store int Store type value in local variable 2
istore_3 Store int type value in local variable 3
lstore_0 Store long type value in local variable 0
lstore_1 Store long type value in local variable 1
lstore_2 Store long type value in local variable 2
lstore_3 Store long type values into local variables. 3
fstore_0 float type value into the local variable 0
fstore_1 stores the value of type float in local variable 1
fstore_2 stores the value of type float in local variable 2
fstore_3 stores the value of type float in local variable 3
dstore_0 stores the value of type double in local variable 0
dstore_1 stores the value of type double in local variable 1
dstore_2 stores the double type value in the local variable 2
dstore_3 stores the double type value in the local variable 3
astore_0 stores the reference type or returnAddress type value in the local variable 0
astore_1 stores the reference type or returnAddress type value in the local variable 1
astore_2 stores the reference type Or returnAddress type value stored in local variable 2
astore_3 store reference type or returnAddress type value stored in local variable 3
iastore store int type value in array
lastore store long type value in array
fastore store float type value in array
dastore Store the double type value in the array
aastore Store the reference type value in the array
bastore Store the byte type or boolean type value in the array
castore Store the char type value in the array
sastore Store the short type value in the array
wide instruction
wide extended use of additional byte index of local variables
through (Untyped) stack operations
nop do nothing.
pop pops a word at the top of the stack.
pop2 pops a word at the top of the stack.
dup copies a word at the top of the stack.
dup_x1 copies a word at the top of the stack, and then copies the content and the original pop. The two-word content is pushed onto the stack
dup_x2. The one-word content at the top of the copy stack is copied, and then the copied content and the three-word content that was originally popped are pushed onto the stack.
Dup2 The two-word content
at the top of the copy stack. The content of two words, and then push the copied content and the original three-word content to the stack.
Dup2_x2 Copy the two-word content at the top of the stack, and then push the copied content and the original four-word content. Stack
swap The two word lengths at the top of the exchange stack Content
type conversion
i2l Convert int type data to long type
i2f Convert int type data to float type
i2d Convert int type data to double type
l2i Convert long type data to int type
l2f converts long type data to float type
l2d converts long type data to double type
f2i converts float type data to in t type
f2l converts float type data to long type
f2d converts float type data to double type
d2i converts double type data to int type
d2l converts double type data to long type
d2f converts double type data to float type
i2b converts int type data to byte type
i2c converts int type data to char type
i2s converts int type data to short type
integer operation
iadd performs int type addition
ladd execution Long type addition
isub performs int type subtraction
lsub performs long type subtraction
imul performs int type multiplication
lmul performs long type multiplication
idiv performs int type division
ldiv performs long type division
irem calculates the int type division remainder
lrem calculates long The remainder of type division
ineg performs an inverse operation
on a value of type int lneg performs an inverse operation on a value of type long
iinc adds a constant value to a local variable of type int.
Logical operation
Shift operation
ishl Performs an int type to the left Shift operation
lshl performs a long shift operation to the left
ishr Performs an int shift operation to the right
lshr performs a long shift operation to
the right type iushr performs an int shift logic operation to the right
lushr performs a long shift operation Right logical shift operation
Bitwise Boolean operation
iand "logical AND" operation on int type value
land "logical AND" operation on long type value
ior "logical OR" operation on int type value
lor "logical OR" operation on long type value
ixor on int type value "Logical XOR" operation
lxor "Logical XOR" operation on long type values
Floating point operation
fadd Performs addition of float type
dadd Performs addition of double type
fsub Performs subtraction of float type
dsub Performs subtraction of double type
fmul Performs float type Multiplication
dmul Performs double type multiplication
fdiv Performs float type division
ddiv Performs double type division
frem Calculates the float type division remainder
drem Calculates the double type division remainder
fneg Inverts a float type value
dneg Takes a double type value Inverse
Objects and arrays
Object operation instructions
new Create a new object
checkcast Determine that the object is of the given type
getfield Get the field from the object
putfield Set the value of the field in the object
getstatic Get the static field from the class
putstatic Set the value of the static field in the class
instanceof Determines whether the object is of a given type.
Array operation instruction newarray Assigns
a new array with a data member type of basically a data type
anewarray Assigns a new array with a data member type of reference type
arraylength Gets the array length
multianewarray Assigns a new multidimensional array
control flow
conditional branch
If the ifeq command is equal to 0,
ifif is not equal to 0, then
iflt is less than 0,
ifif is greater than or equal to 0,
ifgt is greater than 0,
ifif is less than or equal to 0, then Jump
if_icmpcq if two int values ​​are equal, then jump
if_icmpne if two int type values ​​are not equal, then jump
if_icmplt if one int type value is less than another int type value, then jump
if_icmpge if an int type value is greater than or Equal to another int type value, then jump
if_icmpgt if an int type value is greater than another int type value, then jump
if_icmple if an int type value is less than or equal to another int type value, then jump
ifnull if equal to null, then Jump
ifnonnull if not equal to null, then jump
if_acmp eq If two object references are equal, jump
if_acmpnc If two object references are not equal, then jump
Compare command
lcmp compare long type value
fcmpl compare float type value (return -1 when NaN is encountered)
fcmpg compare float type value (return 1 when NaN is encountered)
dcmpl compare double type value (when NaN is encountered, Returns -1)
dcmpg compares double values ​​(returns 1 when NaN is encountered) unconditional jump
instruction
goto unconditional jump
goto_w unconditional jump (wide index)
table jump instruction
tableswitch accesses the jump table by index and jumps
lookupswitch Access the jump table through key-value matching and perform a jump operation.
Exception
athrow throws an exception or error
finally clause
jsr jump to subroutine
jsr_w jump to subroutine (wide index)
rct returns
method call from subroutine With the return
method call instruction
invokevirtual, the instance method is
invoked according to the class of the object, invokespecial, the instance method is invoked according to the compile-time type,
invokestatic, the class (static) method,
invokcinterface, the interface method, the
method return instruction,
ireturn, and the int data from the method,
lreturn, The method returns data of type long
freturn returns data of type float
from the method dreturn returns data of type double
from the method areturn returns data of reference type
from the method return returns from the method, the return value is void
thread synchronized (synchronized)
monitorenter enters and gets the object monitor ( Used with astore instruction)
monitorexit releases and exits the object monitor (used with aload instruction)

JVM instruction mnemonic
variables to the operand stack: iload, iload_, lload, lload_, fload, fload_, dload, dload_, aload, aload_
operand stack to variables: istore, istore_, lstore, lstore_, fstore, fstore_, dstore, dstor_, astore, astore_constant
to the operand stack: bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_ml, iconst_, lconst_, fconst_, dconst_add
: iadd, ladd, fadd, dadd
minus: isub, lsub, fsub, dsub
Multiplication: imul, lmul, fmul, dmul
division: idiv, ldiv, fdiv, ddiv
remainder: irem, lrem, frem, drem
negative: ineg, lneg, fneg, dneg
shift: ishl, lshr, iushr, lshl, lshr, lushr
bitwise or: ior, lor
bitwise and: iand, land
bitwise XOR: ixor, lxor
type conversion: i2l, i2f, i2d, l2f, l2d, f2d (relaxed value conversion)
i2b, i2c, i2s, l2i, f2i, f2l, d2i, d2l, d2f (narrowing numeric conversion)
creation class is practical: new
creates a new array: newarray, anewarray, multianwarray
Access the class field and class instance field: getfield, putfield, getstatic, putstatic
to load data to the operand stack: baload, caload, saload, iaload, laload, faload, daload, aaload
from the operand stack storage to the array: bastore, Castore, sastore, iastore, lastore, fastore, dastore, aastore
get array length: arraylength
phase detection class instance or array attribute: instanceof, checkcast
operand stack management: pop, pop2, dup, dup2, dup_xl, dup2_xl, dup_x2, dup2_x2, swap
conditional transfer: ifeq, iflt, ifle, ifne, ifgt, ifge, ifnull, ifnonnull, if_icmpeq, if_icmpene,
if_icmplt, if_icmpgt, if_icmple, if_icmpge, if_acmpeq, if_acmpne, lcmp, fcmpl
fcmpg, dcmpl, dcmpg
compound condition , lookupswitch
unconditional transfer: goto, goto_w, jsr, jsr_w, ret
scheduling method of the object: invokevirtual
call method implemented by the interface: invokeinterface
call instance method that requires special treatment: invokespecial
call static method in the named class: invokestatic
Method returns: ireturn, lreturn, freturn, dreturn, areturn, return
exception:
the realization of the keyword finally: jsr, jsr_w, ret

Interested friends can use the javap command or jclasslib tool to view the bytecode, compare the memory and understand the
specific meaning of the local variable table and operand stack. You can refer to the blogger ’s introduction of another blog, the link is: https: // blog .csdn.net / sjz88888 / article / details / 104864256

Published 14 original articles · won 3 · views 928

Guess you like

Origin blog.csdn.net/sjz88888/article/details/105018702