The JVM instruction set

All 205 opcodes of the Java Virtual Machine: what each does to the operand stack, how it is encoded, how often javac uses it, and a real example of each.

The JVM is a stack machine. Instructions take their inputs from an operand stack and push their results back; local variables, including this and the parameters, live in numbered slots. Each opcode is one byte, and most carry their type in their name: iadd adds ints, dadd doubles, aload loads a reference. byte, short, char and boolean have almost no instructions of their own: on the stack they are ints.

The counts come from parsing every one of the 7,391 classes in JDK 25.0.5's java.base module: 66,382 methods and 1,951,129 instructions. The ten most common are aload_0 (7.4%), dup (7.4%), invokevirtual (6.1%), bipush (4.6%), getfield (3.8%), aastore (3.5%), aload_1 (3.2%), aload (3.1%), ldc_w (2.8%), invokestatic (2.7%). Together they are 44.6% of all bytecode. 8 opcodes are never used at all: nop, fstore_0, swap, frem, jsr, ret, goto_w, jsr_w.

Jump to: Constants · Loads · Stores · Arrays · Stack manipulation · Arithmetic and bitwise · Conversions · Comparisons · Branches and switches · Returns · Fields · Method calls · Objects and types · Monitors · Other

Constants 20

Push a constant onto the operand stack. Small values have their own one-byte instructions; bigger ones come from an operand or the constant pool.

HexInstructionStackWhat it doesIn java.base
0x01aconst_null… → …, nullPushes null.9,304
0x02iconst_m1… → …, -1 (int)Pushes the int constant -1.3,740
0x03iconst_0… → …, 0 (int)Pushes the int constant 0.45,662
0x04iconst_1… → …, 1 (int)Pushes the int constant 1.39,832
0x05iconst_2… → …, 2 (int)Pushes the int constant 2.20,715
0x06iconst_3… → …, 3 (int)Pushes the int constant 3.6,091
0x07iconst_4… → …, 4 (int)Pushes the int constant 4.5,561
0x08iconst_5… → …, 5 (int)Pushes the int constant 5.3,914
0x09lconst_0… → …, 0 (long)Pushes the long constant 0.2,402
0x0alconst_1… → …, 1 (long)Pushes the long constant 1.987
0x0bfconst_0… → …, 0 (float)Pushes the float constant 0.40
0x0cfconst_1… → …, 1 (float)Pushes the float constant 1.41
0x0dfconst_2… → …, 2 (float)Pushes the float constant 2.10
0x0edconst_0… → …, 0 (double)Pushes the double constant 0.163
0x0fdconst_1… → …, 1 (double)Pushes the double constant 1.108
0x10bipush… → …, value (int)Pushes a byte, sign-extended to int.89,187
0x11sipush… → …, value (int)Pushes a short, sign-extended to int.34,361
0x12ldc… → …, valuePushes a constant from the constant pool (index in one byte).41,535
0x13ldc_w… → …, valuePushes a constant from the constant pool (index in two bytes).54,903
0x14ldc2_w… → …, value (long or double)Pushes a long or double constant from the constant pool.9,670

Loads 25

Copy a local variable onto the operand stack. Slots 0 to 3 have one-byte forms; other slots take an operand.

HexInstructionStackWhat it doesIn java.base
0x15iload… → …, value (int)Pushes the int in local variable (operand).45,311
0x16lload… → …, value (long)Pushes the long in local variable (operand).14,779
0x17fload… → …, value (float)Pushes the float in local variable (operand).287
0x18dload… → …, value (double)Pushes the double in local variable (operand).1,179
0x19aload… → …, value (reference)Pushes the reference in local variable (operand).60,166
0x1aiload_0… → …, value (int)Pushes the int in local variable 0.3,941
0x1biload_1… → …, value (int)Pushes the int in local variable 1.15,276
0x1ciload_2… → …, value (int)Pushes the int in local variable 2.16,309
0x1diload_3… → …, value (int)Pushes the int in local variable 3.13,244
0x1elload_0… → …, value (long)Pushes the long in local variable 0.1,027
0x1flload_1… → …, value (long)Pushes the long in local variable 1.2,828
0x20lload_2… → …, value (long)Pushes the long in local variable 2.3,170
0x21lload_3… → …, value (long)Pushes the long in local variable 3.1,949
0x22fload_0… → …, value (float)Pushes the float in local variable 0.135
0x23fload_1… → …, value (float)Pushes the float in local variable 1.158
0x24fload_2… → …, value (float)Pushes the float in local variable 2.157
0x25fload_3… → …, value (float)Pushes the float in local variable 3.143
0x26dload_0… → …, value (double)Pushes the double in local variable 0.509
0x27dload_1… → …, value (double)Pushes the double in local variable 1.297
0x28dload_2… → …, value (double)Pushes the double in local variable 2.358
0x29dload_3… → …, value (double)Pushes the double in local variable 3.201
0x2aaload_0… → …, value (reference)Pushes the reference in local variable 0.145,030
0x2baload_1… → …, value (reference)Pushes the reference in local variable 1.63,228
0x2caload_2… → …, value (reference)Pushes the reference in local variable 2.34,470
0x2daload_3… → …, value (reference)Pushes the reference in local variable 3.22,341

Stores 25

Pop the top of the operand stack into a local variable.

HexInstructionStackWhat it doesIn java.base
0x36istore…, value (int) → …Pops a int into local variable (operand).19,144
0x37lstore…, value (long) → …Pops a long into local variable (operand).7,710
0x38fstore…, value (float) → …Pops a float into local variable (operand).54
0x39dstore…, value (double) → …Pops a double into local variable (operand).491
0x3aastore…, value (reference) → …Pops a reference into local variable (operand).26,719
0x3bistore_0…, value (int) → …Pops a int into local variable 0.260
0x3cistore_1…, value (int) → …Pops a int into local variable 1.2,043
0x3distore_2…, value (int) → …Pops a int into local variable 2.4,586
0x3eistore_3…, value (int) → …Pops a int into local variable 3.4,445
0x3flstore_0…, value (long) → …Pops a long into local variable 0.86
0x40lstore_1…, value (long) → …Pops a long into local variable 1.340
0x41lstore_2…, value (long) → …Pops a long into local variable 2.576
0x42lstore_3…, value (long) → …Pops a long into local variable 3.484
0x43fstore_0…, value (float) → …Pops a float into local variable 0.0
0x44fstore_1…, value (float) → …Pops a float into local variable 1.7
0x45fstore_2…, value (float) → …Pops a float into local variable 2.6
0x46fstore_3…, value (float) → …Pops a float into local variable 3.19
0x47dstore_0…, value (double) → …Pops a double into local variable 0.26
0x48dstore_1…, value (double) → …Pops a double into local variable 1.17
0x49dstore_2…, value (double) → …Pops a double into local variable 2.62
0x4adstore_3…, value (double) → …Pops a double into local variable 3.36
0x4bastore_0…, value (reference) → …Pops a reference into local variable 0.1,796
0x4castore_1…, value (reference) → …Pops a reference into local variable 1.5,553
0x4dastore_2…, value (reference) → …Pops a reference into local variable 2.8,282
0x4eastore_3…, value (reference) → …Pops a reference into local variable 3.7,267

Arrays 20

Create arrays, read and write their elements, and get their length. Every element access checks for null and for an index out of bounds.

HexInstructionStackWhat it doesIn java.base
0x2eiaload…, arrayref, index → …, value (int)Pops an array and an index; pushes the int element.2,558
0x2flaload…, arrayref, index → …, value (long)Pops an array and an index; pushes the long element.7,327
0x30faload…, arrayref, index → …, value (float)Pops an array and an index; pushes the float element.154
0x31daload…, arrayref, index → …, value (double)Pops an array and an index; pushes the double element.351
0x32aaload…, arrayref, index → …, value (reference)Pops an array and an index; pushes the reference element.8,966
0x33baload…, arrayref, index → …, value (int)Pops an array and an index; pushes the byte or boolean element.2,502
0x34caload…, arrayref, index → …, value (int)Pops an array and an index; pushes the char element.749
0x35saload…, arrayref, index → …, value (int)Pops an array and an index; pushes the short element.164
0x4fiastore…, arrayref, index, value (int) → …Pops an array, an index and a int value; stores the value in the array.14,312
0x50lastore…, arrayref, index, value (long) → …Pops an array, an index and a long value; stores the value in the array.2,949
0x51fastore…, arrayref, index, value (float) → …Pops an array, an index and a float value; stores the value in the array.102
0x52dastore…, arrayref, index, value (double) → …Pops an array, an index and a double value; stores the value in the array.1,272
0x53aastore…, arrayref, index, value (reference) → …Pops an array, an index and a reference value; stores the value in the array.67,452
0x54bastore…, arrayref, index, value (int) → …Pops an array, an index and a byte or boolean value; stores the value in the array.22,081
0x55castore…, arrayref, index, value (int) → …Pops an array, an index and a char value; stores the value in the array.1,280
0x56sastore…, arrayref, index, value (int) → …Pops an array, an index and a short value; stores the value in the array.3,244
0xbcnewarray…, count (int) → …, arrayrefPops a length; pushes a new array of a primitive type.3,063
0xbdanewarray…, count (int) → …, arrayrefPops a length; pushes a new array of references.19,330
0xbearraylength…, arrayref → …, length (int)Pops an array; pushes its length.6,694
0xc5multianewarray…, count1, count2, … → …, arrayrefPops several lengths; pushes a new multi-dimensional array.17

Stack manipulation 9

Discard, duplicate and swap values on the operand stack without looking at their types. Long and double values take two slots, which is why the dup2 forms exist.

HexInstructionStackWhat it doesIn java.base
0x57pop…, value → …Discards the top stack slot.15,497
0x58pop2…, value2, value1 → …Discards the top two stack slots (or one long or double).130
0x59dup…, value → …, value, valueDuplicates the top of the stack.144,789
0x5adup_x1…, value2, value1 → …, value1, value2, value1Duplicates the top value and inserts it two slots down.868
0x5bdup_x2…, value3, value2, value1 → …, value1, value3, value2, value1Duplicates the top value and inserts it three slots down.57
0x5cdup2…, value2, value1 → …, value2, value1, value2, value1Duplicates the top two slots (or one long or double).1,462
0x5ddup2_x1…, value3, value2, value1 → …, value2, value1, value3, value2, value1Duplicates the top two slots and inserts them three slots down.34
0x5edup2_x2…, value4, value3, value2, value1 → …, value2, value1, value4, value3, value2, value1Duplicates the top two slots and inserts them four slots down.1
0x5fswap…, value2, value1 → …, value1, value2Swaps the top two values.0

Arithmetic and bitwise 37

Arithmetic, shifts and bitwise operations on int, long, float and double. There are no byte, short, char or boolean versions: those values are ints on the stack.

HexInstructionStackWhat it doesIn java.base
0x60iadd…, value1 (int), value2 (int) → …, result (int)Adds two ints on top of the stack; pushes the result.8,545
0x61ladd…, value1 (long), value2 (long) → …, result (long)Adds two longs on top of the stack; pushes the result.7,549
0x62fadd…, value1 (float), value2 (float) → …, result (float)Adds two floats on top of the stack; pushes the result.10
0x63dadd…, value1 (double), value2 (double) → …, result (double)Adds two doubles on top of the stack; pushes the result.296
0x64isub…, value1 (int), value2 (int) → …, result (int)Subtracts two ints on top of the stack; pushes the result.6,194
0x65lsub…, value1 (long), value2 (long) → …, result (long)Subtracts two longs on top of the stack; pushes the result.1,631
0x66fsub…, value1 (float), value2 (float) → …, result (float)Subtracts two floats on top of the stack; pushes the result.3
0x67dsub…, value1 (double), value2 (double) → …, result (double)Subtracts two doubles on top of the stack; pushes the result.255
0x68imul…, value1 (int), value2 (int) → …, result (int)Multiplies two ints on top of the stack; pushes the result.1,140
0x69lmul…, value1 (long), value2 (long) → …, result (long)Multiplies two longs on top of the stack; pushes the result.4,632
0x6afmul…, value1 (float), value2 (float) → …, result (float)Multiplies two floats on top of the stack; pushes the result.43
0x6bdmul…, value1 (double), value2 (double) → …, result (double)Multiplies two doubles on top of the stack; pushes the result.466
0x6cidiv…, value1 (int), value2 (int) → …, result (int)Divides two ints on top of the stack; pushes the result.485
0x6dldiv…, value1 (long), value2 (long) → …, result (long)Divides two longs on top of the stack; pushes the result.266
0x6efdiv…, value1 (float), value2 (float) → …, result (float)Divides two floats on top of the stack; pushes the result.10
0x6fddiv…, value1 (double), value2 (double) → …, result (double)Divides two doubles on top of the stack; pushes the result.96
0x70irem…, value1 (int), value2 (int) → …, result (int)Takes the remainder of two ints on top of the stack; pushes the result.326
0x71lrem…, value1 (long), value2 (long) → …, result (long)Takes the remainder of two longs on top of the stack; pushes the result.173
0x72frem…, value1 (float), value2 (float) → …, result (float)Takes the remainder of two floats on top of the stack; pushes the result.0
0x73drem…, value1 (double), value2 (double) → …, result (double)Takes the remainder of two doubles on top of the stack; pushes the result.1
0x74ineg…, value (int) → …, result (int)Negates the int on top of the stack.279
0x75lneg…, value (long) → …, result (long)Negates the long on top of the stack.157
0x76fneg…, value (float) → …, result (float)Negates the float on top of the stack.7
0x77dneg…, value (double) → …, result (double)Negates the double on top of the stack.47
0x78ishl…, value1 (int), value2 (int) → …, result (int)Shifts left two ints on top of the stack; pushes the result.1,122
0x79lshl…, value1 (long), value2 (int) → …, result (long)Shifts left two longs on top of the stack; pushes the result.2,125
0x7aishr…, value1 (int), value2 (int) → …, result (int)Arithmetic-shifts right two ints on top of the stack; pushes the result.973
0x7blshr…, value1 (long), value2 (int) → …, result (long)Arithmetic-shifts right two longs on top of the stack; pushes the result.1,536
0x7ciushr…, value1 (int), value2 (int) → …, result (int)Logical-shifts right two ints on top of the stack; pushes the result.861
0x7dlushr…, value1 (long), value2 (int) → …, result (long)Logical-shifts right two longs on top of the stack; pushes the result.429
0x7eiand…, value1 (int), value2 (int) → …, result (int)Bitwise ANDs two ints on top of the stack; pushes the result.3,706
0x7fland…, value1 (long), value2 (long) → …, result (long)Bitwise ANDs two longs on top of the stack; pushes the result.1,718
0x80ior…, value1 (int), value2 (int) → …, result (int)Bitwise ORs two ints on top of the stack; pushes the result.2,115
0x81lor…, value1 (long), value2 (long) → …, result (long)Bitwise ORs two longs on top of the stack; pushes the result.397
0x82ixor…, value1 (int), value2 (int) → …, result (int)Bitwise XORs two ints on top of the stack; pushes the result.998
0x83lxor…, value1 (long), value2 (long) → …, result (long)Bitwise XORs two longs on top of the stack; pushes the result.317
0x84iinc… → …Adds a signed constant to an int local variable, without touching the stack.7,076

Conversions 15

Convert the value on top of the stack between primitive types: widening (int to long), narrowing (double to int) and the int-to-small-type casts.

HexInstructionStackWhat it doesIn java.base
0x85i2l…, value (int) → …, result (long)Converts the int on top of the stack to long.3,037
0x86i2f…, value (int) → …, result (float)Converts the int on top of the stack to float.65
0x87i2d…, value (int) → …, result (double)Converts the int on top of the stack to double.92
0x88l2i…, value (long) → …, result (int)Converts the long on top of the stack to int.963
0x89l2f…, value (long) → …, result (float)Converts the long on top of the stack to float.14
0x8al2d…, value (long) → …, result (double)Converts the long on top of the stack to double.72
0x8bf2i…, value (float) → …, result (int)Converts the float on top of the stack to int.39
0x8cf2l…, value (float) → …, result (long)Converts the float on top of the stack to long.5
0x8df2d…, value (float) → …, result (double)Converts the float on top of the stack to double.29
0x8ed2i…, value (double) → …, result (int)Converts the double on top of the stack to int.45
0x8fd2l…, value (double) → …, result (long)Converts the double on top of the stack to long.33
0x90d2f…, value (double) → …, result (float)Converts the double on top of the stack to float.12
0x91i2b…, value (int) → …, result (int)Converts the int on top of the stack to byte.2,036
0x92i2c…, value (int) → …, result (int)Converts the int on top of the stack to char.443
0x93i2s…, value (int) → …, result (int)Converts the int on top of the stack to short.229

Comparisons 5

Compare two longs, floats or doubles and push -1, 0 or 1. An int branch then tests the result: there is no single "branch if long less than" instruction.

HexInstructionStackWhat it doesIn java.base
0x94lcmp…, value1 (long), value2 (long) → …, result (int)Compares two longs and pushes -1, 0 or 1.3,104
0x95fcmpl…, value1 (float), value2 (float) → …, result (int)Compares two floats and pushes -1, 0 or 1; NaN gives -1.65
0x96fcmpg…, value1 (float), value2 (float) → …, result (int)Compares two floats and pushes -1, 0 or 1; NaN gives 1.59
0x97dcmpl…, value1 (double), value2 (double) → …, result (int)Compares two doubles and pushes -1, 0 or 1; NaN gives -1.162
0x98dcmpg…, value1 (double), value2 (double) → …, result (int)Compares two doubles and pushes -1, 0 or 1; NaN gives 1.92

Branches and switches 23

Conditional and unconditional jumps, and the two switch instructions. Branch offsets are relative to the branch instruction's own address.

HexInstructionStackWhat it doesIn java.base
0x99ifeq…, value (int) → …Pops an int; jumps if it is equal to zero.21,435
0x9aifne…, value (int) → …Pops an int; jumps if it is not equal to zero.12,832
0x9biflt…, value (int) → …Pops an int; jumps if it is less than zero.1,676
0x9cifge…, value (int) → …Pops an int; jumps if it is greater than or equal to zero.2,002
0x9difgt…, value (int) → …Pops an int; jumps if it is greater than zero.702
0x9eifle…, value (int) → …Pops an int; jumps if it is less than or equal to zero.2,075
0x9fif_icmpeq…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is equal to the second.3,295
0xa0if_icmpne…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is not equal to the second.5,147
0xa1if_icmplt…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is less than the second.1,917
0xa2if_icmpge…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is greater than or equal to the second.5,779
0xa3if_icmpgt…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is greater than the second.1,231
0xa4if_icmple…, value1 (int), value2 (int) → …Pops two ints; jumps if the first is less than or equal to the second.2,267
0xa5if_acmpeq…, value1 (reference), value2 (reference) → …Pops two references; jumps if they are the same object.1,418
0xa6if_acmpne…, value1 (reference), value2 (reference) → …Pops two references; jumps if they are different objects.2,945
0xa7goto… → …Jumps unconditionally.35,040
0xa8jsr… → …, addressJumps to a subroutine, pushing the return address (old finally blocks; not allowed since Java 7 class files).0
0xa9ret… → …Returns from a subroutine to the address in a local variable.0
0xaatableswitch…, index (int) → …Jumps through a table indexed by an int (dense case values).659
0xablookupswitch…, key (int) → …Jumps through sorted match/offset pairs (sparse case values).497
0xc6ifnull…, value (reference) → …Pops a reference; jumps if it is null.9,072
0xc7ifnonnull…, value (reference) → …Pops a reference; jumps if it is not null.6,443
0xc8goto_w… → …Jumps unconditionally (four-byte offset).0
0xc9jsr_w… → …, addressJumps to a subroutine (four-byte offset).0

Returns 6

Return from the current method, with a value of the method's return type or with none.

HexInstructionStackWhat it doesIn java.base
0xacireturn…, value (int) → …, (empty: the frame is gone)Returns the int on top of the stack from the method.17,614
0xadlreturn…, value (long) → …, (empty: the frame is gone)Returns the long on top of the stack from the method.1,825
0xaefreturn…, value (float) → …, (empty: the frame is gone)Returns the float on top of the stack from the method.305
0xafdreturn…, value (double) → …, (empty: the frame is gone)Returns the double on top of the stack from the method.608
0xb0areturn…, value (reference) → …, (empty: the frame is gone)Returns the reference on top of the stack from the method.32,175
0xb1return… → …, (empty: the frame is gone)Returns from a void method.21,097

Fields 4

Read and write static and instance fields, named by a Fieldref constant.

HexInstructionStackWhat it doesIn java.base
0xb2getstatic… → …, valuePushes the value of a static field.43,153
0xb3putstatic…, value → …Pops a value into a static field.8,609
0xb4getfield…, objectref → …, valuePops an object; pushes the value of one of its fields.73,588
0xb5putfield…, objectref, value → …Pops an object and a value; stores the value in the field.24,204

Method calls 5

The five ways to call a method. Arguments are popped from the operand stack, receiver first; the result, if any, is pushed.

HexInstructionStackWhat it doesIn java.base
0xb6invokevirtual…, objectref, arg1, … → …, resultCalls an instance method, chosen by the receiver's class.118,921
0xb7invokespecial…, objectref, arg1, … → …, resultCalls a constructor, a private method or a superclass method directly.43,732
0xb8invokestatic…, arg1, … → …, resultCalls a static method.52,122
0xb9invokeinterface…, objectref, arg1, … → …, resultCalls an interface method, chosen by the receiver's class.25,892
0xbainvokedynamic…, arg1, … → …, resultCalls through a call site that a bootstrap method links on first use (lambdas, string concatenation, records, pattern switches).2,330

Objects and types 4

Allocate objects, test and check their types, and throw them.

HexInstructionStackWhat it doesIn java.base
0xbbnew… → …, objectref (uninitialised)Allocates an object (uninitialised until its constructor runs).33,545
0xbfathrow…, objectref → …, objectrefThrows the exception on top of the stack.16,191
0xc0checkcast…, objectref → …, objectrefChecks that the reference on top of the stack is of a type (throws ClassCastException if not).14,072
0xc1instanceof…, objectref → …, result (int)Pops a reference; pushes 1 if it is of a type, else 0.2,895

Monitors 2

Lock and unlock an object's monitor: the bytecode behind synchronized blocks.

HexInstructionStackWhat it doesIn java.base
0xc2monitorenter…, objectref → …Pops an object and locks its monitor (start of synchronized).959
0xc3monitorexit…, objectref → …Pops an object and unlocks its monitor.2,147

Other 5

An instruction that does nothing, the wide prefix, and the opcodes reserved for debuggers and JVM internals.

HexInstructionStackWhat it doesIn java.base
0x00nop… → …Does nothing.0
0xc4wide… → …Makes the next instruction take a two-byte local index (and a two-byte iinc constant).34
0xcabreakpoint… → …Reserved for debuggers and JVM internals; never valid in a class file.0
0xfeimpdep1… → …Reserved for debuggers and JVM internals; never valid in a class file.0
0xffimpdep2… → …Reserved for debuggers and JVM internals; never valid in a class file.0