JVM Tutorials - Herong's Tutorial Examples - v5.14, by Herong Yang
JVM Instruction Set
This section provides a quick introduction of the JVM instruction set.
What Is JVM Instruction Set? JVM instruction set is a set of instructions for Java virtual machine.
A JVM instruction consists of 4 data components:
Some examples of JVM instructions are given in the table below. Column C. is the opcode (operation code). P. is the count of bytes following the opcode as operation parameters. I. is the count elements consumed from the operand stack as operation input. O. is the count elements added to the operand stack as operation output. "V" in I. or O. columns indicates that the count varies.
Mnemonic C. P. I. O. Description ------------- -- -- -- -- ---------------------------------------- iload_1 1B 0 0 1 Load integer from variable 1 iadd 60 0 2 1 Add 2 integers istore_2 3D 0 1 0 Store integer to variable 2 ireturn AC 0 1 0 Return integer to caller ldc 12 1 0 1 Load a constant with given index ldc_w 13 2 0 1 Load a constant with given wide index invokevirtual B6 2 V V Invoke a method with given reference
The current JVM release supports about 200 instructions as listed below:
C. Mnemonic C. Mnemonic C. Mnemonic C. Mnemonic -- ----------- -- -------- -- --------------- -- ----------- 00 nop 40 lstore_1 80 ior c0 checkcast 01 aconst_null 41 lstore_2 81 lor c1 instanceof 02 iconst_m1 42 lstore_3 82 ixor c2 monitorenter 03 iconst_0 43 fstore_0 83 lxor c3 monitorexit 04 iconst_1 44 fstore_1 84 iinc c4 wide 05 iconst_2 45 fstore_2 85 i2l c5 multianewarray 06 iconst_3 46 fstore_3 86 i2f c6 ifnull 07 iconst_4 47 dstore_0 87 i2d c7 ifnonnull 08 iconst_5 48 dstore_1 88 l2i c8 goto_w 09 lconst_0 49 dstore_2 89 l2f c9 jsr_w 0a lconst_1 4a dstore_3 8a l2d ca breakpoint 0b fconst_0 4b astore_0 8b f2i cb 0c fconst_1 4c astore_1 8c f2l cc 0d fconst_2 4d astore_2 8d f2d cd 0e dconst_0 4e astore_3 8e d2i ce 0f dconst_1 4f iastore 8f d2l cf 10 bipush 50 lastore 90 d2f d0 11 sipush 51 fastore 91 i2b d1 12 ldc 52 dastore 92 i2c d2 13 ldc_w 53 aastore 93 i2s d3 14 ldc2_w 54 bastore 94 lcmp d4 15 iload 55 castore 95 fcmpl d5 16 lload 56 sastore 96 fcmpg d6 17 fload 57 pop 97 dcmpl d7 18 dload 58 pop2 98 dcmpg d8 19 aload 59 dup 99 ifeq d9 1a iload_0 5a dup_x1 9a ifne da 1b iload_1 5b dup_x2 9b iflt db 1c iload_2 5c dup2 9c ifge dc 1d iload_3 5d dup2_x1 9d ifgt dd 1e lload_0 5e dup2_x2 9e ifle de 1f lload_1 5f swap 9f if_icmpeq df 20 lload_2 60 iadd a0 if_icmpne e0 21 lload_3 61 ladd a1 if_icmplt e1 22 fload_0 62 fadd a2 if_icmpge e2 23 fload_1 63 dadd a3 if_icmpgt e3 24 fload_2 64 isub a4 if_icmple e4 25 fload_3 65 lsub a5 if_acmpeq e5 26 dload_0 66 fsub a6 if_acmpne e6 27 dload_1 67 dsub a7 goto e7 28 dload_2 68 imul a8 jsr e8 29 dload_3 69 lmul a9 ret e9 2a aload_0 6a fmul aa tableswitch ea 2b aload_1 6b dmul ab lookupswitch eb 2c aload_2 6c idiv ac ireturn ec 2d aload_3 6d ldiv ad lreturn ed 2e iaload 6e fdiv ae freturn ee 2f laload 6f ddiv af dreturn ef 30 faload 70 irem b0 areturn f0 31 daload 71 lrem b1 return f1 32 aaload 72 frem b2 getstatic f2 33 baload 73 drem b3 putstatic f3 34 caload 74 ineg b4 getfield f4 35 saload 75 lneg b5 putfield f5 36 istore 76 fneg b6 invokevirtual f6 37 lstore 77 dneg b7 invokespecial f7 38 fstore 78 ishl b8 invokestatic f8 39 dstore 79 lshl b9 invokeinterface f9 3a astore 7a ishr ba invokedynamic fa 3b istore_0 7b lshr bb new fb 3c istore_1 7c iushr bc newarray fc 3d istore_2 7d lushr bd anewarray fd 3e istore_3 7e iand be arraylength fe impdep1 3f lstore_0 7f land bf athrow ff impdep2
Some commonly used instructions are described in next tutorials. For more detailed descriptions on all instructions, see "The Java® Virtual Machine Specification" at https://docs.oracle.com/javase/specs/.
Table of Contents
JVM (Java Virtual Machine) Specification
Java HotSpot VM - JVM by Oracle/Sun
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
Micro Benchmark Runner and JVM Options
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations
JRockit JVM 28.2.7 by Oracle Corporation
►JVM Bytecode and Instruction Set
Walkthrough of "javap -c -v" Command Output
Local Variable Array Instructions
Arithmetic Operation Instructions
Bitwise Operation Instructions
Method Invocation Instructions