Thursday, 20 October 2016

JVM Architecture

JVM Architecture


Fun point:
  • Cat knows only cat’s language to understand what other cat is speaking.
  • Hen knows only hen’s language to understand what other hen is speaking.
Coming to the point,
  • Java Compiler knows only source code to understand "what source code file is speaking"  (Note: Source code = any .java file)
  • JVM knows only byte code to understand "what byte code file is speaking"(Note: byte code = any .class file)
According to the diagram follow the things,
    1. Class loader Sub System :
    • It loads the .class files and verifies the byte code is valid or not before process the file to next step
    2. Run time data areas :
    • A separate block of memory is required to store the data info like, methods, variables, objects and results of a program
    • JVM contains Run time data areas to keep these details
     1. Method area
    • Its stores the code of the class which may contains fields and methods.
     2. Heap
    • Heap area contains all objects which are all created.
     3. Java Stacks

    • In Java threads( either one or many ) will work in back-end to finish the task.
    • Every thread contains a stack, stack having a frame for each method call to execute.
    • Stack follows Last In First Out, so currently executing method should be at the top of the stack. 
    • The frame is removed from the stack after the method called successfully or if any exception while method is executing.
    • So, java methods are executes in java stack.
     4. PC Register
    • PG Register takes care of how the instructions are executing.
    5. Native method stacks
    • When a thread calls native methods (C & C++) then JVM will use native method libraries by linking the native method interface to execute the native methods.
    6. Native method interface
    • It holds native methods (C & C++) to process the native method calls.
    7. Native method library
    • It provides the library of methods for the execution of native methods
    8. Execution engine
    · It contains mainly Interpreter JIT compiler
    Interpreter   : Read the byte code and executes
    JIT Compiler : Because of this performance got improved. It decreases the amount of time required for the compilation. 

    Thanks for your time.

    Nireekshan