Home > Java > javaTutorial > body text

What are the two ways of Java bytecode execution?

WBOY
Release: 2023-04-28 09:34:06
forward
1380 people have browsed it

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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template