当前位置:网站首页>Deep understanding of JVM (V) - garbage collection (II)
Deep understanding of JVM (V) - garbage collection (II)
2022-06-30 18:03:00 【Zhaoliwen is a pig】
In depth understanding of JVM( 5、 ... and )—— Garbage collection ( Two )
List of articles
2、 Garbage collection algorithm
Mark - eliminate

Definition : As the name suggests , It refers to the process of garbage collection in the virtual machine , Firstly, the recyclable object is determined by marking algorithm , Then the garbage collector clears the corresponding content according to the identification , Make room for heap memory
- Freeing up memory space here does not clear bytes of memory space 0, Instead, record the start and end address of this memory , The next time you allocate memory , Will directly Cover This memory
shortcoming : It is easy to produce a large number of memory fragments , May not be able to meet the memory allocation of large objects , Once the object cannot be allocated , That would lead to jvm start-up gc, Once started gc, Our application will pause , This causes the response speed of the application to slow down
Mark - Arrangement

Mark - Arrangement Will not be GC Root Referenced object recycling , Know the memory space it occupies . Then sort out the remaining objects , It can effectively avoid problems caused by memory fragmentation , But because the whole takes some time , So it's less efficient
Copy




Divide the memory into two areas of equal size ,FROM and TO(TO Empty in middle ). First will be GC Root The referenced object is from FROM Put in TO in , Recycling is not GC Root Referenced object . Then exchange FROM and TO. This can also avoid the problem of memory fragmentation , But it takes up double the memory space .
3、 Generational recycling

Recycling process
The newly created objects are placed in The new generation of Eden in

When there is not enough memory in the garden of Eden , There will be a garbage collection , The recycling at this time is called Minor GC
Minor GC Will The garden of Eden and the survival zone FROM Living objects First Copied to the Survival zone TO in , And let it Life plus 1, Again Swap two surviving areas



Create the object again , If the new generation of Eden is full again , will Trigger again Minor GC( Will trigger stop the world, Pause other user threads , Just let the garbage collection thread work ), At this time, we will not only recycle the garbage in the garden of Eden , And recycle the garbage in the surviving areas , Then copy the active object to the surviving area TO in . After recycling, two surviving areas will be exchanged , And let the objects in the surviving area Life plus 1

If the object in the surviving area Life exceeds a certain threshold ( The maximum is 15,4bit), Will be Put in the older generation in

If the memory of the new generation and the old generation is full , It will trigger first Minor GC, Trigger again Full GC, scanning In the new generation and the old generation All objects that are no longer in use and recycle
GC analysis
Large object processing strategy
When I meet a A larger object when , Even the new generation The garden of Eden It's empty , also The object cannot be accommodated when , The object will be Directly promoted to the elderly generation
Thread memory overflow
A thread's memory overflowed and threw an exception (out of memory), Won't let other threads end
This is because when a thread Throw out OOM After abnormality , All the memory resources it occupies will be released , This will not affect the operation of other threads , The process is still normal
边栏推荐
- Exploration and practice of "flow batch integration" in JD
- Analysis on the construction scheme and necessity of constructing expressway video monitoring platform
- 元宇宙带来的游戏变革会是怎样的?
- 腾讯云安装mysql数据库
- MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc
- Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence
- K-line diagram interpretation and practical application skills (see position entry)
- [BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
- 基于SSH的客户关系CRM管理系统
- Simulation of campus network design based on ENSP
猜你喜欢
![[零基础学IoT Pwn] 环境搭建](/img/3b/a0689a1570fcc40bb9a5a4e9cdc63c.png)
[零基础学IoT Pwn] 环境搭建

自旋锁探秘

China Infrastructure Development Association: electronic contract is recommended

Tubes响应性数据系统的设计与原理

Word中添加代码块(转载)

5G商用三年,未来创新何去何从?

Implementation of graduation project management system based on SSM

Daily question brushing record (IX)

基于eNSP的校园网设计的仿真模拟

Advanced Mathematics (Seventh Edition) Tongji University General exercises one person solution
随机推荐
Solution: STM32 failed to parse data using cjson
Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence
News management system based on SSM
Exch:exchange server 2013 is about to end support
MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc
[machine learning] K-means clustering analysis
Add code block in word (Reprint)
[sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
canvas云朵形状动画
Spin lock exploration
[零基础学IoT Pwn] 环境搭建
大文件处理(上传,下载)思考
Exch:完整性检查 Database Integrity Checking
Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
Several points in MySQL that are easy to ignore and forget
TCP session hijacking based on hunt1.5
What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
如何写一个技术方案
网络:服务器网卡组技术原理与实践
基于eNSP的校园网设计的仿真模拟