当前位置:网站首页>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
边栏推荐
- 基于SSM的新闻管理系统
- IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
- Tubes响应性数据系统的设计与原理
- How to write a technical proposal
- 巴比特 | 元宇宙每日必读:未成年人打赏后要求退款,虚拟主播称自己是大冤种,怎么看待这个监管漏洞?...
- NFT: 开启加密艺术时代的无限可能
- Redis (II) -- persistence
- 基于SSH的客户关系CRM管理系统
- Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
- Hyper-V: enable SR-IOV in virtual network
猜你喜欢
【架构】1366- 如何画出一张优秀的架构图
Rainbow Brackets 插件的快捷键
同济、阿里的CVPR 2022最佳学生论文奖研究了什么?这是一作的解读
MySQL之零碎知识点
Design and principle of tubes responsive data system
vue3 响应式数据库—— reactive
leetcode:1042. Do not plant flowers adjacent to each other [randomly fill in qualified + no contradiction will be formed behind + set.pop]
每日面试1题-如何防止CDN防护被绕过
Apache 解析漏洞(CVE-2017-15715)_漏洞复现
5G商用三年,未来创新何去何从?
随机推荐
Rainbow Brackets 插件的快捷键
基于eNSP的校园网设计的仿真模拟
[binary tree] preorder traversal to construct binary search tree
Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
5g business is officially commercial. What are the opportunities for radio and television?
A tough battle for Tencent cloud
[sword finger offer] 53 - I. find the number I in the sorted array
[sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
MSF后渗透总结
Spin lock exploration
现在玩期货需要注意什么,在哪里开户比较安全,我第一次接触
TFTP下载kernel,nfs挂载文件系统
[BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
NFT铸造交易平台开发详情
New skill: accelerate node through code cache JS startup
【义修换届大礼包】
Development details of NFT casting trading platform
Parker proportional overflow valve rs10r35s4sn1jw
Small Tools(3) 集成Knife4j3.0.3接口文档
How to write a technical proposal