Java Virtual Machine Online Instruction Reference对每个虚拟机指令都有更详细的说明,并配有示例,非常的易于理解,每个指令可以参考这份文档进行学习。
下面按虚拟机指令的作用类型分成以下几大组,每个指令上的链接指向官网说明文档。
Data Operations
The Stack
Pushing constants onto the stack
| opcode | Description |
|---|---|
| bipush | Push a signed byte. |
| sipush | Push a signed word. |
| ldc | Push a single word constant. |
| ldc_w | Push a single word constant. (16-bit ref in constant pool) |
| ldc2_w | Push a double word constant. |
| aconst_null | Push the null object. |
| iconst_m1 | Push integer -1. |
| iconst_i | Integers i = 0..5. |
| lconst_l | Longs l = 0..1. |
| fconst_f | Floats f = 0.0..2.0. |
| dconst_d | Doubles d = 0.0..1.0. |
Stack Manipulation
| opcode | Description |
|---|---|
| nop | Do nothing. |
| pop | Pop the top word. |
| pop2 | Pop the top two words. |
| dup | Duplicate the top word to place 2. |
| dup2 | Duplicate the top two words. |
| dup_x1 | Duplicate the top word to place 3. |
| dup2_x1 | Duplicate the top two words to places 4 and 5. |
| dup_x2 | Duplicate the top word to place 4. |
| dup2_x2 | Duplicate the top two words to places 5 and 6. |
| swap | Swap the top two words. |
Local Variables
Push local
| opcode | Description |
|---|---|
| aload | Load object from local variable n |
| aload_n | Load object from local variable n : n = 0..3 |
| dload | Load double from local variable n |
| dload_n | Load double from local variable n : n = 0..3 |
| fload | Load float from local variable n |
| fload_n | Load float from local variable n : n = 0..3 |
| iload | Load integer from local variable n |
| iload_n | Load integer from local variable n : n = 0..3 |
| lload | Load long from local variable n |
| lload_n | Load long from local variable n : n = 0..3 |
Pop stack into local var
| opcode | Description |
|---|---|
| astore | store object in local variable n |
| astore_n | store object in local variable n : n = 0..3 |
| dstore | store double in local variable n |
| dstore_n | store double in local variable n : n = 0..3 |
| fstore | store float in local variable n |
| fstore_n | store float in local variable n : n = 0..3 |
| istore | store integer in local variable n |
| istore_n | store integer in local variable n : n = 0..3 |
| lstore | store long in local variable n |
| lstore_n | store long in local variable n : n = 0..3 |
Arrays
Creating arrays
| opcode | Description |
|---|---|
| newarray | New array of primitive type |
| anewarray | New array of objects |
| multianewarray | New multidimensional array |
Pushing array values
| opcode | Description |
|---|---|
| aaload | Push object from array. |
| baload | Push byte or boolean from array. |
| caload | Push char from array. |
| daload | Push double from array. |
| faload | Push float from array. |
| iaload | Push integer from array. |
| laload | Push long from array. |
| saload | Push short from array. |
Storing values in arrays
| opcode | Description |
|---|---|
| aastore | Store object in array. |
| bastore | Store byte or boolean in array. |
| castore | Store char in array. |
| dastore | Store double in array. |
| fastore | Store float in array. |
| iastore | Store integer in array. |
| lastore | Store long in array. |
| sastore | Store short in array. |
Objects
| opcode | Description |
|---|---|
| arraylength | Get length of array. |
| new | Allocate mem for object. |
| putfield | Store an instance variable. |
| getfield | Push an instance variable. |
| putstatic | Store a static object's variable. |
| getstatic | Push a static object's variable. |
| checkcast | Checks object type of stack top. |
| instanceof | Checks object's class. |
Transformations
Arithmetic
| opcode | Description |
|---|---|
| iinc | Increment local var. |
| dadd | Add two doubles. |
| fadd | Add two floats. |
| iadd | Add two integers. |
| ladd | Add two longs. |
| dsub | Subtract two doubles. |
| fsub | Subtract two floats. |
| isub | Subtract two integers. |
| lsub | Subtract two longs. |
| dmul | Multiply two doubles. |
| fmul | Multiply two floats. |
| imul | Multiply two integers. |
| lmul | Multiply two longs. |
| ddiv | Divide two doubles. |
| fdiv | Divide two floats. |
| idiv | Divide two integers. |
| ldiv | Divide two longs. |
| drem | Take remainder of two doubles. |
| frem | Take remainder of two floats. |
| irem | Take remainder of two integers. |
| lrem | Take remainder of two longs. |
| dneg | Negate a double. |
| fneg | Negate a float. |
| ineg | Negate a integer. |
| lneg | Negate a long. |
Bit Operations
| opcode | Description |
|---|---|
| ishl | shift integer left |
| ishr | shift integer right |
| iushr | shift integer right without regard to sign |
| lshl | shift long left |
| lshr | shift long righ |
| lushr | shift long right without regard to sign |
| iand | and two integers |
| land | and two longs |
| ior | or two integers |
| lor | or two longs |
| ixor | exclusive or two integers |
| lxor | exclusive or two longs |
Type Conversions
| opcode | Description |
|---|---|
| i2l | integer to long |
| i2f | integer to float |
| i2d | integer to double |
| i2b | integer to byte |
| i2s | integer to short |
| i2c | integer to char |
| l2i | long to integer |
| l2f | long to float |
| l2d | long to double |
| f2i | float to integer |
| f2l | float to long |
| f2d | float to double |
| d2i | double to integer |
| d2l | double to long |
| d2f | double to float |
Process Control
Transfer
Conditional Branching
| opcode | Description |
|---|---|
| ifeq | branch if equal |
| ifne | branch if not equal |
| iflt | branch if less than |
| ifle | branch if less than or equal |
| ifgt | branch if greater than |
| ifge | branch if greater than or equal |
| ifnull | branch if null |
| ifnonnull | branch if not null |
| if_icmpeq | branch if two ints are equal |
| if_icmpne | branch if two ints are not equal |
| if_icmplt | branch if int2 less than int1 |
| if_icmple | branch if int2 less than or equal to int1 |
| if_icmpgt | branch if int2 greater than int1 |
| if_icmpge | branch if int2 greater than or equal to int1 |
| if_acmpeq | branch if references are equal |
| if_acmpne | branch if references are uneqal |
Comparisons
| opcode | Description |
|---|---|
| lcmp | compare two longs |
| fcmpl | compare two floats (-1 on NaN) |
| fcmpg | compare two floats (1 on NaN) |
| dcmpl | compare two doubles (-1 on NaN) |
| dcmpg | compare two doubles (1 on NaN) |
Unconditional Branches
| opcode | Description |
|---|---|
| goto | go to label |
| goto_w | go to label (wide address) |
| jsr | jump to subroutine |
| jsr_w | jump to subroutine (wide address) |
| ret | return from subroutine |
Tables
| opcode | Description |
|---|---|
| lookupswitch | case statement equivalent |
| tableswitch | branch by range of values |
Methods
| opcode | Description |
|---|---|
| invokeinterface | call interface method |
| invokespecial | call method in a specific class |
| invokestatic | call a static method |
| invokevirtual | call any other method |
| ireturn | return from method with integer |
| lreturn | return from method with long |
| freturn | return from method with float |
| dreturn | return from method with double |
| areturn | return from method with object |
| return | return from method with nothing |
Miscellany
| opcode | Description |
|---|---|
| athrow | throw exception |
| breakpoint | used for debugging |
| wide | used for 2-word address or value |
| monitorenter | begin sychronization |
| monitorexit | end sychronization |