What is JVM?
- Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive Java Code or applications.
- It converts Java bytecode into machine language. JVM is a part of the Java Run Environment (JRE).
Here is the working
Java Virtual Machine(JVM) is a virtual machine that provides a runtime environment to execute Java bytecode.
The JVM doesn’t understand Java typos, that’s why you compile your *.java files to obtain *.class files that contain bytecodes that understandable by JVM.
- This bytecode gets interpreted on different machines, bytecode is an intermediary language
JVM controls the execution of every Java program. It enables features such as automated exception handling, Garbage-collected heap.
What JVM does?
JVM performs operations
- Loads code
- Verify code
- Executes code
- Provides runtime environment
JVM provides definitions for the:
- Class file format
- Register set
- Garbage-collected heap
- Fatal error reporting etc.
Here is a simple brief about JVM architecture
Classloader– Classloader is a subsystem of JVM which is used to load class files. It performs three major functions viz. Loading, Linking, and Initialization.
- Bootstrap ClassLoader:
- This is the first classloader which is the superclass of Extension classloader.
- It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java. util package classes, java.io package classes, java.sql package classes, etc.
- Extension ClassLoader:
- This is the child classloader for Bootstrap and the parent classloader for the System classloader.
- It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
- This is the child classloader of the Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory.
- You can change the classpath using the “-cp” or “-classpath” switch. It is also known as the Application classloader.
Method Area stores per-class structures such as the runtime constant pool, field and method data, and the code for methods.
- This is the runtime data area in which objects are allocated.
- This memory is common and shared across multiple threads.
JVM language Stacks
- Java Stack stores frames.
- Java language Stacks holds local variables and it’s partial results, and plays a part in method invocation and return.
- Each thread has a private JVM stack, created at the same time as the thread.
- A new frame is created each time a method is invoked. The frame is destroyed when its method invocation completes.
Program Counter Registers:
The PC register stores the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its own separate PC register.
Native Method Stacks:
- Native method stacks hold the instruction of native code depending on the native library.
- It is written in another language instead of Java.
Native Method interface:
- The Native Method Interface is a programming framework.
- It allows Java code that is running in a JVM to be called by libraries and native applications.
Native Method Libraries:
Native Libraries is a collection of the Native Libraries(C, C++) that are needed by the Execution Engine.
It is a type of software used to test hardware, software, or complete systems.
The test execution engine never carries any information about the tested product.
Software code compilation and execution
- Editor – To type the program into, a notepad could be used for this.
- Compiler – To convert your high language program into native machine code
- Linker –It is a program in a system that helps to link object modules of a program into a single object file. It performs the process of linking.
- Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.
- Execution – Actual execution of the code, which is handled by your OS & processor.