Link to the original English text, translated by Abhishek Gupta. Translator: youfu
This article will introduce some basic concepts of the JVM memory structure, and will soon talk about the permanent generation. Let's see where it went after Java SE 8 was released.
Basic knowledge
JVM is just another process running on your system. The magic begins with a Java command. Just like any operating system process, JVM also needs memory to perform its runtime operations. Remember-JVM itself is a software abstraction layer of hardware, where Java programs can be run, as well as the platform independence we boast and Wora (one write, run everywhere ).
Faster than JVM Memory Structure
As the virtual machine specification says, the memory in the JVM is divided into five virtual areas.
- Heap
- Method Area (non-heap)
- JVM Stack
- Local Stack
- PC register
Heap
- Every object allocated in your Java program needs to be stored in the memory. Heap is the place where these instantiated objects are stored. Yes -- all blame the new operator. It fills up your Java heap!
- It is shared by all threads.
- When the heap is exhausted, the JVM will throw a java. Lang. outofmemoryerror exception.
- The heap size can be adjusted using the JVM options-XMS and-xmx.
Heap is divided:
- Eden area-new objects or objects with short lifecycles are stored in this area. The size of this area can be adjusted using the-XX: newsize and-XX: maxnewsize parameters. The new generation GC (Garbage Collector) cleans up this area.
- Protected vor zone-objects still referenced after garbage collection in the Eden zone will be in this zone. The size of this zone can be adjusted by the JVM parameter-XX: Invalid vorratio.
- Old age-objects that survive after multiple GC operations in the Eden and vor areas (of course, thanks to those lingering references) will be stored in this area. A Special Garbage Collector is responsible for this area. Objects in the old generation are recycled by the GC (Major GC) of the old generation.
Method Area
It is also called a non-heap region (in the implementation of the hotspot JVM)
It is divided into two main subareas
- Persistent generation-this region stores class-related data including class definitions, structures, fields, methods (data and code), and constants. It can be adjusted through-XX: permsize and-XX: maxpermsize. If the space is used up, the Java. Lang. outofmemoryerror: permgen space exception will occur.
- Code cache-this cache area is used to store compiled code. The compiled code is a local code (hardware-related) generated by the JIT (Just In Time) compiler, which is unique to Oracle hotspot JVM.
JVM Stack
- It is closely related to methods in Java classes.
- It stores the intermediate results and return values of local variables and method calls.
- Every thread in Java has its own stack, Which is inaccessible to other threads.
- The JVM option-XSS can be used for adjustment.
Local Stack
- Used for local methods (non-Java code)
- Distribute by thread
PC register
- Program counters for specific threads
- Contains the address of the command being executed by JVM (its value is not defined if it is a local method)
Well, this is the basic knowledge of JVM memory partitions. Let's talk about this topic.
So where is the permanent generation?
In fact, the permanent generation has been completely deleted. Instead, another memory area is also called the metadata.
Meta space-Quick Start
- It is part of the local heap memory.
- It can be adjusted through-XX: metaspacesize and-XX: maxmetaspacesize.
- When the threshold value specified by XX: metaspacesize is reached, the region is cleaned up.
- If the memory of the local space is exhausted, the system will receive an error message from Java. Lang. outofmemoryerror: Metadata space.
- The JVM parameters-XX: permsize and-XX: maxpermsize related to the persistent generation will be ignored.
Of course, this is just the tip of the iceberg. For a better understanding of JVM, the best information is its own virtual machine specifications!
Permanent generation of JVM-where to go?