[go: up one dir, main page]

0% found this document useful (0 votes)
63 views5 pages

JVM (JAVA Virtual Machine) : The JVM Performs Following Operation

The JVM (Java Virtual Machine) is an abstract machine that provides a runtime environment for executing Java bytecode. It defines memory areas like the heap and stack, as well as components like the class loader, execution engine, and garbage collector. The class loader loads bytecode, the execution engine contains an interpreter and JIT compiler to execute the code, and the garbage collector automatically frees up unused memory.

Uploaded by

pratham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views5 pages

JVM (JAVA Virtual Machine) : The JVM Performs Following Operation

The JVM (Java Virtual Machine) is an abstract machine that provides a runtime environment for executing Java bytecode. It defines memory areas like the heap and stack, as well as components like the class loader, execution engine, and garbage collector. The class loader loads bytecode, the execution engine contains an interpreter and JIT compiler to execute the code, and the garbage collector automatically frees up unused memory.

Uploaded by

pratham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

JVM (JAVA Virtual Machine)

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides


runtime environment in which java bytecode can be executed. The Java Virtual Machine
understands only byte code; that’s why there is a javac compiler that converts the source
code (.java) into byte code (.class) which JVM understands. Although JVM installed
within different operating systems is different, JVM’s output is consistent across all
operating systems.

1. A specification where working of Java Virtual Machine is specified. But


implementation provider is independent to choose the algorithm. Its
implementation has been provided by Oracle and other companies.

2. An implementation its implementation is known as JRE (Java Runtime


Environment).

3. Runtime Instance Whenever you write java command on the command prompt


to run the java class, an instance of JVM is created.

The JVM performs following operation:

o Loads code

o Verifies code

o Executes code

o Provides runtime environment

JVM provides definitions for the:

o Memory area

o Class file format

o Register set

o Garbage-collected heap

o Fatal error reporting etc.


Class Loader

Native Method
Class Area Heap Stack PC Register
Stack

Native Method
Execution Engine Native Method Interface
Libraries
Components of JVM

ClassLoader
As the name suggests, it is a component responsible for Loading Class files. Loading,
Linking and initializing a class file are the major functions of the Loader. The loader
does it work in runtime.

Loading:

Basically, the loader reads the .class file and then generates the binary code and saves
it in a method area. Bootstrap Classloader, Extension Classloader, and Application
Classloader are the various ClassLoaders responsible for loading various classes.

Linking:

Three major functions like Verification, Preparation, and Resolve. It starts with .class
file verification. If verification fails, it gives a run time verification exception. Later,
Memory is allocated to the variables with default values. Then, finally, the symbolic
memory references are replaced with direct reference from the memory area.

Initializing:

This is the final part of ClassLoader. Original values are assigned to all the static
variables, followed by the execution of Static Block. This part executes from the top to
the bottom of a class.

Heap
Details of an object and instance variables are all stored here. It is a shared memory
area, which means the data stored here is not thread-safe.

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

One of the most relatable errors is the “OutOfMemoryError” exception, which means the
JVM cannot allocate an object in the Heap area, or memory allocation cannot be done
for the same object.
Stack
This is where a separate runtime stack is created for every new thread. Also known as a
Run-Time Stack, every time a method is called upon, all the details are stored in the
corresponding runtime stand, and after the completion of the method, these details are
removed from the stack.

PC Registers
For every single thread, a separate PC (Program Counter) register is created, which
stores the address of the current execution instruction, which, later, will be updated
with the next instruction. This memory area is quite small and is of fixed size.

Native Method Stack


It is one of its own kind of memory area, which is invoked by a thread and then the
thread is in a whole new level where structure and security restrictions implied by Java
Virtual Machine are no longer in exercise. Compared to other runtime memory areas,
the memory occupied by the native method stacks has no fixed size, with no limitations
in increment or decrement.

Java Native Interface


JNI simply interacts with the below mentioned Native Method Libraries, which are of C,
C++ implementation, and provide the same to the execution engine. Direct Access to
assembly code is allowed by JNI. For a JVM, Java and Native are the two types of
codes. The JNI smoothly establishes a well-defined link between these two.

Native Method Libraries


Collection of Native Libraries, as required by the Execution Engine.
Execution Engine
Well, now we have a java program into bytecode, which is being assigned to the above-
explained data areas via a class loader, and now the bytecode will be executed by the
execution engine. Execution Engine simply reads the bytecode in units, like a machine
reading code lines one by one. The bytecode is a human-readable format, which is why
the machine cannot read it as it is and needs to be converted to a machine-readable
format, where the below components are utilized for the interpretation purpose.

The Execution Engine has three major components, which are Interpreter, JIT Compiler
and a Garbage Collector.

1. Interpreter

Simply executes the bytecode in a sequential method. A command-line query makes a


call with a compiled file as an argument. The interpreter is quite quick in interpreting
and executing commands one by one, which happens faster than the JIT compiler to
compile the code.

java class name

A main() class is must in a compiled .class file.

2. JIT Compiler

One of the most important components of the Java Runtime Environment which
enhances the Java Application performance at run time. No other component has more
impact on performance than the JIT Compiler. This is a default compiler and is activated
when any Java method is called.

3. Garbage Collector

As the name suggests, it does have something to do with garbage; Garbage Collector
simply searches for every possible object available in the JVM heap space, checks if it is
in use, and then delete the unused ones. So, it simply marks the pieces of memory
which are in use or not. Then it goes on sweeping, where it simply removes the object
marked. The best use case is that no manual memory allocation system is needed as
the Garbage Collector does the job of automatically removing unused memory space.
As this is an automatic task, no programmer has control over scheduling any time slot
for specifically cleaning tasks and requires more CPU power as it searches for object
references.

You might also like