JVM Runtime Data Areas
This chapter provides tutorial notes and example codes on JVM runtime data areas. Topics include introduction of JVM runtime data areas: Method Area, Heap, Direct Memory, PC Registers, JVM Stacks, and Native Method Stacks; different between thread-shared and per-thread data areas; demonstration programs for different types of OutOfMemoryError exceptions; demonstration program for StackOverflowError exception.
What Are Runtime Data Areas?
Method Area Expansion Demonstration
OutOfMemoryError on the Method Area
Method Area Growth with Dynamically Generated Classes
Garbage Collection Issue with Dynamically Generated Classes
Interned Strings Stored in Heap
Heap Expansion Demonstration
Direct Memory Expansion Demonstration
allocateMemory() Method on Direct Memory
JVM Stack Expansion Demonstration
PC Register and Native Method Stack
- JVM uses 6 types of data areas at runtime: Method Area, Heap, Direct Memory, PC Registers, JVM Stacks, and Native Method Stacks.
- Method Area, also called Permanent Generation (PermGen) space or Class Metadata space, stores class definitions and constants.
- Heap stores dynamically created data objects (instances of classes and arrays).
- Direct Memory stores dynamically created ByteBuffer objects and other data elements created by native methods.
- Method Area, Heap and Direct Memory are created at startup time and shared by all threads.
- Method Area, Heap and Direct Memory are managed by garbage collectors to remove unused objects.
- "-XX:MaxMetaspaceSize=" option sets the size limit on the Method Area.
- "-Xmx" option sets the size limit on Heap and on Direct Memory.
- When the Method Area runs out of memory, JVM throws the "OutOfMemoryError: Metaspace" exception.
- When the Heap runs out of memory, JVM throws the "OutOfMemoryError: Java heap space" exception.
- When the Direct Memory runs out of memory, JVM throws the "OutOfMemoryError: Direct buffer memory" exception.
- PC Registers, JVM Stacks and Native Method Stacks are created when threads are created and associated with threads one copy per thread.
- A PC Register, short for Program Counter Register, stores the address of the instruction currently being executed in the thread the PC Registered is associated to.
- A JVM Stack stores a stack of frames. The top frame stores local variables, partial calculation results, method call information
for the method currently being executed in the thread the JVM Stack is associated to.
- A Native Method Stack stores a stack of frames similar to a JVM Stack. But it is used to help executing native methods
in the thread the JVM Stack is associated to.
- "-Xss" option sets the size limit on a single JVM Stack data area.
- When a JVM Stack runs out of memory, JVM throws the "StackOverflowError" exception.
Table of Contents
About This Book
Downloading and Installing JDK 1.8.0 on Windows
Downloading and Installing JDK 1.7.0 on Windows
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
Sun's JVM - Java HotSpot VM
JRockit JVM 28.2.7 by Oracle Corporation
►JVM Runtime Data Areas
Memory Management and Garbage Collectors
Garbage Collection Tests
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
CDS (Class Data Sharing)
Micro Benchmark Runner and JVM Options
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations
PDF Printing Version