This is the 7th day of my participation in Gwen Challenge

Execution engine

1. Overview of the execution engine

Execution engine is one of the core components of Java virtual machine. The execution engine of virtual machine is realized by software itself, which can customize the instruction set and the structure system of the execution engine without physical conditions. It can execute the instruction set format that is not directly supported by hardware.

The main task of the JVM is to load the bytecode into memory, but the bytecode cannot run directly on the operating system. To run a bytecode, an execution engine is required to interpret or compile the bytecode instructions into the machine instructions for the platform.

Execution engine working process:

  • What instructions does the execution engine need to execute that are entirely dependent on the PC register
  • After an instruction is executed, the PC register updates the next instruction to be executed.
  • The execution engine can accurately locate object instance information in the heap through object references stored in the local variable table.

2. Compile and explain the running process

What is an interpreter?

Interpreter: The bytecode is interpreted line by line by predefined specifications when the Java virtual machine starts, translating the contents of each bytecode file into the corresponding machine instructions for execution.

What is a JIT (Compiler)?

Compiler: The virtual machine compiles the source code directly into the native machine language.

Why is Java a half-compiled, half-interpreted language?

The execution engine can use either an interpreter or a just-in-time compiler to parse bytecode files, and JVMS typically use a combination of the compiler and interpreter when executing code. The just-in-time compiler can cache bytecode instructions into the JIT cache of the method area and call the instructions directly if called frequently.

Interpreter and compiler execution:

3. The interpreter

The interpreter’s primary responsibility is to be a runtime translator, translating the contents of bytecode files into platform-specific machine instructions.

Due to the inefficiency of the interpreter, Java supports a technique called the just-in-time compiler. The purpose of the just-in-time compiler is to avoid the function being interpreted. Instead, the whole function body is compiled into machine code. Each time a function is executed, only the compiled machine code is executed, which greatly improves the execution efficiency.

Why should an interpreter exist when Java has a just-in-time compiler (JIT)?

Although the overall efficiency of the interpreter is low and needs to be parsed line by line, the interpreter responds quickly. After the program is started, the interpreter can come into play immediately, saving the compilation time. To be effective, the compiler must first compile the code into native code, which takes a certain amount of execution time. However, when translating native code, the execution is more efficient. At the same time explain the execution of the recompiler for radical optimization is not tenable, as the compiler escape door.

How the HotSpot VIRTUAL machine executes:

When the virtual machine is started, the interpreter can function first, rather than wait for instant compiler compiles all perform again, that can save unnecessary compilation time, and as the program running time, instant compiler function gradually, according to the hot spot detection function, valuable code compiled to native machine instructions, In exchange for more efficient program execution.