1. Description
(1) Just-in-time compilation method: The interpreter first compiles the bytecode into machine code and then executes the machine code.
(2) Interpretation and execution method: The interpreter completes all operations of the Java bytecode program by interpreting and executing a small piece of code each time.
The second method is commonly used. Because the JVM specification is flexible enough, it can convert bytecode into machine code more efficiently. For applications that have higher requirements for running speed, the interpreter can be used to immediately compile Java bytecode into machine code, thus ensuring the portability and high performance of Java code.
2. Example
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=4, args_size=1 0: iconst_1 1: istore_1 2: iconst_2 3: istore_2 4: iconst_1 5: iconst_2 6: invokestatic #2 // Method calc:(II)I 9: istore_3 10: return static int calc(int, int); descriptor: (II)I flags: ACC_STATIC Code: stack=6, locals=2, args_size=2 0: iload_0 1: i2d 2: ldc2_w #3 // double 2.0d 5: invokestatic #5 // Method java/lang/Math.pow:(DD)D 8: iload_1 9: i2d 10: ldc2_w #3 // double 2.0d 13: invokestatic #5 // Method java/lang/Math.pow:(DD)D 16: dadd 17: invokestatic #6 // Method java/lang/Math.sqrt:(D)D 20: d2i 21: ireturn
The above is the detailed content of What are the two ways of Java bytecode execution?. For more information, please follow other related articles on the PHP Chinese website!