What is execution engine in JAVA?

Execution Engine in Java is the core component of the JVM (java virtual machine) which communicates with different memory areas of the JVM. This component is used to execute the bytecode that is assigned to the runtime data areas via the classloader. In addition to this, each java Class file is executed through the execution engine, and each thread that is present in a running application is a distinct instance of the virtual machine’s execution engine.

Hence, by reading this article, you will understand the execution engine in more detail, but before that, let’s comprehend what Java Virtual Machine is.

Understanding Java Virtual Machine

Java Virtual Machine (JVM) is an abstract virtual machine residing on the computer, providing a runtime environment for the Java bytecode to get executed. However, in order to execute the java bytecode, an execution engine is used.

The Java Runtime Environment or JRE is the implementation of the Java Virtual Machine (JVM). JVM examines the bytecode, interprets it, and executes the same bytecode to display the output.

The primary function of JVM is to run the compiled .class files (i.e., the bytecode) and produce an output. However, each operating system has a distinct JVM, the produced bytecode output is the same across all operating systems. It means that the bytecode produced on Linux OS will be capable of running on Windows OS and vice-versa, thus making Java a platform-independent language.

So, without further delay, now let’s dive into this article and understand the execution engine in Java and its different components.

Execution Engine in Java

As we stated above, in order to execute the java bytecode, the execution engine is used. It is because, in general, the Java bytecode will be written in a human-readable form. Hence with the use of an execution engine, the human-readable bytecode will be converted to a language that can be easily executed by the machine in the Java Virtual Machine.

In order to change the language, the execution engine contains three major subcomponents, including −

• Interpreter

• JIT Compiler

• Garbage Collector

Let’s take a look at each component in detail!

Interpreter

This component reads the byte code and interprets(converts) into the machine code(native code), and executes them in a sequential manner. By accepting the filename argument, this component runs the application from the command line. The following prototype command can be used −

java <_compiled_file_name_without_extension_>


However, the drawback with the interpreter is that it converts or interprets each time, even the same method multiple times, which in turn decreases the performance of the system. Hence, to overcome this issue, the JIT ((Just In Time) Compilers is introduced in 1.1 version, which is discussed below.

JIT (Just In Time) Compiler

The main purpose of the JIT compiler is to increase performance. In other words, it is introduced to overcome the interpreter’s drawback of slow execution and improves the performance of the system.

Additionally, to reduce the time required for compilation, the JIT compiler compiles a similar part of the bytecode at the same time.

• During run time, the JVM loads class files determine their semantics, and performs appropriate computations. Due to the additional processor and memory usage while interpretation makes the Java application function slowly as compared to a native application.

• The JIT compiler helps in increasing the performance of Java programs by compiling bytecode into native machine code during run time.

• When a method is invoked, the JIT compiler is enabled throughout and gets activated. For a compiled method, instead of converting or interpreting, the JVM directly calls the compiled code. When speaking theoretically, if compiling does not require any processor time or memory usage, the speed of a native compiler and that of a Java compiler will be the same.

• JIT compilation needs both processor time and memory usage. Therefore, at the start of the java virtual machine, thousands of methods are invoked. So, when compiling all these methods together can significantly affect startup time, even if the end result is a very good performance optimization.

Profiler

The part of JIT Compiler is the profiler tool that is used to monitor the java bytecode constructs and operations at the JVM level.

Garbage Collector

This is a program or a part of the execution engine component that runs in the background and manages the memory automatically. The main purpose of this component is to free up the heap memory by collecting and removing the unreferenced objects.

Wrapping up

At the end of this article, we hope you got a better understanding of what is execution engine in Java and their different component.