Java Virtual Machine(JVM)
JVM(java virtual machine) is an abstract machine. Jvm is a software and It is a specification that provides runtime environment in which java bytecode can be executed. Java virtual machine(jvm) is platform dependent.
👉: Java is platform independent language but java virtual machine (JVM) is platform dependent because every operating system have different-different jvm which is install along with jdk software.
What is JVM
- An Implementation: Its implementation is known as JRE(Java Runtime Environment).
- Runtime Instance: Whenever you write a java command on command prompt to run the java class, an instance of JVM is created.
What is does
The JVM perform following operation
- Loads code.
- Verifies code.
- Executes code.
- Provides runtime environment.
Internal Architecture of JVM
Let's understand the internal architecture of java virtual machine(JVM). Its contains classloader, memory areas(class area(method area), heap memory, stack memory, native method stack, program counter(pc register), execution engine.
1) Classloader: classloader is a subsystem of java virtual machine(JVM) that is used to load a class file i.e (.class files). Before loading the bytecode into the jvm it will verity where the bytecode is valid or not. This verification will be done by the bytecode verifier. If the bytecode is valid then there is different areas into which the bytecode is loaded, called runtime data areas e.g class area, heap, stack, etc.
2) Class(Method) Area: Class area (Method Area) stores per-class structures such as the constant pools, field and method data, the code for method. In class or method area static variables, non-static and static method will be stored.
3) Heap: it is the runtime data area in which objects are allocated. The heap memory is the main memory of the jvm because here instance variable take a memory in this heap memory. When we create instance variable these variable are goes into the object, and object allocated in heap area.
1) Classloader: classloader is a subsystem of java virtual machine(JVM) that is used to load a class file i.e (.class files). Before loading the bytecode into the jvm it will verity where the bytecode is valid or not. This verification will be done by the bytecode verifier. If the bytecode is valid then there is different areas into which the bytecode is loaded, called runtime data areas e.g class area, heap, stack, etc.
2) Class(Method) Area: Class area (Method Area) stores per-class structures such as the constant pools, field and method data, the code for method. In class or method area static variables, non-static and static method will be stored.
3) Heap: it is the runtime data area in which objects are allocated. The heap memory is the main memory of the jvm because here instance variable take a memory in this heap memory. When we create instance variable these variable are goes into the object, and object allocated in heap area.
4) Stack: it holds local variables. Stack memory are used for storing the information of the methods. Java stack stores frames.
Here JVM creates two thread in stack, these are
- main method: Which is called main thread and this main thread is responsible to execute java method which name starts with main method.
- garbage collection thread: Garbage collection thread is used to destroy all the unused objects from heap memory or area.
5) Program Counter Register: PC (program counter) register. it contains the address of the java virtual machine(JVM) instruction currently being executed.
6) Native Method Stack: It contains all the native methods used in the application.
7) Execution Engine:
it contains:
- Interpreter: Read bytecode stream than execute the instructions.
- Just-In-Time: It is used to improve the performance. the JIT compiler is enabled by default and is activated when java method is called. the JIT compiler compiles the bytecodes of that method into native machine code, compiling it "just in time " to run. when a method has been compiled the JVM calls the compiled code of that method directly instead of interpreting it.
Lifetime of JVM
A runtime instance of the java virtual machine has a clear mission in life to run one java application. When a java application starts, a runtime instance is born. When the java application is completes, the instance dies. If you starts three java applications at the same time, on the same computer, you will get three java virtual machine instances. Each java application runs inside its own java virtual machine. A JVM instance starts running its solitary application by invoking the main() method of some initial class.
Nice blog thanks for sharing about JVM
ReplyDeleteAngular course
Angular training
you have written an excellent blog.. keep sharing your knowledge...
ReplyDeleteRobot Framework Test Automation Training in Chennai
Robot Framework Test Automation Course in Chennai
Robot Framework Test Automation Online Training
Robot Framework Test Automation Online Course
This is great stuff!! need to share lots of articles for the reader who like your blog and thanks for sharing your ideas and tips
ReplyDelete1Z0-819: Oracle Java SE 11 Developer
1Z0-900: Java EE 7 Application Developer