Order code | mnemonics | instructions |
---|---|---|
00 0 x | nop | Do nothing |
0 x 01 | aconst_null | Push null to the top of the stack |
0 x. | iconst_m1 | Push int -1 to the top of the stack |
0 x 3 | iconst_0 | Push int 0 to the top of the stack |
0 x 04 | iconst_1 | Push int 1 to top of stack |
0 x 05 | iconst_2 | Push int 2 to the top of the stack |
0 x 6 | iconst_3 | Push int 3 to top of stack |
0 x 7 | iconst_4 | Push int 4 to top of stack |
0 x 08 | iconst_5 | Push int 5 to top of stack |
0 x 09 | lconst_0 | Push long 0 to the top of the stack |
0x0a | lconst_1 | Push long 1 to the top of the stack |
0x0b | fconst_0 | Push float 0 to the top of the stack |
0x0c | fconst_1 | Push float 1 to the top of the stack |
0x0d | fconst_2 | Push float 2 to the top of the stack |
0x0e | dconst_0 | Push double 0 to the top of the stack |
0x0f | dconst_1 | Push double type 1 to the top of the stack |
0 x 10 | bipush | Pushes the single-byte constant value (-128 to 127) to the top of the stack |
0 x 11 | sipush | Pushes a short integer constant value (-32768 to 32767) to the top of the stack |
0 x 12 | ldc | Pushes an int, float, or String constant value from the constant pool to the top of the stack |
0 x 13 | ldc_w | Pushes an int, float, or String constant value from the constant pool to the top of the stack (wide index) |
0 x 14 | ldc2_w | Pushes a long or double constant value from the constant pool to the top of the stack (wide index) |
0 x 15 | iload | Pushes the specified int local variable to the top of the stack |
0 x 16 | lload | Pushes the specified long local variable to the top of the stack |
0 x17, | fload | Pushes the specified float local variable to the top of the stack |
0 x 18 | dload | Pushes the specified local variable double to the top of the stack |
0 x 19 | aload | Pushes the specified reference type local variable to the top of the stack |
0x1a | iload_0 | Pushes the 0th local variable of type int to the top of the stack |
0x1b | iload_1 | Pushes the first local variable of type int to the top of the stack |
0x1c | iload_2 | Pushes the second local variable of type int to the top of the stack |
0x1d | iload_3 | Pushes the third local variable of type int to the top of the stack |
0x1e | lload_0 | Pushes the 0th local variable of type long to the top of the stack |
0x1f | lload_1 | Pushes the first long local variable to the top of the stack |
0 x 20 | lload_2 | Pushes the second long local variable to the top of the stack |
0 x 21 | lload_3 | Pushes the third long local variable to the top of the stack |
0 x 22 | fload_0 | Pushes the 0th local variable of type float to the top of the stack |
0 x 23 | fload_1 | Pushes the first local variable of type float to the top |
0 x 24 | fload_2 | Pushes the second local variable of type float to the top of the stack |
0 x 25 | fload_3 | Pushes the third local variable of type float to the top of the stack |
0 x 26 | dload_0 | Pushes the 0th local variable of type double to the top of the stack |
0 x 27 | dload_1 | Pushes the first local variable of type double to the top of the stack |
0 x 28 | dload_2 | Pushes the second local variable of type double to the top of the stack |
0 x 29 | dload_3 | Pushes the third local variable of type double to the top of the stack |
0x2a | aload_0 | Pushes the 0th local variable of reference type to the top of the stack |
0x2b | aload_1 | Pushes the first reference type local variable to the top of the stack |
0x2c | aload_2 | Pushes the second reference type local variable to the top of the stack |
0x2d | aload_3 | Pushes the third reference type local variable to the top of the stack |
0x2e | iaload | Pushes the 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 |
0 x 30 | faload | Pushes the value of the specified index of the float array to the top of the stack |
0 x 31 | daload | Pushes the value of the specified index of the array double to the top of the stack |
0 x 32 | aaload | Pushes the value of the specified index of the reference array to the top of the stack |
0 x 33 | baload | Pushes the value of the specified index of a Boolean or byte array to the top of the stack |
0 x 34 | caload | Pushes the value of the specified index of an array of type char to the top of the stack |
0 x 35 | saload | Pushes the value of the specified index of the array of type short to the top of the stack |
0 x 36 | istore | Stores a stack top int in the specified local variable |
0 x 37 | lstore | Stores the top stack long value in the specified local variable |
0 x 38 | fstore | Stores the top stack float value in the specified local variable |
0 x 39 | dstore | Stores a top stack double in the specified local variable |
0x3a | astore | Stores a top – reference value to a specified local variable |
0x3b | istore_0 | Store a stack top int in the 0th local variable |
0x3c | istore_1 | Store the top int value in the first local variable |
0x3d | istore_2 | Store the stack top int in the second local variable |
0x3e | istore_3 | Store the stack top int in the third local variable |
0x3f | lstore_0 | Store the top stack long value in the 0th local variable |
0 x 40 | lstore_1 | Store the top stack long value in the first local variable |
0 x 41 | lstore_2 | Store the top stack long value in the second local variable |
0 x 42 | lstore_3 | Store the top stack long value in the third local variable |
0 x 43 | fstore_0 | Store the top stack value of type float in the 0th local variable |
0 x 44 | fstore_1 | Store the top stack value of type float in the first local variable |
0 x 45 | fstore_2 | Store the top stack value of type float in the second local variable |
0 x 46 | fstore_3 | Store the top stack value of float in the third local variable |
0 x 47 | dstore_0 | Store the top stack double as the 0th local variable |
0 x 48 | dstore_1 | Store the top stack double in the first local variable |
0 x 49 | dstore_2 | Store the top stack double in the second local variable |
0x4a | dstore_3 | Store the top stack double in the third local variable |
0x4b | astore_0 | Store the top stack reference value in the 0th local variable |
0x4c | astore_1 | Store the top reference value in the first local variable |
0x4d | astore_2 | Store the top reference value in the second local variable |
0x4e | astore_3 | Store the top reference value in the third local variable |
0x4f | iastore | Stores a stack int at the specified index of the specified array |
0 x 50 | lastore | Stores the top stack long at the specified index of the specified array |
0 x 51 | fastore | Stores the top stack float value at the specified index of the specified array |
0 x 52 | dastore | Stores a top stack double at the specified index of the specified array |
0 x 53 | aastore | Stores the top reference value in the specified array at the specified index position |
0 x 54 | bastore | Stores top stack Boolean or byte values at the specified index of the specified array |
0 x 55 | castore | Stores the top stack char value at the specified index of the specified array |
0 x 56 | sastore | Stores the top stack short at the specified index of the specified array |
0 x 57 | pop | Pop the top value of the stack (it cannot be a long or a double) |
0 x 58 | pop2 | To pop one (long or double) or two (other) values at the top of the stack |
0 x 59 | dup | Copies the top stack value and pushes the copied value to the top of the stack |
0x5a | dup_x1 | Copies the top stack value and pushes the two copy values to the top of the stack |
0x5b | dup_x2 | Copies top stack values and pushes three (or two) copy values to the top of the stack |
0x5c | dup2 | Copies one (long or double) or two (other) values from the top of the stack and pushes the copied values to the top |
0x5d | dup2_x1 | < to be added > |
0x5e | dup2_x2 | < to be added > |
0x5f | swap | Swap the top two values on the stack (values cannot be long or double) |
0 x 60 | iadd | Add two int values at the top of the stack and press the result to the top |
0 x 61 | ladd | Add two long values at the top of the stack and press the result to the top of the stack |
0 x 62 | fadd | Add two float values at the top of the stack and push the result to the top |
0 x 63 | dadd | Add two double values at the top of the stack and push the result to the top |
0 x 64 | isub | Subtraction two ints from the top of the stack and pushes the result to the top |
0 x 65 | lsub | Subtract two long values from the top of the stack and push the result to the top of the stack |
0 x 66 | fsub | Subtraction two float values at the top of the stack and pushes the result to the top |
0 x 67 | dsub | Subtract two double values from the top of the stack and push the result to the top |
0 x 68 | imul | Multiply two int values at the top of the stack and push the result to the top |
0 x 69 | lmul | Multiply the two long values at the top of the stack and push the result to the top |
0x6a | fmul | Multiply two float values at the top of the stack and push the result to the top |
0x6b | dmul | Multiply the double at the top of the stack and push the result to the top |
0x6c | idiv | Divide two int values at the top of the stack and push the result to the top |
0x6d | ldiv | Divide two long values at the top of the stack and push the result to the top of the stack |
0x6e | fdiv | Divide the top two float values and push the result to the top of the stack |
0x6f | ddiv | Divide the double at the top of the stack and push the result to the top |
0 x 70 | irem | Modulo two ints at the top of the stack and press the result to the top |
0 x 71 | lrem | Modulo two long values at the top of the stack and press the result to the top of the stack |
0 x 72 | frem | Modulo two float values at the top of the stack and press the results to the top |
0 x 73 | drem | Modulo a double at the top of the stack and press the result to the top |
0 x 74 | ineg | Negates the top int and pushes the result to the top |
0 x 75 | lneg | Negative the top long and push the result to the top of the stack |
0 x 76 | fneg | Take a negative value of float at the top of the stack and push the result to the top |
0 x 77 | dneg | Negates the top double and pushes the result to the top |
0 x 78 | ishl | Shifts an int to the left by the specified number of bits and pushes the result to the top of the stack |
0 x 79 | lshl | Shifts the long value left by the specified number of bits and pushes the result to the top of the stack |
0x7a | ishr | Shifts the value of int right by the specified number of bits and pushes the result to the top of the stack |
0x7b | lshr | Shifts the long value right (sign) by the specified number of bits and pushes the result to the top of the stack |
0x7c | iushr | Shifts the value of int right (unsigned) by the specified number of bits and pushes the result to the top of the stack |
0x7d | lushr | Shifts the long value right (unsigned) by the specified number of bits and pushes the result to the top of the stack |
0x7e | iand | Make a bitwise and of two int values at the top of the stack and push the result to the top |
0x7f | land | Make bitwise and of two long values at the top of the stack and push the result to the top of the stack |
0 x 80 | ior | Make a bitwise or of two int values at the top of the stack and push the result to the top |
0 x 81 | lor | Make bitwise or for the two long values at the top of the stack and push the result to the top of the stack |
0 x 82 | ixor | Make bitwise xor of the top two ints and push the result to the top of the stack |
0 x 83 | lxor | Put the two long values at the top of the stack as bitwise xor and push the result to the top of the stack |
0 x 84 | iinc | Int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int int |
0 x 85 | i2l | Casts a stack top int to a long and pushes the result to the top of the stack |
0 x 86 | i2f | Casts the top int to float and pushes the result to the top of the stack |
0 x 87 | i2d | Casts a top int to a double and pushes the result to the top of the stack |
0 x 88 | l2i | Casts a long to an int and pushes the result to the top of the stack |
0 x 89 | l2f | Casts the top stack long to a float and pushes the result to the top of the stack |
0x8a | l2d | Casts a stack top long to a double and pushes the result to the top of the stack |
0x8b | f2i | Casts a float to an int and pushes the result to the top of the stack |
0x8c | f2l | Casts a float to a long and pushes the result to the top of the stack |
0x8d | f2d | Casts a float 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 |
0x8f | d2l | Casts a top double to a long and pushes the result to the top |
0 x 90 | d2f | Casts a top double to a float and pushes the result to the top of the stack |
0 x 91 | i2b | Casts a stack top int to a byte and pushes the result to the top of the stack |
0 x 92 | i2c | Casts a top int to a char and pushes the result to the top of the stack |
0 x 93 | i2s | Casts a stack top int to a short and pushes the result to the top |
0 x 94 | lcmp | Compare two long values at the top of the stack and push the result (1, 0, -1) to the top of the stack |
0 x 95 | fcmpl | Compare two float values at the top of the stack and push 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 |
0 x 96 | fcmpg | Compare two float values at the top of the stack and push the result (1, 0, -1) to the top of the stack; When one of the values is NaN, the 1 is pushed to the top of the stack |
0 x 97 | dcmpl | Compare two double values at the top of the stack and push 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 |
0 x 98 | dcmpg | Compare two double values at the top of the stack and push the result (1, 0, -1) to the top of the stack. When one of the values is NaN, the 1 is pushed to the top of the stack |
0 x 99 | ifeq | Jump when int at the top of the stack equals 0 |
0x9a | ifne | Jump when an int at the top of the stack is not equal to 0 |
0x9b | iflt | Jump when int is less than 0 at the top of the stack |
0x9c | ifge | Jump when int at the top of the stack is greater than or equal to 0 |
0x9d | ifgt | Jump when the int at the top of the stack is greater than 0 |
0x9e | ifle | Jump when the top of the stack int is less than or equal to 0 |
0x9f | if_icmpeq | Compare the size of two int values at the top of the stack. Jump when the result equals 0 |
0xa0 | if_icmpne | Compare the size of two int values at the top of the stack. Jump when the result is not equal to 0 |
0xa1 | if_icmplt | Compare two int values at the top of the stack. Jump if the result is less than 0 |
0xa2 | if_icmpge | Compare two int values at the top of the stack. Jump when the value is greater than or equal to 0 |
0xa3 | if_icmpgt | Compare two int values at the top of the stack. Jump when the result is greater than 0 |
0xa4 | if_icmple | Compare the size of two int values at the top of the stack. Jump when the result is less than or equal to 0 |
0xa5 | if_acmpeq | Compare two reference values at the top of the stack and jump when the results are equal |
0xa6 | if_acmpne | Compare two reference values at the top of the stack and jump if the results are not equal |
0xa7 | goto | Unconditional jump |
0xa8 | jsr | Jumps to the specified 16-bit offset position and pushes the JSR’s next instruction address 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 | For switch conditional jump, case value continuous (variable length instruction) |
0xab | lookupswitch | For switch conditional jump, case value discontinuous (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 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 domain 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 | Call instance method |
0xb7 | invokespecial | Calls to superclass constructors, instance initialization methods, private methods |
0xb8 | invokestatic | Calling static methods |
0xb9 | invokeinterface | Calling an interface Method |
0xba | – | |
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 pushes its reference value to the top of the stack |
0xbd | anewarray | Create an array of reference types (such as class, interface, array) and push the reference value to the top of the stack |
0xbe | arraylength | Gets the length value of the array and pushes it to the top of the stack |
0xbf | athrow | Throw the exception at the top of the stack |
0xc0 | checkcast | Verify the cast; a ClassCastException is thrown if the cast fails |
0xc1 | instanceof | Checks whether the object is an instance of the specified class by pushing 1 on top of the stack if it is, and 0 otherwise |
0xc2 | monitorenter | Gets a lock on an object used to synchronize methods or blocks |
0xc3 | monitorexit | Releases a lock on an object used to synchronize methods or blocks |
0xc4 | wide | Use this directive to expand the index width of a local variable when the index exceeds 255. |
0xc5 | multianewarray | create a new array of dimensions dimensions with elements of type identified by class reference in constant pool index (indexbyte1 << 8 + indexbyte2); the sizes of each dimension is identified by count1, [count2, etc.] |
0xc6 | ifnull | if value is null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
0xc7 | ifnonnull | if value is not null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) |
0xc8 | goto_w | goes to another instruction at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) |
0xc9 | jsr_w | jump to subroutine at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) and place the return address on the stack |
0xca | breakpoint | reserved for breakpoints in Java debuggers; should not appear in any class file |
0xcb-0xfd | unnamed | these values are currently unassigned for opcodes and are reserved for future use |
0xfe | impdep1 | reserved for implementation-dependent operations within debuggers; should not appear in any class file |
0xff | impdep2 | reserved for implementation-dependent operations within debuggers; should not appear in any class file |
With the above instruction set table, it is much easier to look at the bytecode.
Corresponding English = > en.wikipedia.org/wiki/Java_b…
To a few sample:
sample1
- java
public void sample1(){
int num = 5;
}
Copy the code
- Javap -c View bytecode
public void sample1();
Code:
0: iconst_5
1: istore_1
2: return
Copy the code
- explain
Iconst_5 // pushes int 5 to the top of the stack istore_1 // stores the top int to the first local variable return // returns void from the current methodCopy the code
sample2
- java
public int sample2(int a, int b) {
return a + b;
}
Copy the code
- Bytecode and interpretation
public int sample2(int, int); Code: 0: iload_1 // push the first int to the top of the stack 1: iload_2 // push the second int to the top of the stack 2: iadd // Add the two int values at the top of the stack and push the result to the top of the stack 3: Ireturn // Returns an int from the current methodCopy the code
sample3
- java
A little bit more complicated
public float sample3() {
float num = 0;
for (int i = 0; i < 5; i++) {
num *= i;
}
return num;
}
Copy the code
- Bytecode and interpretation
public float sample3(); Code: 0: fconst_0 // Push float 0 to the top of the stack 1: fstore_1 // Store float value to the first local variable 2: iconst_0 // Push int 0 to the top of the stack, that is, I = 0 in the for loop 3: Istore_2 // store the top int in the second local variable 4: iload_2 // push the second local int to the top of the stack 5: iconst_5 // push the int 5 to the top of the stack, which is the maximum value in the for loop 5 6: If_icmpge 20 // compare the size of a stack int (0) and the size of a stack int (0); // compare the size of a stack int (0) and the size of a stack int (0). Fload_1 // Pushes the first local variable of type float to the top of the stack, num 10: iload_2 // Pushes the second local variable of type int to the top of the stack, which is I 11 in the for loop: I2f = i2f = i2f = i2f = i2f = i2f = i2f = i2f Fstore_1 // Store the top stack float value in the first local variable, which is the product of I and num 14: Iinc 2, 1; iinc 2, 1; iinc 2, 1; iinc 2, 1; iINC 2, 1; iINC 2, 1; iINC 2, 1; Fload_1 // Pushes the first local variable of type float to the top of the stack 21: freturn // Returns float from the current methodCopy the code
These are three simple examples, and the reader can begin to see why switch is more efficient than if else, starting with bytecode.