JVM Internal Phases Exposed

What is Virtual?   This is not having physical existence

 Virtual machine  is a simple software program which simulates the functions of a physical machine. This is not having physical existence, but which can perform all operations like physical machines. Physical machine whatever it is doing, all those things we can able to do on the virtual machine. Best example of virtual machine is calculator in computer; it is worked like physical calculator.

Software based virtual machines

 These virtual machines acts as run time engine to run a particular programming language applications. Examples of software based virtual machines are 

1. JVM (Java Virtual Machine) acts as runtime engine to run Java applications

2. PVM (Parrot Virtual Machine) acts as runtime engine to run Perl applications

3. CLR (Common Language Runtime) acts as runtime engine to run .NET based applications

The first component in JVM is Class Loader Sub System

1. Class Loader Sub System

   This system is responsible for loading .class file with 3 activities

  1. Loading
  2.  Linking
  3. Initialization

1 Loading :-

   Loading means read .class file from hard disk and store corresponding binary data inside method area of JVM. For each .class file JVM will store following information

1. Fully qualified name of class

2. Fully qualified name of immediate parent

3. Whether .class file represents class|interface|enum

4. Methods|Constructors|Variables information

5. Modifiers information

6. Constant Pool information 

  After loading the class file and store inside method area, immediately JVM will perform one activity i.e., create an object of type java.lang.Class in method area.

  Created object is not student object or customer object. It is a predefined class “Class” object that is presently in java.lang package. The created object is represents either student class binary information or customer class binary information.

2 Linking :-

   After “loading” activity JVM immediately perform Linking activity. Linking once again contain 3 activities,

  • Verification
  •  Preparation
  •   Resolution

   Java language is the secure language. Through java spreading virus, malware these kind of this won't be there. If you execute old language executable files (.exe) then immediately we are getting alert message saying you are executing .exe file it may harmful to your system. 

   Byte Code Verifier /verification : - But in java .class files we never getting these alert messages. What is the reason is inside JVM a special component is there i.e., Byte Code Verifier. This Byte Code Verifier is responsible to verify weather .class file is properly formatted or not, structurally correct or not, generated by valid compiler or not. If the .class file is not generated by valid compiler then Byte Code Verifier raises runtime error java.lang.VerifyError. This total process is done in verification activity. 

 preparation :- phase, JVM will allocate memory for class level static variables and assigned default values.

E.g. For int ---> 0, For double ---> 0.0, For boolean ---> false

  Here just default values will be assigned and original values will be assigned in initialization phase.

 Resolution. :- It is the process of replacing all symbolic references used in our class with original direct references from method area.


Initialization    In Initialization activity, for class level static variables assigns original values and static blocks will be executed from top to bottom.

Varies Memory Area/Runtime Data Area :-

1) Method Area :-

  • The method area is used to store the class data and method data including static methods.
  • There is only one method area per JVM and it is a shared resource.

2) Heap Area :

  • The Heap Area is used to store the objects and their corresponding instance variables and arrays.
  • There is only one Heap area per JVM, hence Method and Heap area are shared among resources so the data stored is not thread safe.

3) Stack Area :

  • For every new thread a new stack will be created,
  • All Local variables will be created and stored in stack area.
  • Since it is not a shared resource, so it is thread safe.

4) PC Registers :-

  • PC(Program Counter) Register contains the address of the JVM instruction, currently being executed.

5) Native Method Stack :-

  • It contains all the Native method used in the application.

Execution Engine :-

The byte-code which is assigned to Runtime data area will be executed here.

1) Interpreter :

  •  It interprets the bytecode faster and but executes code slowly.
  • The disadvantage of the interpreter is that when one method is called multiple times, every time a new interpretation is required.

2) JIT Compiler :

  • It is used to improve the performance.
  • The Interpreter is used in converting the bytecode, but when it finds the repeated code it will use the JIT compiler.
  • The JIT Compiler compiles the entire bytecode and changes it to native code.
  • This native code will be used directly for repeated method calls, which improve the performance of the system.




要查看或添加评论,请登录

?? ??Saral Saxena ???????的更多文章

  • Spring boot Apps getting optimized

    Spring boot Apps getting optimized

    Before making any changes, established clear performance baselines. Here’s what our initial metrics looked like:…

  • Validating Payloads with Spring Boot 3.4.0

    Validating Payloads with Spring Boot 3.4.0

    First, let’s examine a controller that receives a object. This object contains fields such as: first name, last name…

  • Limitations of Java Executor Framework.

    Limitations of Java Executor Framework.

    The Java Executor Framework has inherent limitations that affect its performance in high-throughput, low-latency…

  • ??Structured Logging in Spring Boot 3.4??

    ??Structured Logging in Spring Boot 3.4??

    Spring Boot 3.4 has been released ??, and as usual, I want to introduce you to some of its new features.

  • Sending large payload as response in optimized way

    Sending large payload as response in optimized way

    Handling large payloads in a Java microservices application, sending large responses efficiently while maintaining…

  • Disaster Recovery- Strategies

    Disaster Recovery- Strategies

    Backup and Restore This is the simplest of the approaches and as the name implies, it involves periodically performing…

  • Memory Optimization Techniques for Spring Boot Applications with Practical Coding Strategies

    Memory Optimization Techniques for Spring Boot Applications with Practical Coding Strategies

    Learn practical coding strategies to optimize memory usage in Spring Boot applications. This guide covers efficient…

  • Designing CI/CD Pipeline

    Designing CI/CD Pipeline

    Problem statement You are responsible for designing and implementing a CI/CD pipeline for a large-scale microservices…

  • Calculate CPU for containers in k8s dynamically

    Calculate CPU for containers in k8s dynamically

    It’s possible to dynamically resize the CPU on containers in k8s with the feature gate “InPlacePodVerticalScaling”…

社区洞察

其他会员也浏览了