当前位置:网站首页>JVM garbage collector details
JVM garbage collector details
2022-07-25 15:20:00 【Literary youth learn programming】
Serial and parallel collectors
Serial recovery : JDK1.5 The default algorithm before The disadvantage is that there is only one thread , It takes a long time for the program to stop when garbage collection is performed
Parallel recycling : Multiple threads perform garbage collection for throughput systems , The system will stop when it is recycled
serial The collector
The serial collector is the oldest , The most stable and efficient collector , There may be a longer pause , Use only one thread to recycle . The new generation 、 The old days used serial recycling ; New generation replication algorithms 、 Old age mark - Compress ; In the process of garbage collection Stop The World( Service suspension )
A single thread collector , When it comes to garbage collection , All other worker threads must be suspended until the end of its collection .
characteristic :CPU The highest utilization rate , Pause time means that the user waits for a long time .
Applicable scenario : Small applications
adopt JVM Parameters -XX:+UseSerialGC You can use a serial garbage collector .
ParNew The collector
ParNew The collector is essentially Serial Multithreaded version of collector . The new generation is parallel , Old age serial ; New generation replication algorithms 、 Old age mark - Compress
Parameter control :-XX:+UseParNewGC ParNew The collector
-XX:ParallelGCThreads Limit the number of threads
parallel The collector
Parallel Scavenge Collector similar ParNew The collector ,Parallel The collector pays more attention to the throughput of the system . The adaptive adjustment strategy can be turned on by parameters , The virtual machine collects performance monitoring information based on the current system performance , Dynamically adjust these parameters to provide the most appropriate pause time or maximum throughput ; It can also be controlled by parameters GC Time is no more than milliseconds or proportion ; New generation replication algorithms 、 Old age mark - Compress
Use multithreading to scan and compress the heap
characteristic : Short pause time , High recovery efficiency , High throughput requirements .
Applicable scenario : Large applications , Scientific Computing , Large scale data collection, etc .
adopt JVM Parameters XX:+USeParNewGC Turn on the concurrent tag scan garbage collector .
cms The collector
CMS(Concurrent Mark Sweep) A collector is one that aims to obtain the shortest recovery pause time . At present, a large part of Java Applications are focused on Internet sites or B/S On the server side of the system , Such applications pay special attention to the response speed of services , I hope the system has the shortest pause time , To give users a better experience .
From the name ( contain “Mark Sweep”) As you can see from the above CMS The collector is based on “ Mark - eliminate ” algorithmic , Its operation process is more complicated than the previous collectors , The whole process is divided into 4 A step , Include :
Initial marker (CMS initial mark)
Concurrent Tags (CMS concurrent mark)
Re label (CMS remark)
Concurrent elimination (CMS concurrent sweep)
Where the initial mark 、 Re marking these two steps still requires “Stop The World”. The initial mark is just a mark GC Roots Objects that can be directly related to , fast , The concurrency tagging phase is going on GC Roots Tracing The process of , The retag phase is to fix the concurrent tagging period , The tag record of the part of the object whose tag changes as the user program continues to operate , The pause time of this stage is generally a little longer than that of the initial marking stage , But it takes much less time than concurrent tagging .
Due to the most time-consuming concurrent marking and concurrent clearing process in the whole process , Collector threads can work with user threads , So in general ,CMS The collector's memory recovery process is performed concurrently with the user thread . Old age collector ( The new generation uses ParNew)
advantage : Concurrent collection 、 Low pause
shortcoming : Generate a lot of space debris 、 The concurrency phase reduces throughput
use “ Mark - eliminate ” Algorithm implementation , Use a multithreaded algorithm to scan the heap , Recycle objects found to be unused .
(1) Initial marker
(2) Concurrent Tags
(3) Concurrent preprocessing
(4) Re label
(5) Concurrent elimination
(6) Concurrent reset
characteristic : Response time first , Reduce garbage collection pause time
Adaptive scene : Large servers, etc .
adopt JVM Parameters -XX:+UseConcMarkSweepGC Set up
g1 The collector
stay G1 in , The heap is divided into Many consecutive areas (region). use G1 Algorithm for recycling , Absorbed CMS Collector features .
characteristic : Support a large pile , High throughput
-- Support more CPU And the garbage collection thread
-- When the main thread is paused , Use parallel collection
-- With the main thread running , Use concurrent collection
Real time target : Configurable in N In milliseconds, it only takes up M Millisecond time for garbage collection
adopt JVM Parameters -XX:+UseG1GC Use G1 Garbage collector
Be careful : Concurrency refers to a processor processing multiple tasks at the same time .
Parallel refers to multiple processors or multi-core processors processing multiple different tasks at the same time .
Concurrency is logically simultaneous (simultaneous), And parallel is physical simultaneity .
A metaphor : Concurrent is a person eat three steamed bread at the same time , In parallel, three people eat three steamed buns at the same time .
边栏推荐
猜你喜欢

How to solve the problem of scanf compilation error in Visual Studio

Understanding the execution order of T-SQL query from the execution order of join on and where

推荐10个堪称神器的学习网站

异步fifo的实现

spark分区算子partitionBy、coalesce、repartition

在win10系统下使用命令查看WiFi连接密码

What is the Internet of things

Spark AQE

延迟加载源码剖析:

Vs2010添加wap移动窗体模板
随机推荐
How spark gets columns in dataframe --column, $, column, apply
Idea护眼色设置
简易轮播图和打地鼠
Sublimetext-win10 cursor following problem
推荐10个堪称神器的学习网站
Object.prototype.hasOwnProperty() 和 in
ice 100G 网卡分片报文 hash 问题
Solve the error caused by too large file when uploading file by asp.net
请问seata中mysql参数每个客户端连接最大的错误允许数量要怎么理解呢?
任务、微任务、队列和调度(动画展示每一步调用)
本地缓存--Ehcache
Implementation of asynchronous FIFO
When using jetty to run items, an error is reported: form too large or form too many keys
JS 同步、异步,宏任务、微任务概述
树莓派入门:树莓派的初始设置
Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
Fast-lio: fast and robust laser inertial odometer based on tightly coupled IEKF
用setTimeout模拟setInterval定时器
Outline and box shadow to achieve the highlight effect of contour fillet
Single or multiple human posture estimation using openpose