当前位置:网站首页>JVM之垃圾回收器上篇
JVM之垃圾回收器上篇
2022-07-06 09:30:00 【机智的爆爆哥】
1.垃圾回收器分类
按工作模式分类,垃圾回收器可以分为:
- 并发式垃圾回收
- 独占式垃圾回收
并发式指的是多个线程交替执行垃圾回收,使得程序的暂停时间减少了。
独占式指的是一旦执行垃圾回收,停止其他用户线程,也就是说一旦执行了垃圾回收,用户程序就不能工作了。
按线程数分类,垃圾回收器可以分为:
- 串行垃圾回收器
- 并行垃圾回收器
- 并发垃圾回收器
串行GC只适合于单核CPU上使用,效果比较好,现在一般都不用了。
并行GC指的是多个线程同时执行垃圾回收,但还是属于独占式的,会有stop the world的现象。
并发GC指的是垃圾回收线程与用户线程交替执行,不许需要停顿。
按碎片处理分类,垃圾回收器可以分为:
- 压缩式垃圾回收器
- 非压缩式垃圾回收器
这个主要针对的是标记清除算法,有些回收器是不采用这个算法的,所以才会有此分类。
按工作内存分类,垃圾回收器可以分为新生代与老年代的垃圾回收,因为这两个区域差别很大,根据这两个区域产生了不同的垃圾回收器。
2.评估GC的性能指标
指标有许多种,大致简单介绍下。
吞吐量:指用户线程执行时间占总时间的比例,当然是越大越好。
垃圾收集开销:指垃圾回收线程占总时间的比例,越小越好。
暂停时间:这是我们常说的STW,不管哪个垃圾回收器都会有停顿时间,这是垃圾回收线程导致的,我们希望越短越好。
收集频率:指的是垃圾回收次数在一定时间内的比例,这个根据情况而定,当频率高了,单位暂停时间短,频率低了,单位暂停时间长。
内存占用:一般指的是堆区域的占用,越大能够存放的对象也就越多。
快速:有点抽象,我们希望对象不被使用后越快回收越好。
注意到我前面加粗的名词了吗?
这些组成了不可能三角,内存占用大了,垃圾回收一次对象的时间就会越长,也使得暂停时间越久,但吞吐量能够提高,反正内存小,吞吐量变低,但是暂停时间会变得小一些。
但还是有个特定标准的,因为内存相对比较便宜,我们希望在最大吞吐量的前提下,能够降低停顿时间。
3.垃圾回收器的发展史
只做了解,这里就截了张图,可以简单看下红框内容。

4.七种经典垃圾回收器
串行GC:Serial,Serial Old,这两个的区别在于前者是回收新生代的,后者回收老年代。
并行GC:ParNew,Parallel Scavenge,Parallel Old。
并发GC:CMS,G1,其中G1算上全能型选手。

5.垃圾回收器的组合关系
要知道,并不是一个JVM就用一种垃圾回收器的,他们是搭配使用的,组合如下,虚线表示会在后期版本剔除掉。

6.查看默认的垃圾回收器
在任意的程序启动前,我们可以加入JVM参数,打印下默认的垃圾回收器是什么。
-XX:+PrintCommandLineFlags
打印结果如下,jdk默认用的是ParallelGC
-XX:InitialHeapSize=265723392 -XX:MaxHeapSize=4251574272 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC咱们将在下一篇重点讲述不同的垃圾回收器。
边栏推荐
- The most lost road I have ever walked through is the brain circuit of ByteDance programmers
- 7-12 inventory code base
- The QT program compiled on CentOS lacks a MySQL driven solution
- ~85 transition
- High performance mysql (Third Edition) notes
- 100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
- Shell_ 02_ Text three swordsman
- ~79 Movie card exercise
- GCC error: terminate called after throwing an instance of 'std:: regex_ error‘ what(): regex
- Many papers on ByteDance have been selected into CVPR 2021, and the selected dry goods are here
猜你喜欢

Koa Middleware

redux使用说明

The QT program compiled on CentOS lacks a MySQL driven solution

Data config problem: the reference to entity 'useunicode' must end with ';' delimiter.

Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.

8086 CPU 内部结构

字节跳动春招攻略:学长学姐笔经面经,还有出题人「锦囊」

The daemon thread starts redis and modifies the configuration file

README. txt

Resume of a microservice architecture teacher with 10 years of work experience
随机推荐
~77 linear gradient
MySQL字符串函数
Description of project structure configuration of idea
我走過最迷的路,是字節跳動程序員的腦回路
The QT program compiled on CentOS lacks a MySQL driven solution
Activiti目录(三)部署流程、发起流程
唯有学C不负众望 TOP4 S1E6:数据类型
汇编语言寻址方式
DOS function call
When it comes to Google i/o, this is how ByteDance is applied to flutter
README. txt
Continue and break jump out of multiple loops
The daemon thread starts redis and modifies the configuration file
How to configure hosts when setting up Eureka
yum install xxx报错
Data transfer instruction
~84 form supplement
Koa Middleware
唯有學C不負眾望 TOP5 S1E8|S1E9:字符和字符串&&算術運算符
Mongodb learning notes