Architecture

 




Let's look at the JVM's internal architecture. It includes a class loader, memory area, execution engine, and other components.



Class Loader Subsystem




 

Class loader is a JVM subsystem that is used to load class files. The class loader loads the java programm first when we run it. Java includes three built-in class loaders.

§  Loading

a)    Bootstrap Class Loader 

The first-class loader and the superclass of Extension Class Loader. It loads the rt.jar file, which contains all Java Standard Edition class files such as java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes, and so on.

b)    Extension Class Loader

This is the Bootstrap class loader's child and the System class loader's parent. It loads the jar files contained in the $JAVA HOME/jre/lib/ext directory.

c)    Application Class Loader

This is the Extension classloader's child class loader. The classfiles are loaded from the classpath. Classpath is set to the current directory by default. The "-cp" or "-classpath" switches can be used to change the classpath. Application classloader is another name for it.

 

§  Linking

a)    Verify

Verification ensures the correctness of the.class file, that is, whether it is properly formatted and generated by a valid compiler. If the verification fails, we get a java.lang run-time exception. VerifyError. The component ByteCodeVerifier performs this function. When this activity is finished, the class file is ready for compilation. 

b)    Prepare 

The JVM allocates memory for class variables and sets it to default values.

c)    Resolve

Resolution is the process of replacing type symbolic references with direct references. It is accomplished by searching the method area for the referenced entity.

 

§  Initialization

All static variables are assigned with their values defined in the code and static block during this phase (if any). This is done in a class from top to bottom and from parent to child in the class hierarchy.

 



Runtime Data Areas

 


§  Method Area: Method Area keeps per-class structures like the runtime constant pool, field and method data, and method code.


§  Heap Area: It is the runtime data area where objects are assigned.


§  Stack Area: Frames are stored in Java Stack. It stores local variables and partial results, as well as participating in method invocation and return. Each thread has its own JVM stack, which is created at the same time as the thread. Each time a method is called, a new frame is created. When a frame's method invocation is finished, it is destroyed.


§  PC Registers: The address of the Java virtual machine instruction currently being executed is stored in the PC (programme counter) register.


§  Native Method Stacks: It contains all of the application's native methods.

 

Execution Engine


               

                  The Execution Engine will execute the bytecode assigned to the Runtime Data Area. The Execution Engine reads and executes the bytecode piece by piece.

§  Interpreter: The interpreter interprets bytecode more quickly but executes it slowly. The interpreter's disadvantage is that when one method is called multiple times, a new interpretation is required each time.

§  JIT Compiler: The JIT Compiler mitigates the interpreter's disadvantage. The Execution Engine will use the interpreter to convert byte code, but when it encounters repeated code, it will use the JIT compiler, which will compile the entire bytecode and convert it to native code. This native code will be used directly for repeated method calls, resulting in improved performance.

1. Intermediate Code Generator – This programme generates intermediate code.

2. Code Optimizer – In charge of optimising intermediate code.

 

§  Garbage Collector: Gathers and discards unreferenced objects. System.gc can be used to initiate garbage collection (). The JVM's garbage collection collects the objects that are created.

Comments

Post a Comment