Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How Many Types of Memory Areas are Allocated by JVM?
Next article icon

How Many Types of Memory Areas are Allocated by JVM?

Last Updated : 03 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

JVM (Java Virtual Machine) is an abstract machine. In other words, it is a program/software that takes Java bytecode and converts the bytecode (line by line) into machine-understandable code. JVM acts as a run-time engine to run Java applications. JVM is the one that calls the main method present in Java code. JVM is a part of the JRE(Java Runtime Environment). 

Operations Performed by JVM

The various operations performed by the JVM are listed below:

  • Loading of code: The JVM loads class files that contain Java bytecode into memory. This means it finds the necessary files and gets them ready to run.
  • Verification of code: The JVM checks the bytecode it has loaded to make sure it's correct and safe.
  • Executing the code: The JVM runs the verified bytecode by turning it into machine code that the computer can understand.
  • Providing a Runtime Environment: The JVM provides a runtime environment that helps manage system resources, memory, and garbage collection.

ClassLoader Subsystem

The ClassLoader is a subsystem of the JVM responsible for loading class files. It primarily performs three activities:

  • Loading: Locates and loads the class files into memory.
  • Linking: Combines the class files and resolves dependencies.
  • Initialization: Initializes static variables and executes static blocks.

Types of Memory Areas Allocated By JVM

The JVM allocates memory into 5 distinct areas to carry out its operations. These areas are:

  • Class(Method) Area
  • Heap
  • Stack
  • Program Counter Register (PC Register)
  • Native Method Stack

The image below demonstrates the types of memory areas allocated by JVM:

JVM Architecture


1. Class (Method) Area

The Class (Method) Area is a memory block in the JVM that stores important information about classes. It includes:

  • Class Code: The bytecode that defines the class itself.
  • Variable Code: This includes static variables and runtime constants associated with the class.
  • Method Code: The bytecode for all the methods defined in the class, including constructors.

Note: In Java 8 and later versions, the concept of the Method Area still exists but works differently now. Instead of being part of the heap memory, the class information like static variables and method details are stored in a separate space called Metaspace. This Metaspace lives outside the heap, using native system memory. So, static data and class metadata don’t take up space in the heap anymore.

The class area stores class-level data of every class such as the runtime constant pool, field and method data and the code for methods, enabling the JVM to execute Java programs effectively.

2. Heap

The Heap Area is the memory block in the JVM where all objects are created and stored. It is used to allocate memory for:

  • Objects: Instances of classes created during the execution of a program.
  • Class Interfaces: Memory for class interfaces is also allocated here.
  • Arrays: Since arrays are considered objects in Java, their memory is allocated in the heap as well.

Note: Static variables and methods are not stored in the heap from Java 8 onwards, instead they stored in the metaspace. The heap stores instance data like objects and array.

The Heap Area is crucial for dynamic memory allocation, allowing the JVM to allocate memory for objects at runtime.

3. Stack 

In Java, each thread has its own stack called the Run-Time Stack, created when the thread starts.

  • IT stores various things like method call frames, local varaibles, method parameters and return addresses.
  • The JVM only performs two operations directly on the stacks that is push(when a method is called) and pop(when a method execution completes).
  • Every method call performed by the thread is stored in the corresponding run-time stack. The stack area is used to store Method call information, Local variables, Method parameters, Return Address
  • After completing all method calls the stack becomes empty and that empty stack is destroyed by the JVM just before terminating the thread.

4. Program Counter Register

Each JVM thread has its own PC register that stores the address of the JVM instruction currently being executed.

  • For non-native method the PC hold address of the available JVM instruction.
  • For native method, the PC register value is undefined.

Note: PC register is capable of storing the return address or a native pointer on some specific platform.

5. Native Method Stack

It is also known as C stack and this area is used to store the state of native methods which are written in languages other than Java (for e.g C or C++).

  • Each thread has its own native method stack, which can be fixed or dynamically sized.
  • This stack handles native method calls and execution.

Next Article
How Many Types of Memory Areas are Allocated by JVM?

P

PREMMAURYA
Improve
Article Tags :
  • Java
  • java-basics
  • java-JVM
Practice Tags :
  • Java

Similar Reads

    How MATLAB Allocates Memory?
    MATLAB is used to analyze and design the system and products transforming our world. MATLAB is a matrix-based language that is the most natural way to express Computational Mathematics. that's Built-in graphics that make it easy to visualize and gain insights from data.  The purpose of memory alloca
    5 min read
    Java Stack vs Heap Memory Allocation
    In Java, memory allocation is primarily divided into two categories, i.e., Stack and Heap memory. Both are used for different purposes, and they have different characteristics.Stack Memory: This memory is used to store local variables, method calls, and reference data during program execution.Heap M
    4 min read
    How to Generate JVM Heap Memory Dump?
    Java Heap dump is a snapshot of all java objects that are present in the JVM(Java Virtual Machine) at a certain point in time. The JVM allocates memory for objects which are class instances or arrays in the heap memory. When the objects are no longer needed or are no more referenced, the Garbage Col
    7 min read
    How are Java Objects Stored in Memory?
    In Java, memory management is handled by the Java Virtual Machine (JVM). The breakdown of how objects are stored in memory:All Java objects are dynamically stored in the heap memory.References to these objects are stored in the stack memory.Objects are created using the "new" keyword and are allocat
    5 min read
    Types of memory on a Cisco device
    Cisco IOS (Internetwork Operating System) is a proprietary operating system that runs on Cisco Systems routers and switches. The core function of Cisco IOS is to enable data communications between network nodes. Types of memory on a Cisco device :Cisco devices usually have four types of memory that
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences