What are the main parts of the JVM, and what does each one do?
The Java Virtual Machine has three big parts, and they each do a different job.
The first part is the class loader subsystem. It finds the bytes of a class, reads them, and turns them into a runtime class. It is the part that decides where a class comes from and makes sure that a class is only ever loaded once.
The second part is the runtime data areas. These are the places in memory where the program actually lives. There are five of them, and they are described in the next question.
The third part is the execution engine. This is what actually runs your code. It contains the interpreter, which runs the bytecode directly, the just in time compiler, which turns the hot parts of the program into machine instructions, and the garbage collector, which frees the memory that is no longer needed.
public class Main {
public static void main(String[] args) {
// Ask the JVM about itself.
System.out.println("java.vm.name : " + System.getProperty("java.vm.name"));
System.out.println("java.vm.version : " + System.getProperty("java.vm.version"));
System.out.println("java.home : " + System.getProperty("java.home"));
System.out.println("java.class.path : " + System.getProperty("java.class.path"));
System.out.println("java.vm.info : " + System.getProperty("java.vm.info"));
}
}
There is one more part that is worth mentioning, and it is the set of runtime libraries. Those are the native libraries that the JVM itself calls, such as the ones that do the file access and the network access on behalf of your Java code.
The next question in this topic looks at the runtime data areas in detail.