当前位置:网站首页>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
边栏推荐
- Interview shock 60: what will cause MySQL index invalidation?
- K-line diagram interpretation and practical application skills (see position entry)
- Small Tools(3) 集成Knife4j3.0.3接口文档
- Several points in MySQL that are easy to ignore and forget
- [bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
- Thinking on large file processing (upload, download)
- leetcode:787. The cheapest transfer flight in station K [k-step shortest path + DFS memory + defaultdict (dict)]
- Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea
- 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
- [Architecture] 1366- how to draw an excellent architecture diagram
猜你喜欢

Horizontal visual error effect JS special effect code

Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases

MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等

Redis (III) - transaction
![[Netease Yunxin] playback demo build: unable to convert parameter 1 from](/img/6e/41e1eafd4c863c9e5f3a545b69a257.png)
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**

Write the simplest small program in C language Hello World

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

Design and principle of tubes responsive data system

New skill: accelerate node through code cache JS startup

5g has been in business for three years. Where will innovation go in the future?
随机推荐
基于eNSP的校园网设计的仿真模拟
A tough battle for Tencent cloud
NFT铸造交易平台开发详情
每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
Compile and generate busybox file system
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
Rexroth hydraulic control check valve z2s10-1-3x/
Key to understanding the trend of spot Silver
[零基础学IoT Pwn] 环境搭建
5G商用三年,未来创新何去何从?
Several points in MySQL that are easy to ignore and forget
canvas鼠标控制重力js特效
[sword finger offer] 53 - I. find the number I in the sorted array
How to write a technical proposal
Exch:修复丢失的系统邮箱
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
Nft: unlimited possibilities to open the era of encryption Art
腾讯云安装mysql数据库
Flutter custom component
Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)