当前位置:网站首页>The meaning and trigger conditions of gc
The meaning and trigger conditions of gc
2022-08-01 10:02:00 【Drgom】
The necessity of jvm gc
When the heap memory of the jvm is not enough, you need to perform gc to release the memory
Conditions for gc execution
Before the jvm executes gc, all threads must be stopped and gc executed
What object is recycled by gc
The JVM uses the reachability algorithm to recover unreferenced objects. The reference counting method cannot count the applications between objects.
When gc, whether the object is recycled or not depends on what java reference type the object is
- FinalReference = "will never be recycled
- SoftReference = "Reclaimed before memory leaks
- WeakReference = "Will be recycled during garbage collection
- PhantomReference=>anytime

gc classification and execution environment
A simple analysis of the structure of the heap
Before jvm1.8, the heap memory was divided into Eden, S0, S1, Old Meomory, Perm (abolished after 1.8), each newly instantiated object will be put into young gen, when the Eden+s0 area is full,Perform minor gc. After 15 times of gc, the objects that still exist are upgraded to the old age (or the object is relatively large, and if the object exceeds the threshold, it will be directly placed in the old age). When the entire heap memory is not enough, the entire heap memory will be gc.is major gc.
Introduction to commonly used gc algorithms
- Mark-Sweep Algorithm: Mark useless objects, and then clean up and recycle.Disadvantages: Inefficient, generates garbage debris.
- Copying algorithm: Divide two memory areas of equal size according to capacity. When one block is used up, copy the live objects to another block, and then clean up the used memory space at one time.Disadvantage: The memory usage is not high, only half of the original.
- Marking-cleaning algorithm: mark useless objects, move all surviving objects to one end, and then directly clear the memory beyond the end boundary.
- Generation algorithm: Divide the memory into several blocks according to the life cycle of the object, generally the new generation and the old generation, the new generation basically adopts the copy algorithm, and the old generation adopts the mark sorting algorithm
gc collector classification and advantages and disadvantages
| Gc collector | Algorithms used | Action area | Features | Benefits | Disadvantages |
|---|---|---|---|---|---|
| Serial Collector | Copy Algorithm | New Generation | Markup and cleanup are single-threaded | Simple and efficient | The jvm must be paused, the pause time is long |
| Serial Old Collector | Markup-Organization | Old Age | Markup and cleanup are single-threaded | Simple and efficient | The jvm must be paused, the pause time is long |
| ParNew Collector | Copy Algorithm | New Generation | Parallel | Good throughput | The jvm must be paused, the pause time is long |
| ParallelScavenge Collector | Copy Algorithm | New Generation | Parallel | Precise control of gc time | It is difficult to control the time of gc well |
| Parold Collector | Copy Algorithm | Old Age | Parallel | Good throughput | The jvm must be paused, the pause time is long |
| CMS collector | Markup Clear | Old Age | Parallel | Minimum pause time | Gc takes longer to handle floating garbage |
| G1 Collector | Tag Collation | Entire heap | Parallel | Efficient, no fragmentation, GC pause time can be specified | G1 requires additional memory to record data partitions |
| ZGC collector | Tag Collation | Entire heap | Parallel | Efficient and low-latency processing of large memory gc | Generate floating garbage |
Definition of Floating Garbage: The marking process marks living objects. Judging from the reachability of GCRoot, the objects are alive, but the "dead" objects cannot be marked.If it is marked as alive in the initial marking stage, and "dies" during concurrent operation, the remark process cannot be corrected, so it becomes floating garbage and needs to wait for the arrival of the next gc
边栏推荐
- 2022年7月31日--使用C#迈出第一步--使用 C# 创建具有约定、空格和注释的易读代码
- 报告:想学AI的学生数量已涨200%,老师都不够用了
- Introduction and application of pointers
- 企业微信群:机器人定时提醒功能数据库配置化
- C语言小游戏——扫雷
- How to implement deep copy in js?
- Introduction and application of heap memory (including examples)
- VS“无法查找或打开PDB文件”是怎么回事?如何解决
- 如何从完美的智能合约中窃取 1 亿美元
- cisco交换机基本配置命令(华为交换机保存命令是什么)
猜你喜欢

Google Earth Engine APP——15行代码搞定一个inspector高程监测APP

CTFshow,命令执行:web37
Get the Token from the revised version of Qubutu Bed

node 格式化时间的传统做法与高级做法(moment)

AC与瘦AP的WLAN组网实验

PowerPC技术与市场杂谈

CTO strongly banning the use of the Calendar, that in what?

BGP综合实验

报告:想学AI的学生数量已涨200%,老师都不够用了

IntellJ IDEA如何显示换行符(line endings)
随机推荐
WTM:ASP.NET Core快速开发利器!
笔记。。。。
notes....
Introduction and application of pointers
notes....
mysql login in cmd and basic operations of database and table
Quantify daily work metrics
Go-Excelize API源码阅读(八)——GroupSheets(sheets []string)、UngroupSheets()
7/31 训练日志
IntellJ IDEA如何显示换行符(line endings)
阿里腾讯面试一二
会议OA(待开会议&所有会议)
Introduction and application of heap memory (including examples)
Comprehensive experiment BGP
消息队列面试题(2022最新整理)
ClickHouse入门介绍与其特性
Manual upgrade and optimization tutorial of Lsky Pro Enterprise Edition
STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
基于CAP组件实现补偿事务与消息幂等性
已解决(pip安装库报错)Consider using the-- user option or check the permissions.