Java garbage collection basics

JRE:
JVM,Java platporm core classes, supporting Java platform libraries.

Performance indicators:
corresponding capabilities, throughput

The main components of jvm
include: class loader, runtime data area, execution engine,
highlighted components are related to jvm performance: Heap: where objects are stored. The Jit compiler also has a large impact on performance, but rarely can be tuned. Reasonable selection of Garbage Collector has a great impact on performance.
Insert image description here

Garbage Collector
process:
1. Mark, mark the unreferenced objects. The yellow in the figure indicates the marked objects.
Insert image description here

2a, delete, clean up unreferenced objects,
Insert image description here

2b, delete with compacting, delete compression. To improve performance, the remaining objects can be compressed together so that subsequent memory allocations are faster and easier.
Insert image description here

Why is generational garbage collection needed?
As mentioned before, garbage cleaning and tag cleaning are very inefficient. As more and more objects are allocated, the garbage collection time will become longer and longer, the stw time will be very long, and the performance will become worse and worse. Then through a lot of experience, the survival time of most objects is very short. Therefore, generational garbage treatment is required.

jvm中堆的拆分
the heap is broken up into smaller parts or generations. The heap parts are: Young Generation, Old Generation, and Permanent Generation.
Young Generation 分为3parts:eden,Survivor “from”,Survivor “to”。
Insert image description here

Garbage collection process
1. First, all newly created objects are allocated space in the eden area.
Insert image description here

2. When the eden area is filled, a Minor Garbage Collection will be performed.
Insert image description here

3. After clearing all unreferenced objects in Eden, move the remaining objects in the Eden area to one of the Survivor areas, such as S0, and give the object an age of 1.
Insert image description here

4. When the Eden area is filled again, the next Minor GC is performed. After clearing all unreferenced objects in the Eden area and S0 area, move the remaining objects in these two areas to S1, and add one age to all objects.
Insert image description here

5. During the next Minor GC, when the objects in the Survivor area reach a certain age such as: 8, they will be moved to Old Generation.
Insert image description here

6. When the Old Generation is filled, a Major GC will be performed to clean and compress the control.
Insert image description here

Visual GC plug-in
Open the following file and install the Visual GC plug-in.
Insert image description here

Rendering:

Insert image description here

Guess you like

Origin blog.csdn.net/Edward_hjh/article/details/127108872