当前位置:网站首页>JVM Notes
JVM Notes
2022-08-04 04:05:00 【wuhui2100】
一、JVM笔记
1、根可达算法(javaAn object marked for recycling),Generally, it starts from four root nodes(线程栈变量、静态变量、常量池、JNI指针)
2、GC回收三种算法(According to the neutralization and application of these three algorithms, it forms its own uniqueGC)
1)、Mark-Sweep:标记清除
Delete the marked memory、Whether the corresponding memory address;resulting in the formation of fragmented spaces,So that the allocation fails when a large space object is required
2)、Copying:拷贝
Allocate several large spaces,According to the root reachable algorithm, find the available data and put it into another large space,Delete the corresponding large space to be reclaimed again
缺点:浪费空间
3)、Mark-Compact:标记压缩
When recycling, the available ones are reordered by the way
缺点:效率低,比copy还低
3、堆内存逻辑分区
Java1.8The default is to divide the memory into two generations,Recycling generally uses the tape recycling mechanism;It is divided into new generation and old generation
新生代使用copying(拷贝算法),老年代使用Mark Compact(标记压缩算法)
The ratio of the new generation to the old generation in memory is 1:3,而新生代中eden与survivor比例是8:1:1
1)、新生代使用copying(拷贝算法)
The first garbage collection of the young generation(major gc)Will Eden area(eden)The surviving data is copied to the surviving area(survivor-0)之后将edenZone deletion and recycling;
The second will be Eden(eden)Objects surviving in (survivor-0)幸存区0All objects are copied to the survivor area1(survivor-1)中 将对应的eden与survivor-0都回收;
The third timesurvivor-1拷贝回survivor-0中,回收eden与survivor-0区;
循环上面三个步骤;When the surviving object reaches the collection count threshold, the corresponding object is moved to the old generation
2)、老年代使用Mark Compact(标记压缩算法)或者Mark Sweep(标记清除算法)结合使用
Triggered when the old generation reaches the set thresholdfull gc
4、General diagram of the garbage collector
The garbage collector evolves as memory continues to grow
1)、serial The garbage collector is a few megabytes to tens of megabytes in memory,单线程的垃圾收集器(The process executed during recycling needs to be stopped and needs to wait for the recycling to complete,to use the program again)
即年轻代使用serial,老年代使用serial old垃圾收集器回收
2)、 Parallel ScavengeThe garbage collector is a few hundred megabytes to several megabytes of memoryG时,多线程垃圾收集器(The process executed during recycling needs to be stopped and needs to wait for the recycling to complete,to use the program again),Java1.8默认使用PS+PO的垃圾收集器组合
即年轻代使用Parallel Scavenge,老年代使用Parallel Old垃圾回收器
3)、CMS垃圾收集器,When the memory is dozensG时(Multithreading is not always better),引入CMS垃圾回收,That is, multiple worker threads work concurrently with multiple garbage collection threads
The simultaneous operation of the worker thread and the garbage collection thread may lead to misunderstanding that an object can be garbage collected,It needs a three-color marking algorithm to solve:
黑色标记:Satisfy yourself already marked、Objects that have already pointed to themselves are also marked(孩子)则为黑色
灰色标记:Mark it yourself done,Objects that have not yet been marked are marked in gray
白色标记:还没有遍历到的节点
当上图B->D,没有扫描到,业务逻辑实现A->D产生了,则会将Das garbage,CMS解决方案就是将A标记为灰色,Still missing the mark(不建议使用CMS)
4)、Epsilon在jvmNo garbage disposal is done,用于开发jvmpersonnel transferbug,And when it's big and not neededgcobject can be used to mark,Prevent other garbage collectors from operating on it
5)、G1垃圾收集器,Partitioning algorithm reclaims part of the area,All young generations will be reclaimed when reclaimed,When the new generation is largeSTW很长
Mainly for the partition algorithm,Concurrent collection will be partially recycled,压缩空闲空间不会延长GC的暂停时间,更容易预测GC暂停时间,Use for scenarios that do not require high throughput;G1Mainly physical generation(a small area),logical zoning
6)、ZGC垃圾回收器
Use paging algorithm(go lang回收算法),ZGCThe core algorithm of 颜色指针,Also partition,However, the new generation and the old generation are no longer partitioned,
7)、Shenandoah,Red Hat provides an open source garbage collector
5、Java命令进行定位
1)、jsp 列出Java中所有进程
2)、jinfo + 进程号 List related properties under the current process
3)、jstat Javadata tracking information
jstat -gc(参数) + 进程号 : 跟踪gc的一些信息
jstat -gc(参数) + 进程号 + Refresh milliseconds :跟踪gcThe number of milliseconds in which some information is refreshed
4)、jstack + 线程 View the call stack information of all threads under the current process
当存在cpuCan be used when memory soars:
top :See which process is usingcpu很高
top -hp + 进程号 : Check out which thread to usecpu很高
最后使用jstack Check the corresponding stack information to see which method has a problem
5)、jmap There are two major functions to check the occupancy of the object in the heap memory(The proportion of memory occupied by objects of different classes),Generate a heap dump file(怀疑jvm内存有bugThis memory can be exported for analysis)
jmap histo + 进程号 :Generate an object graph
jmap histo + 进程号 | head 20 : Generates the largest front in the object graph20The proportion of each class object
使用jmap有一个严重的问题:When dumping the heap to a file,will be stuck,Run until the dump is successful(Not recommended for production environments 用)
6)、使用arthas(阿尔萨斯)工具
arthas阿里开源的jvm诊断工具,Covers the above command,主要有:
1、dashboard : 仪表盘,Check which thread occupies more support
2、head dump: 堆转储文件
3、thread :List except all threads,看那个cpuEat more threads
thread -d : 查看是否存在死锁
4、jvm : 列出java中设置的jvm参数,and which garbage collectors are used
5、jad : 反编译java代码
6、redefine : 在线修改class
7、trace :Stand-alone link tracking,Distributed link tracing is used(zipkin)
边栏推荐
- How to automatically export or capture abnormal login ip and logs in elastic to the database?
- 基于Qt的目录统计QDirStat
- 初识Numpy
- 函数,递归以及dom简单操作
- Take care of JVM performance optimization (own note version)
- 嵌入式数据库开发编程MySQL(全)
- Based on the statistical QDirStat Qt directory
- 2022支付宝C2C现金红包PHP源码DEMO/兼容苹果/安卓浏览器和扫码形式
- Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
- Introduction to mq application scenarios
猜你喜欢
随机推荐
案例 | 重庆银行流动数据安全挑战及应对实践
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
docker+bridge+redis master-slave+sentry mode
Use serve to build a local server
跨境电商看不到另一面:商家刷单、平台封号、黑灰产牟利
系统设计.秒杀系统
docker+网桥+redis主从+哨兵模式
深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
Reproduce 20-character short domain name bypass
企业直播风起:目睹聚焦产品,微赞拥抱生态
Innovation and Integration | Huaqiu Empowerment Helps OpenHarmony Ecological Hardware Development and Landing
类如何只能静态分配和只能动态分配
Embedded database development programming MySQL (full)
【观察】超聚变:首提“算网九阶”评估模型,共建开放繁荣的算力网络
6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
将xml标签转换为txt(voc格式转换为yolo方便进行训练)
Mockito unit testing
缓存穿透、缓存击穿、缓存雪崩以及解决方案
2022年软件测试——精选金融银行面试真题
DIY电工维修如何拆卸和安装开关面板插座