As to undertake

If you haven’t read the first chapter, please refer to the following article: ☕【JVM principles explore 】class bytecode instruction operation introduction (part 1)

Introduction to thread stack

  • Each thread has a stack to hold frames. Create a frame for each method call. A frame consists of three core parts: an operation stack, a local array of variables, and a constant pool reference to the class to which the current method belongs.

  • An array of local variables, also known as a local variable table, contains the parameters of a method and is also used to hold the values of some local variables.

    • Parameter values are always stored at the beginning of index0 in the local variable array. If the current frame is created by a constructor or instance method, the object reference (this) will be stored at location0 before the rest of the parameters are stored.

    • The size of a local variable table is determined at compile time and also depends on the number of local variables and the size of some methods.

  • The operation stack is a (LIFO) stack for pushing and pulling values, the size of which is also determined at compile time. Some Opcode instructions push values onto the operation stack (DUP), while others take operands off the stack (pop, swap).

    • Use them and push the results onto the stack. The action stack is also used to receive values returned from the method.

Complete JVM instruction set

The following three reserved opcodes are reserved for internal use by VMS.

  • 0xCa BreakPoint Indicates a breakpoint during debugging
  • 0xfe Impdep1 Language backdoor reserved for specific software
  • 0xFF Impdep2 Language backdoor reserved for specific hardware

The following is a list of all JVM instruction sets, which may vary from one to another. See the Java Virtual Machine Specification (JavaSE8 Edition)

  • Instruction code mnemonic description

  • 0x00 NOp No operation

  • 0x01 ACONST_NULL Pushes NULL to the top of the stack

  • 0x02 Iconst_M1 pushes int -1 to the top of the stack

  • 0x03 IconST_0 pushes int 0 to the top of the stack

  • 0x04 IconST_1 pushes int 1 to the top of the stack

  • 0x05 iconST_2 pushes int 2 to the top of the stack

  • 0x06 iconST_3 pushes int 3 to the top of the stack

  • 0x07 iconST_4 pushes int 4 to the top of the stack

  • 0x08 iconST_5 pushes int 5 to the top of the stack


  • 0x09 lCONST_0 pushes long 0 to the top of the stack
  • 0x0a LCONST_1 pushes long 1 to the top of the stack

  • 0x0b fCONST_0 pushes type float 0 to the top of the stack
  • 0x0c FCONST_1 pushes type float 1 to the top of the stack
  • 0x0d fCONST_2 pushes type float 2 to the top of the stack

  • 0x0e dCONST_0 pushes double 0 to the top of the stack
  • 0x0f dCONST_1 pushes double 1 to the top of the stack

  • 0x10 BiPush pushes single-byte constant values (-128 to 127) to the top of the stack
  • 0x11 siPush pushes a short integer constant value (-32768 to 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 a 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 local variable of type float 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 pushes the first local variable of int to the top of the stack
  • 0x1b ILoAD_1 pushes the second local variable of int to the top of the stack
  • 0x1c ILoAD_2 pushes the third int local variable to the top of the stack
  • 0x1D ILoAD_3 pushes the fourth local variable 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 pushes 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 pushes the first local variable of type float to the top of the stack
  • 0x23 FLOAD_1 pushes the second local variable of type float to the top of the stack
  • 0x24 FLOad_2 pushes the third local variable of type float to the top of the stack
  • 0x25 FLOad_3 pushes the fourth local variable of type float to the top of the stack

  • 0x26 dload_0 pushes the first double local variable to the top of the stack
  • 0x27 Dload_1 pushes the second local variable of type double to the top of the stack
  • 0x28 dload_2 pushes the third double local variable to the top of the stack
  • 0x29 Dload_3 pushes the fourth local variable of type double to the top of the stack

  • 0x2a ALOad_0 pushes the first reference type local variable 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 pushes the third reference type local variable to the top of the stack
  • 0x2D ALOAD_3 pushes the fourth reference type local variable to the top of the stack

  • 0x2e iALOad pushes the value of the specified index of an 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 referenced array’s specified index to the top of the stack
  • 0x33 BaloAD pushes the value of the Boolean or Byte array specified index to the top of the stack
  • 0x34 caload pushes the value of the char array’s specified index 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 top of the stack int value into the specified local variable
  • 0x37 lStore stores the top of the stack long value into the specified local variable
  • 0x38 FStore stores the top stack float value to the specified local variable
  • 0x39 DStore stores the top of stack double into the specified local variable
  • 0x3a astore stores the top of stack reference value into the specified local variable

  • 0x3b istORE_0 stores the top-stack int value into the first local variable
  • 0x3c istore_1 stores the top-stack int value into the second local variable
  • 0x3D istore_2 stores the top int value into the third local variable
  • 0x3e istore_3 stores the top-stack int value into the fourth local variable

  • 0x3f lstore_0 stores the top-stack long value into the first local variable
  • 0x40 lstore_1 stores the top-stack long value into the second local variable
  • 0x41 lstore_2 stores the top-stack long value into the third local variable
  • 0x42 lStore_3 Stores the top-stack long value into the fourth local variable

  • 0x43 fstore_0 stores the top stack float value into the first local variable
  • 0x44 fstore_1 stores the top stack float value into the second local variable
  • 0x45fstore_2 stores the top stack float value into the third local variable
  • 0x46fstore_3 stores the top stack float value into the fourth local variable

  • 0x47 dstore_0 stores the top-stack double into the first local variable
  • 0x48 dstore_1 stores the top double into the second local variable
  • 0x49 dstore_2 stores the top double into the third local variable
  • 0x4a dstore_3 stores the top double into the fourth local variable

  • 0x4b astore_0 stores the top of the stack reference value into the first local variable
  • 0x4c astore_1 stores the top of the stack reference value into the second local variable
  • 0x4d astore_2 stores the top of the stack reference value into the third local variable
  • 0x4e astore_3 stores the top of stack reference value into the fourth local variable

  • 0x4f iastore stores the top int into the specified index position of the specified array
  • 0x50 laStore stores the top long value in the specified index position of the specified array
  • 0x51 FAStore stores the top float value into the specified index position of the specified array
  • 0x52 Dastore stores the top double at the specified index of the specified array
  • 0x53 aastore stores the top of stack reference value at the specified index position of the specified array
  • 0x54 Bastore stores a stack top Boolean or Byte value at a specified index location in a specified array
  • 0x55 Castore stores the char value at the top of the stack at the specified index of the specified array
  • 0x56 sastore stores the top short value to the specified index position of the specified array

  • 0x57 pop Pops the top value of the stack (value cannot be long or double)
  • 0x58 POP2 Pops one (long or double) or two values at the top of the stack (other values)

  • 0x59 DUP copies the top value of the stack and pushes it to the top
  • 0x5a dup_x1 copies the top value of the stack and pushes the two copies to the top
  • 0x5b dup_x2 copies the top value of the stack and pushes three (or two) copies to the top of the stack
  • 0x5c dup2 Copies one (long or double) or two (other) values to the top of the stack and pushes the copied values to the top
  • 0x5d dup2_x1 copies one or two values at the top of the stack and inserts them below the two or three values at the top of the stack
  • 0x5e dup2_x2 copies one or two values at the top of the stack and inserts them below the two, three, or four values at the top

  • 0x5f swap swaps two values at the top of the stack (values cannot be long or double)

  • 0x60 iAdd adds the top two int values and pushes the result to the top of the stack
  • 0x61 lAdd adds the top two longs and pushes the result to the top of the stack
  • 0x62 FAdd adds two float values at the top of the stack and pushes the result to the top of the stack
  • 0x63 DAdd adds the top two double values and pushes the result to the top of the stack

  • 0x64 ISub subtracts the top two int values and pushes the result to the top of the stack
  • 0x65 lSub subtracts the top two longs and pushes the result to the top of the stack
  • 0x66 fSub subtracts the top two float values and pushes the result to the top of the stack
  • 0x67 DSub subtracts the top double and pushes the result to the top of the stack

  • 0x68 IMul multiplies the top two int values and pushes the result to the top of the stack
  • 0x69 lMUL multiplies the top two longs and pushes the result to the top of the stack
  • 0x6a fMUl multiplies the top two float values and pushes the result to the top of the stack
  • 0x6b dmul multiplies the top two double values and pushes the result to the top of the stack

  • 0x6c IDIV Divides the top two int values and pushes the result to the top of the stack
  • 0x6d ldiv divides the top two longs and pushes the result to the top of the stack
  • 0x6e fdiv divides the top two float values and pushes the result to the top of the stack
  • 0x6f ddiv divides the top two double values and pushes the result to the top of the stack

  • 0x70 IREM performs modular operations on the two int values at the top of the stack and pushes the results to the top of the stack
  • 0x71 LREM performs modular operation on the top two longs and pushes the result to the top of the stack
  • 0x72 frem modulates the top two float values and pushes the result to the top of the stack
  • 0x73 DREM takes the modulus operation of the two double values at the top of the stack and pushes the result to the top of the stack

  • 0x74 INEG Takes a negative value of int at the top of the stack and pushes the result to the top
  • 0x75 lneg takes the top long value negative and pushes the result to the top of the stack
  • 0x76 Fneg takes the top float value negative and pushes the result to the top of the stack
  • 0x77 dneg takes the top double negative and pushes the result to the top of the stack

  • 0x78 ishL shifts the value of int to the left by the specified number of digits and pushes the result to the top of the stack
  • 0x79 LSHL shifts the long value left by the specified number of digits and pushes the result to the top of the stack
  • 0x7a ishr shifts the value of int by the specified number of digits and pushes the result to the top of the stack
  • 0x7b LSHR shifts the long value right (symbol) by the specified number of digits and pushes the result to the top of the stack

  • 0x7c iushr shifts the value of int to the right (unsigned) by the specified number of digits and pushes the result to the top of the stack
  • 0x7d Lushr shifts the long value right (unsigned) by the specified number of digits and pushes the result to the top of the stack

  • 0x7e iAND pushes the result to the top of the stack by “bitwise and”
  • 0x7f land “bitwise sum” the top two longs and pushes the result to the top of the stack
  • 0x80 Ior uses the two int values at the top of the stack as bitwise or and pushes the result to the top of the stack
  • 0x81 LOR sets the two longs at the top of the stack as “bitwise or” and pushes the result to the top of the stack
  • 0x82 IXOR pushes the result to the top of the stack as “bitwise xor” for the top two int values
  • 0x83 lxor pushes the result to the top of the stack as “bitwise xor”
  • 0x84 iInc increments the specified value of the specified int variable (I ++, I –, I +=2)

  • 0x85 i2L casts a top int value to a long value and pushes the result to the top of the stack
  • 0x86 i2f casts a top-stack int value to a float value and pushes the result to the top of the stack
  • 0x87 I2D casts a top int to a double and pushes the result to the top of the stack
  • 0x88 L2I casts the top long value to an int value and pushes the result to the top of the stack
  • 0x89 L2F casts the top long value to a float value and pushes the result to the top of the stack
  • 0x8a l2D casts the top of the stack long to a double and pushes the result to the top of the stack
  • 0x8b f2i casts a top float value to an int value and pushes the result to the top of the stack
  • 0x8c f2L casts a top float value to a long value and pushes the result to the top of the stack
  • 0x8d F2D casts a top float value to a double and pushes the result to the top of the stack
  • 0x8e d2i casts a top double to an int and pushes the result to the top of the stack
  • 0x8fd2l casts the top double to the top long and pushes the result to the top of the stack
  • 0x90 D2f casts a top double value to a float value and pushes the result to the top of the stack
  • 0x91 i2b casts a stack top int value to a byte value and pushes the result to the top of the stack
  • 0x92 i2c casts the top int value to a char value and pushes the result to the top of the stack
  • 0x93 i2s casts the top int to the top short and pushes the result to the top of the stack

  • 0x94 LCMP compares the two long values at the top of the stack and pushes the result (1, 0, -1) to the top of the stack
  • 0x95 FCMPL compares two float values at the top of the stack and pushes the result (1, 0, -1) to the top of the stack; When one of the values is NaN, -1 is pushed to the top of the stack
  • 0x96 FCMPG compares two float values at the top of the stack and pushes the result (1, 0, -1) to the top of the stack; When one of the values is NaN, push 1 to the top of the stack
  • 0x97 DCMPL compares two double values at the top of the stack and pushes the result (1, 0, -1) to the top of the stack; When one of the values is NaN, -1 is pushed to the top of the stack
  • 0x98 DCMPG compares the two double values at the top of the stack and pushes the result (1, 0, -1) to the top of the stack; When one of the values is NaN, push 1 to the top of the stack
  • 0x99 iFeQ Jumps if the top int value equals 0
  • 0x9a ifNe Indicates a jump if the value of int at the top of the stack does not equal 0
  • 0x9B iFLT A jump occurs when the value of int at the top of the stack is less than 0
  • 0x9C ifGE Indicates a jump if the value of int at the top of the stack is greater than or equal to 0
  • 0x9d ifgt The value of int at the top of the stack is greater than 0
  • 0x9e ifLe Jumps if the value of int at the top of the stack is less than or equal to 0
  • 0x9f if_ICMPEQ Compares the value of two ints at the top of the stack, jumps if the value equals 0
  • 0xa0 if_icmpne Compares the value of two ints at the top of the stack, and jumps if the value is not equal to 0
  • 0xa1 if_ICMplt Compares two ints at the top of the stack, jumps if the result is less than 0
  • 0xa2 if_ICMPGE Compares two ints at the top of the stack and jumps if the result is greater than or equal to 0
  • 0xa3 if_ICMPgt Compares two ints at the top of the stack, jumps if the result is greater than 0
  • 0xA4 if_icmple Compares two ints at the top of the stack, jumps if the result is less than or equal to 0
  • 0xa5 if_ACMPEQ Compares two reference values at the top of the stack and jumps if the result is equal
  • 0xa6 if_ACmpne Compares two referential values at the top of the stack and jumps if the results are not equal
  • 0xa7 goto Indicates an unconditional jump
  • 0xa8 JSR jumps to the specified 16-bit offset and pushes the address of the next JSR instruction to the top of the stack
  • 0xa9 ret Returns the instruction location of the index specified by the local variable (usually used in conjunction with JSR, jSR_w)
  • 0xAA tablesWITCH Switch Conditional jump, case value continuous (variable length instruction)
  • 0xAB lookupSwitch Used for switch conditional jump, case value discontinuous (variable length instruction)
  • 0xAC iReturn Returns an int from the current method
  • 0xad lReturn Returns long from the current method
  • 0xAE Freturn returns float from the current method
  • 0xaf dreturn returns 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 gets the static field of the specified class and pushes its value to the top of the stack
  • 0xB3 PutStatic Assigns a value to the static field of the specified class
  • 0xB4 getField gets the instance field of the specified class and pushes its value to the top of the stack
  • 0xB5 putField Assigns a value to the instance field of the specified class

  • 0xb6 Invokevirtual calls the instance method
  • 0xB7 Invokespecial calls the superclass constructor, instance initialization method, private method
  • 0xb8 InvokeStatic invokes static methods
  • 0xB9 InvokeInterface invokes the interface method
  • 0xba InvokeDynamic invokes the dynamic link method

  • 0xbb New Creates an object and pushes its reference value to the top of the stack
  • 0xbc newarray creates a specified primitive type (e.g. Int, float, char…) And push its reference values to the top of the stack
  • 0xBd AneWarRay Creates an array of references (such as classes, interfaces, arrays) and pushes its reference values to the top of the stack
  • 0xBE ArrayLength gets the length of the array and pushes it to the top of the stack

  • 0xbf athrow throws the exception at the top of the stack
  • 0xC0 checkCast checks the conversion and a ClassCastException is thrown if the check fails
  • 0xc1 instanceof checks if the object is an instanceof the specified class, pushing 1 to the top of the stack, and 0 to the top otherwise

  • 0xc2 Monitorenter Acquires the lock of an object and uses it to synchronize methods or blocks
  • 0xC3 MonitoreXit Releases locks on objects for synchronizing methods or blocks

  • 0xC4 Wide Widths the local variable index
  • 0xC5 Multianewarray creates a multidimensional array of the specified type and dimension (to execute this instruction, the operation stack must contain the length values for each dimension) and pushes its reference values to the top of the stack
  • 0xC6 Indicates a jump if ifNULL is NULL
  • 0xC7 IfnonNULL Indicates a jump if the value is not NULL
  • 0xC8 goTO_w Indicates an unconditional jump
  • 0xC9 JSR_w jumps to the specified 32-bit offset position and pushes the address of the next jSR_W instruction to the top of the stack
  • 0xCa BreakPoint Indicates a breakpoint during debugging
  • 0xfe Impdep1 Language backdoor reserved for specific software
  • 0xFF Impdep2 Language backdoor reserved for specific hardware