Java Tutorials

Java Virtual Machine ( JVM ) – How does JVM work?

Java Virtual Machine JVM is an abstract machine which provides the environment for java bytecode where it can be executed.
JVM hides the hardware and operating systems. It provides a virtual machine in which Java bytecode generated from Java source code by java compilers is executed. Its implementation is known as JRE.

Java Virtual Machine (JVM) – How JVM works?

 

When a code is executed using command prompt or command terminal, instance of JVM is created.
The responsibilities of Class Loader sub-system are:

  • Loading
  • Linking
  • Initialization

In loading, Class Loader loads .class files and generate binary. The generated bytecode is stored in Class Area. JVM stores name of class and name of its parent class, whether it is interface, enum or a class, variables, modifiers and methods in Class Area. After loading the class, JVM creates object to represent the file in heap memory. An object is of type Class that is predefined in java.lang package. The object of a class can be used to access class level information by a programmer.

In linking, an interface or a class is combined in run-time state of JVM so it can be executed. Linking performs verification, preparation and resolution. Resolution is optional. During verification, .class file is verified whether it has a valid bytecode and has correct format. In case of failure of verification, run-time exception java.lang.VerifyError is thrown. After successful verification, preparation takes place in which memory is allocated to the variables in class and initialization of the memory to default values. Resolution process involves determining concrete values from symbolic references.

In initialization, method is executed for initialization of a class or an interface. All the static variables are initialized with their defined values. This process is executed from parent class to child class and top to bottom in a class.

A stack has blocks called activation record. Each activation record stores a method call. The variables of this method are stored in corresponding activation frame. For each thread, JVM creates a stack and when the thread execution is terminated, stack will be destroyed.

Each thread has a PC register which stores the address of currently executing instruction of a thread. To store native method information, for every thread, a Native Method Stack is created. Execution engine uses the bytecode line by line and executes instructions of a class. Native method interface provides an interface that allows to call native libraries of C/C++ by JVM which may be hard hardware specific. Java native libraries is a collection of native libraries that are required by the execution engine.

 

Internal Architecture of JVM

 

Arslan ud Din Shafiq

Alibaba Cloud MVP, Alibaba Cloud Technical Author, Dzone MVB, Software Engineer, Software Developer, Software Designer, Web Engineer, Web Developer, Web Designer, Database Designer, Database Developer, Cloud Computing Specialist, Linux Expert, Servers, 3D Modeling, Blogger, Facebook Map Editor, Google Map Editor

Recent Posts

I have 20 years of experience in computer security advancement. What I can recommend to regular PC users

If you are living in a digital world you must know how to protect your…

4 years ago

Software Development Life Cycle Model (SDLC)

Software Development Life Cycle Model, also known as SDLC or Software Development Process, is base…

4 years ago

How to Install Go Lang on CentOS 8

Go, often referred to as golang is a modern open-source programming language created by Google…

4 years ago

SE Ranking in [2020]. What is SEO in marketing?

Torque published an article on October 18, 2016, about WordPress statistics. According to this article,…

4 years ago

PostgreSQL Version via Command Line & SQL Shell

PostgreSQL, often known simply as Postgres, is an open-source general-purpose object-relational database management system. In…

4 years ago

Google SEO: 15 Best ways about how can I do SEO for Free?

SEO is free as well as paid. To achieve SE ranking, money is not enough.…

5 years ago