# Java SE7 virtual machine instruction opcode mnemonic

Posted Jun 16, 2020 • 12 min read

# Introduction

In the Class file, the method body in the Java method, which represents the part of the program in a Java source program, is stored in the Code attribute of the method table collection. Stored in the Code attribute is bytecode, which is the compiled program. The instruction of the Java virtual machine is composed of two parts, the first is a byte length, a number representing a certain meaning(ie, opcode), followed by zero or more parameters representing the operation required by the operation code(ie, operand). Since the Java virtual machine adopts an architecture oriented to the operand stack instead of registers, most instructions do not contain operands and only have one opcode.

The length of the opcode is only one byte, which limits the number of opcodes to no more than 256. At the same time, the Class file format gives up the operand length alignment of the compiled code, which means that when the virtual machine processes data that exceeds one byte, it has to reconstruct the specific data structure from the bytes at runtime. For example, if you want to store a two-byte unsigned integer using two unsigned bytes, namely byte1 and byte2, then you need to construct the original unsigned integer like this:

(byte1<<8) | byte2

This will cause some performance loss when executing bytecode. But it is also beneficial to do so, because there is no need to align, and the middle padding and spacing symbols are omitted; using one byte to represent the opcode is also to obtain short compiled code. In this way, the length of the compiled code is reduced as much as possible, which is very suitable for network transmission.

If exception handling is not considered, the interpreter of the Java Virtual Machine can use the following pseudo-code as a basic execution model to understand:

```
do{
Automatically calculate the value of PC register plus 1;
According to the indicated position of the PC register, remove the opcode from the bytecode stream;
if(bytecode exists operand) take out the operand from the bytecode stream;
Perform the operation defined by the opcode;
}while(byte code length>0);
```

# Opcode, mnemonic table

```
Bytecode Mnemonic Instruction Meaning
0x00 nop does nothing.
0x01 aconst_null Push null to the top of the stack.
0x02 iconst_m1 push int type -1 to the top of the stack.
0x03 iconst_0 Push int type 0 to the top of the stack.
0x04 iconst_1 Push int type 1 to the top of the stack.
0x05 iconst_2 Push int type 2 to the top of the stack.
0x06 iconst_3 Push int type 3 to the top of the stack.
0x07 iconst_4 Push int type 4 to the top of the stack.
0x08 iconst_5 Push int type 5 to the top of the stack.
0x09 lconst_0 Push long 0 to the top of the stack.
0x0a lconst_1 Push long type 1 to the top of the stack.
0x0b fconst_0 Push float type 0 to the top of the stack.
0x0c fconst_1 Push float type 1 to the top of the stack.
0x0d fconst_2 Push float type 2 to the top of the stack.
0x0e dconst_0 Push double type 0 to the top of the stack.
0x0f dconst_1 Push double 1 to the top of the stack.
0x10 bipush pushes the single-byte constant value(-128~127) to the top of the stack.
0x11 sipush pushes a short integer constant value(-32768~32767) to the top of the stack.
0x12 ldc pushes int, float or String constant values from the constant pool to the top of the stack.
0x13 ldc_w pushes int, float or String constant values from the constant pool to the top of the stack(wide index).
0x14 ldc2_w pushes the long or double constant value from the constant pool to the top of the stack(wide index).
0x15 iload pushes the specified int local variable to the top of the stack.
0x16 lload pushes the specified long local variable to the top of the stack.
0x17 fload pushes the specified float type local variable to the top of the stack.
0x18 dload pushes the specified double local variable to the top of the stack.
0x19 aload pushes the specified reference type local variable to the top of the stack.
0x1a iload_0 Push the first local variable of type int to the top of the stack.
0x1b iload_1 pushes the second int local variable to the top of the stack.
0x1c iload_2 Push the third local variable of type int to the top of the stack.
0x1d iload_3 pushes the fourth local variable of type int to the top of the stack.
0x1e lload_0 pushes the first long local variable to the top of the stack.
0x1f lload_1 pushes the second long local variable to the top of the stack.
0x20 lload_2 Push the third long local variable to the top of the stack.
0x21 lload_3 pushes the fourth long local variable to the top of the stack.
0x22 fload_0 Push the first local variable of type float to the top of the stack.
0x23 fload_1 Push the second float type local variable to the top of the stack.
0x24 fload_2 Push the third float type local variable to the top of the stack
0x25 fload_3 Push the fourth local variable of float type to the top of the stack.
0x26 dload_0 Push the first double local variable to the top of the stack.
0x27 dload_1 Push the second double local variable to the top of the stack.
0x28 dload_2 Push the third double local variable to the top of the stack.
0x29 dload_3 Push the fourth double local variable to the top of the stack.
0x2a aload_0 Push the first local variable of reference type to the top of the stack.
0x2b aload_1 pushes the second reference type local variable to the top of the stack.
0x2c aload_2 Push the third local variable of reference type to the top of the stack.
0x2d aload_3 pushes the fourth local variable of reference type to the top of the stack.
0x2e iaload pushes the value of the specified index of the int array to the top of the stack.
0x2f laload pushes the value of the specified index of the long array to the top of the stack.
0x30 faload pushes the value of the specified index of the float array to the top of the stack.
0x31 daload pushes the value of the specified index of the double array to the top of the stack.
0x32 aaload pushes the value of the specified index of the reference array to the top of the stack.
0x33 baload pushes the value of the specified index of the boolean or byte array to the top of the stack.
0x34 caload pushes the value of the specified index of the char array to the top of the stack.
0x35 saload pushes the value of the specified index of the short array to the top of the stack.
0x36 istore stores the int value at the top of the stack in the specified local variable.
0x37 lstore Stores the long value at the top of the stack into the specified local variable.
0x38 fstore Stores the top float value in the specified local variable.
0x39 dstore Stores the double value on the top of the stack into the specified local variable.
0x3a astore Stores the top reference value in the specified local variable.
0x3b istore_0 Store the int value at the top of the stack in the first local variable.
0x3c istore_1 Store the top int value in the second local variable.
0x3d istore_2 Store the top int value in the third local variable.
0x3e istore_3 Store the top int value in the fourth local variable.
0x3f lstore_0 Store the long value at the top of the stack into the first local variable.
0x40 lstore_1 stores the long value at the top of the stack into the second local variable.
0x41 lstore_2 Store the long value at the top of the stack in the third local variable.
0x42 lstore_3 Store the long value at the top of the stack in the fourth local variable.
0x43 fstore_0 Store the top float value in the first local variable.
0x44 fstore_1 Store the top float value in the second local variable.
0x45 fstore_2 Store the top float value in the third local variable.
0x46 fstore_3 Store the top float value in the fourth local variable.
0x47 dstore_0 Store the double value at the top of the stack in the first local variable.
0x48 dstore_1 Store the double value at the top of the stack in the second local variable.
0x49 dstore_2 Store the double value at the top of the stack in the third local variable.
0x4a dstore_3 Store the double value on the top of the stack in the fourth local variable.
0x4b astore_0 Store the top reference value in the first local variable.
0x4c astore_1 Store the top reference value in the second local variable.
0x4d astore_2 Store the top reference value in the third local variable
0x4e astore_3 Store the top-reference value in the fourth local variable.
0x4f iastore stores the int value at the top of the stack into the specified index position of the specified array
0x50 lastore Stores the long value at the top of the stack into the specified index position of the specified array.
0x51 fastore stores the top float value in the specified index position of the specified array.
0x52 dastore stores the double value at the top of the stack into the specified index position of the specified array.
0x53 aastore Stores the reference value at the top of the stack into the specified index position of the specified array.
0x54 bastore Stores the boolean or byte value at the top of the stack into the specified index position of the specified array.
0x55 castore stores the char value at the top of the stack into the specified index position of the specified array
0x56 sastore saves the short top value of the stack to the specified index position of the specified array.
0x57 pop pops the top value of the stack(the value cannot be of type long or double).
0x58 pop2 Pops one(long or double type) or two values at the top of the stack(other).
0x59 dup Copy the top value of the stack and push the copied value to the top of the stack.
0x5a dup_x1 copies the top value of the stack and pushes the two copied values onto the top of the stack.
0x5b dup_x2 copies the top value of the stack and pushes three(or two) copied values onto the top of the stack.
0x5c dup2 Copy one(long or double type) or two(other) values at the top of the stack and push the copied value onto the top of the stack.
0x5d dup2_x1 Double version of dup_x1 instruction.
0x5e dup2_x2 Double version of dup_x2 instruction.
0x5f swap swaps the top two values on the stack(values cannot be of type long or double).
0x60 iadd adds the two int values on the top of the stack and pushes the result onto the top of the stack.
0x61 ladd adds the two long values on the top of the stack and pushes the result onto the top of the stack.
0x62 fadd adds two float values on the top of the stack and pushes the result onto the top of the stack.
0x63 dadd adds two double values on the top of the stack and pushes the result onto the top of the stack.
0x64 isub subtracts the two int values from the top of the stack and pushes the result onto the top of the stack.
0x65 lsub subtracts the two long values from the top of the stack and pushes the result onto the top of the stack.
0x66 fsub subtracts the two float values from the top of the stack and pushes the result onto the top of the stack.
0x67 dsub subtracts two double values from the top of the stack and pushes the result onto the top of the stack.
0x68 imul multiplies the two int values on the top of the stack and pushes the result onto the top of the stack. .
0x69 lmul Multiplies the two long values on the top of the stack and pushes the result onto the top of the stack.
0x6a fmul multiplies the two float values on the top of the stack and pushes the result onto the top of the stack.
0x6b dmul multiplies the two double values on the top of the stack and pushes the result onto the top of the stack.
0x6c idiv divides two int values on the top of the stack and pushes the result onto the top of the stack.
0x6d ldiv divides the two long values on the top of the stack and pushes the result onto the top of the stack.
0x6e fdiv divides two float values on the top of the stack and pushes the result onto the top of the stack.
0x6f ddiv divides the two double values on the top of the stack and pushes the result onto the top of the stack.
0x70 irem modulo the two int values on the top of the stack and push the result onto the top of the stack.
0x71 lrem modulo the two long values on the top of the stack and push the result onto the top of the stack.
0x72 frem modulo the two float values on the top of the stack and push the result onto the top of the stack.
0x73 drem modulo the two double values on the top of the stack and push the result onto the top of the stack.
0x74 ineg negates the int value on the top of the stack and pushes the result onto the top of the stack.
0x75 lneg negates the long value on the top of the stack and pushes the result onto the top of the stack.
0x76 fneg negates the top float value and pushes the result onto the top of the stack.
0x77 dneg negates the double value on the top of the stack and pushes the result onto the top of the stack.
0x78 ishl shifts the int value to the left by the specified number of bits and pushes the result onto the top of the stack.
0x79 lshl shifts the long value to the left by the specified number of bits and pushes the result onto the top of the stack.
0x7a ishr shifts the int value to the right(signed) by the specified number of bits and pushes the result onto the top of the stack.
0x7b lshr shifts the long value right(signed) by the specified number of bits and pushes the result onto the top of the stack.
0x7c iushr shifts the int value to the right(unsigned) by the specified number of bits and pushes the result onto the top of the stack.
0x7d lushr shifts the long value to the right(unsigned) by the specified number of bits and pushes the result onto the top of the stack.
0x7e iand "bitwise AND" the two int values on the top of the stack and push the result onto the top of the stack.
0x7f land takes the two long values on the top of the stack as "bitwise AND" and pushes the result onto the top of the stack.
0x80 ior "bitwise OR" the two int values on the top of the stack and push the result onto the top of the stack.
0x81 lor "bitwise OR" the two long values on the top of the stack and push the result onto the top of the stack.
0x82 ixor uses the two int values on the top of the stack as "bitwise XOR" and pushes the result onto the top of the stack.
0x83 lxor uses the two long values on the top of the stack as "bitwise XOR" and pushes the result onto the top of the stack.
0x84 iinc will increase the specified int variable by the specified value.
0x85 i2l converts the top int value of the stack to a long value and pushes the result to the top of the stack.
0x86 i2f converts the top int value of the stack to a float value and pushes the result onto the top of the stack.
0x87 i2d converts the top int value of the stack to a double value and pushes the result onto the top of the stack.
0x88 l2i converts the long value at the top of the stack to an int value and pushes the result to the top of the stack.
0x89 l2f converts the long value at the top of the stack into a float value and pushes the result to the top of the stack.
0x8a l2d converts the long value at the top of the stack to a double value and pushes the result to the top of the stack.
0x8b f2i converts the top float value to an int value and pushes the result to the top of the stack.
0x8c f2l Force convert the top float value to a long value and push the result to the top of the stack.
0x8d f2d Forcibly converts the top float value to a double value and pushes the result onto the top of the stack.
0x8e d2i converts the double value at the top of the stack to an int value and pushes the result to the top of the stack.
0x8f d2l converts the double value on the top of the stack to a long value and pushes the result to the top of the stack.
0x90 d2f converts the double value on the top of the stack to a float value and pushes the result onto the top of the stack.
0x91 i2b converts the int value on the top of the stack to a byte value and pushes the result onto the top of the stack.
0x92 i2c converts the int value on the top of the stack to a char value and pushes the result onto the top of the stack.
0x93 i2s Forcibly converts the top int value to a short value and pushes the result to the top of the stack.
0x94 lcmp compares the two long numeric values at the top of the stack, and pushes the result(1, 0, -1) onto the top of the stack.
0x95 fcmpl compares the size of two float values on the top of the stack, and pushes the result(1, 0, -1) onto the top of the stack; when one of the values is "NaN", -1 is pushed onto the top of the stack.
0x96 fcmpg compares the size of the two float values on the top of the stack, and pushes the result(1, 0, -1) onto the top of the stack; when one of the values is "NaN", pushes 1 onto the top of the stack.
0x97 dcmpl compares the size of two double values on the top of the stack, and pushes the result(1, 0, -1) onto the top of the stack; when one of the values is "NaN", -1 is pushed onto the top of the stack.
0x98 dcmpg compares the size of the two double values on the top of the stack, and pushes the result(1, 0, -1) onto the top of the stack; when one of the values is "NaN", pushes 1 onto the top of the stack.
0x99 ifeq Jump when the int value at the top of the stack is equal to 0.
0x9a ifne Jump when the int value on the top of the stack is not equal to 0.
0x9b iflt Jump when the int value at the top of the stack is less than 0.
0x9c ifge Jump when the int value of the top of the stack is greater than or equal to 0.
0x9d ifgt Jump when the int value of the top of the stack is greater than 0.
0x9e ifle Jump when the int value on the top of the stack is less than or equal to 0.
0x9f if_icmpeq compares the size of the top two int values on the stack, and jumps when the result is equal to 0.
0xa0 if_icmpne compares the size of the top two int values on the stack, and jumps when the result is not equal to 0.
0xa1 if_icmplt compares the size of the top two int values on the stack, and jumps when the result is less than 0.
0xa2 if_icmpge compares the size of the top two int values on the stack, and jumps when the result is greater than or equal to 0.
0xa3 if_icmpgt compares the size of the top two int values on the stack, and jumps when the result is greater than 0
0xa4 if_icmple compares the size of the top two int values on the stack, and jumps when the result is less than or equal to 0.
0xa5 if_acmpeq compares the top two reference values on the stack, and jumps when the results are equal.
0xa6 if_acmpne compares the two reference values at the top of the stack, and jumps when the results are not equal.
0xa7 goto Jump unconditionally.
0xa8 jsr jumps to the specified 16-bit offset position, and pushes the address of the next instruction of jsr onto the top of the stack.
0xa9 ret returns to the index position specified by the local variable(usually used in combination with jsr and jsr_w).
0xaa tableswitch is used for switch conditional jump, case value is continuous(variable length instruction).
0xab lookupswitch is used for switch conditional jump, case value is not continuous(variable length instruction).
0xac ireturn returns int from the current method.
0xad lreturn returns long from the current method.
0xae freturn returns float from the current method.
0xaf dreturn returns a double from the current method.
0xb0 areturn returns an object reference from the current method.
0xb1 return returns void from the current method.
0xb2 getstatic Get the static field of the specified class and push its value onto the top of the stack.
0xb3 putstatic assigns a value to the static field of the specified class.
0xb4 getfield Get the instance field of the specified class and push its value to the top of the stack.
0xb5 putfield assigns a value to the instance field of the specified class.
0xb6 invokevirtual invokes the instance method.
0xb7 invokespecial calls the superclass constructor, instance initialization method, and private method.
0xb8 invokestatic calls a static method.
0xb9 invokeinterface Call interface method.
0xba invokedynamic Call dynamic link method .
0xbb new creates an object and pushes its reference value to the top of the stack.
0xbc newarray creates an array of specified primitive types(such as int, float, char??) and pushes its reference value to the top of the stack.
0xbd anewarray creates an array of reference types(such as class, interface, array) and pushes its reference value to the top of the stack.
0xbe arraylength Get the length of the array and push it onto the top of the stack.
0xbf athrow throws an exception at the top of the stack.
0xc0 checkcast checks the type conversion. If it fails, it will throw a ClassCastException.
0xc1 instanceof checks whether the object is an instance of the specified class, if it is 1 is pushed onto the top of the stack, otherwise 0 is pushed onto the top of the stack.
0xc2 monitorenter Obtain the object's monitor, used for synchronization method or synchronization block.
0xc3 monitorexit releases the object's monitor for the synchronization method or synchronization block.
0xc4 wide Expand the index width for accessing the local variable table.
0xc5 multianewarray creates a multi-dimensional array of the specified type and specified dimensions(when this instruction is executed, the length value of each dimension must be included in the operation stack), and its reference value is pushed onto the top of the stack.
0xc6 Jump if ifnull is null.
0xc7 Jump if ifnonnull is not null.
0xc8 goto_w Unconditional jump(wide index).
0xc9 jsr_w jumps to the specified 32-bit address offset position, and pushes the address of the next instruction of jsr_w onto the top of the stack.
Reserve instruction
0xca breakpoint The breakpoint flag when debugging.
0xfe impdep1 Language backdoor for use in specific hardware.
0xff impdep1 Language backdoor for use in specific hardware.
```