Java Virtual Machine (JVM)

 

The Basics Java Virtual Machine


A virtual machine is exactly what it looks like, a machine that literally resides within a piece of software. Like Neo's consciousness inside the Matrix, a digital machine that exists within a larger operating system. This software is installed on the local device, then can be used within the existing operating system to run other operating systems. A typical and common use case is to install VirtualBox on Windows or Mac, then create a virtual instance of another operating system such as a Linux distribution.


What is the Virtual Machine?

 A virtual machine (VM) is a software implementation of a machine (for example, a computer) that executes programs like a physical machine.

 Virtual machines are separated into two major classifications: 

     System virtual Machine (SVM) 

     Process Virtual Machine  (PVM)


What is the Java Virtual Machine?

 Java Virtual Machine is a process virtual machine that can execute java byte code.

 JVM converts Java byte code into machine language and executes it. 

 JVM is perform-dependent: JVM is available for many hardware and software platforms.

 JVM gives java the flexibility of platform independence.


Java Virtual Machine Architecture

Understanding the Java Virtual Machine is made easier by understanding its architecture and how it functions. Over the remainder of this post, we will discuss how the JVM works, and how the architecture affects the way Java programs run.

The JVM consists of three distinct components:

Class loader

 All Java virtual machines include one class loader that is embedded in the virtual machine.

 The class loader loads java classes into the java virtual machine.

 The class loader reads bytecode and creates the instance of the java.lang.class.


Execution engine

 The execution engine helps JVM to convert bytecode into machine code.

 A mechanism is responsible for executing the instructions contained in the methods of loaded classes.


Stack

 Stack stores various method arguments and local variables of any method.

 There are three registers that help in stack manipulation.

  1. Vars register.

  2. Frame register.

  3. Op top register.


Sections in stack

Local variable - This section contains all local variables being used by the current method.

Execution environment - The execution section is used to maintain the operation of the stack itself.

Operand stack - The operand stack is used as a workspace by bytecode instruction.


Method Area

 This is the area where the byte code is placed.

• The program counter points to the next instruction in the method area.

 After the execution of an instruction, JVM set pc to the next instruction.


Garbage Collected Heap

 The object in the java program is stored in Garbage collected heap.

 Arrays in java programs are objects, hence they are also stored in heap.

 Java does not have a free operator to free any previously allocated memory.

 Java does this automatically by the Garbage collection mechanism.


Java Runtime Environment. (JRE)

 JRE is an acronym for Java Runtime Environment.

 Java Runtime Environment contains JVM, class libraries, and other supporting files.

 It does not contain any development tools such as a compiler, debugger, etc.


Just-in-time Compiler (JIT)

 Just-in-time Compiler -is part of the Java Virtual Machine (JVM) that is used to speed up the execution time.

 JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.


Is java a compiled or interpreted language?

 Java is a compiled language because the source code is converted into byte code.

 Java is an interpreted language because the byte code is interpreted by a virtual machine.


What is the JVM used for?

Java Virtual Machines serve two primary purposes; the first is to provide a means for a Java program to run in any environment. The second is to maintain and optimize program memory.

In the days of Java’s inception, the write once, run anywher philosophy was a groundbreaking change that altered the landscape of program development. Programs that were written before this new philosophy operated only on specified target platforms. Instead, it was up to developers to manage the program’s memory, which is very time-consuming.

VM is typically thought of as having a dual definition — technical and informal — meant to illuminate its use according to the user and the behavior it has.

  • JVM Technical Definition: The JVM is the specification of a software program that provides the runtime environment for Java code execution.
  • JVM Informal Definition: The JVM runs Java programs using configured settings to manage program resources during execution.

 


Comments