当前位置:网站首页>Several high-frequency JVM interview questions
Several high-frequency JVM interview questions
2022-07-06 13:03:00 【Java misty rain】
Preface
Hello everyone . I sorted out several high-frequency JVM Interview questions , Guys, come on !
JVM Why is memory divided into new generations , Old age
Why is the new generation divided into Eden and Survivor
JVM Once complete GC How is the process
CMS Collectors and G1 The difference between collectors
JVM tuning
CPU How to check
1. JVM Why is memory divided into new generations , Old age ?
1.1 JVM Shared memory partition
Shared memory area = Lasting generation + Pile up (jdk1.8 And above jvm Abandoned the lasting generation )
Lasting generation = Method area + other
Java Pile up = Old age + The new generation
The new generation = Eden + S0 + S1
1.2 Why is it divided into the old generation and the new generation
The new generation : It mainly stores newly created objects , Memory size is usually small , Garbage collection will be more frequent .
Old age (Tenured Gen): Main storage JVM Objects with a long life cycle ( After several times of Young GC After recycling, it still exists ), Or big objects , Garbage collection is also relatively less frequent .
Why divide the old age and the new generation , The main The object size is different , Object life cycle is different . After division , Provide garbage collection efficiency , Save resources , Improve object utilization wait .
2. Why is the Cenozoic divided into Eden and Survivor? Why set two Survivor
without Survivor,Eden Every time the district goes on Minor GC, The surviving object will be sent to the old age . The old generation is soon filled , Trigger Major GC. The memory space of the old generation is much larger than that of the new generation , Do it once. Full GC The ratio of time spent Minor GC Much longer , So it needs to be divided into Eden and Survivor.
Survivor The meaning of being , Is to reduce the number of people sent to the old age , And then reduce Full GC Happen ,Survivor Pre screening guarantee , Only experience 16 Time Minor GC Objects that can survive in the new generation , Will be sent to the old age .
Set the two Survivor The biggest advantage of the zone is that it solves fragmentation , The newly created object is Eden in , Experience once Minor GC,Eden The live object in will be moved to the first piece survivor space S0,Eden Be emptied ; etc. Eden The district is full again , Just trigger it again Minor GC,Eden and S0 The live objects in will be copied to the second block survivor space S1( This process is very important , Because this replication Algorithm To ensure the S1 From S0 and Eden Two live objects occupy continuous memory space , To avoid fragmentation )
3. JVM Once complete GC How is the process
Java The heap is divided into old and new generations
The new generation Divided into Eden And two Survivor(S0、S1)
When Eden The area is full of space , Java A virtual opportunity triggers Minor GC, To collect the new generation of garbage , Surviving objects , It will be transferred to Survivor District .
Big object ( Need a lot of continuous memory space Java object , Like that long string ) Go straight into old age ;
If the object is Eden born , And after the first time Minor GC Still alive after , And be Survivor If it can be accommodated , Age is set to 1, Every time I get through Minor GC, Age +1, If the age exceeds a certain limit (15), They are promoted to old age . That is, the long-term survival of the object into the old state .
The old generation is full and unable to accommodate more objects ,Minor GC After that it usually goes on Full GC,Full GC Clean up the entire memory heap – Including the young and the old .
Major GC It happened in the old days GC, Clean up the old age area , Often accompanied at least once Minor GC, Than Minor GC slow 10 More than times .
4. CMS Collectors and G1 The difference between collectors
CMS Collector is the collector of the old days , Generally with the new generation Serial and ParNew Collector used together ;G1 Collector collection range is old and new generation , It does not need to be used in combination with other collectors ;
CMS A collector is a way to get Minimum recovery pause time Collector for target , G1 The collector Predictable garbage collection pause time .
CMS Collector is used “ Mark - eliminate ” Algorithm Garbage collection , It is easy to generate memory fragmentation ; and G1 The collector uses “ Mark - Arrangement ” Algorithm , Space integration , Reduced memory space fragmentation .
CMS and G1 The recycling process is different , The garbage collection process is different .CMS yes Initial marker 、 Concurrent Tags 、 Re label 、 Concurrent cleanup ;G1 Is the initial tag 、 Concurrent Tags 、 Final marker 、 Screening and recovery .
5. JVM tuning
JVM Tuning is actually through tuning JVM Parameters , That is, the optimization of garbage collector and memory allocation , To achieve higher throughput and performance .JVM Tuning mainly adjusts the following parameters 
Stack memory dependent
-Xms Set the size of the initial heap
-Xmx Set the maximum heap size
-Xmn Set younger generation size , It is equivalent to configuring at the same time -XX:NewSize and -XX:MaxNewSize For the same value
-Xss Stack size per thread
-XX:NewSize Set younger generation size (for 1.3/1.4)
-XX:MaxNewSize Young generation maximum (for 1.3/1.4)
-XX:NewRatio The ratio of the younger generation to the older generation ( Remove the permanent generation )
-XX:SurvivorRatio Eden District and Survivor The ratio of the region
-XX:PretenureSizeThreshold When the created object exceeds the specified size , Assign objects directly to the older generation .
-XX:MaxTenuringThreshold Set the object in Survivor Maximum age threshold for replication , Over the threshold to the old age
Garbage collector related
-XX:+UseParallelGC: Choose garbage collector as parallel collector .
-XX:ParallelGCThreads=20: Configure the number of threads for the parallel collector
-XX:+UseConcMarkSweepGC: Set up concurrent collection of elderly generation .
-XX:CMSFullGCsBeforeCompaction=5 Because the concurrent collector does not compress the memory space 、 Arrangement , So running for a while will produce “ debris ”, Reduce the efficiency of operation . This value sets to run 5 Time GC Compress the memory space later 、 Arrangement .
-XX:+UseCMSCompactAtFullCollection: Turn on the compression of the old . May affect performance , But it can eliminate debris
Auxiliary information related
-XX:+PrintGCDetails Print GC Details
-XX:+HeapDumpOnOutOfMemoryError Give Way JVM Automatically generate memory snapshot in case of memory overflow , Check the problem with
-XX:+DisableExplicitGC Disable the system System.gc(), To prevent manual triggering FGC Cause problems .
-XX:+PrintTLAB see TLAB Use of space
6. CPU How to check
Input jps, Get the process number .
top -Hp pid Get the... Of all threads in this process CPU Time consuming performance
printf %x cpu The highest thread ( Turn into 16 Base number )
jstack Command to view the current java The stack state of the process | grep that 16 Base number
perhaps jstack -l > /tmp/output.txt Type the stack information into a txt file .
If this article helps you , Don't forget to give me a 3 even , give the thumbs-up , forward , Comment on ,
I'll see you next time ! How to get answers : Liked Commented Closed ~
Learn more knowledge and skills , Follow up with private bloggers (03)

边栏推荐
- [dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
- 记录:动态Web项目servlet访问数据库404错误之解决
- 【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
- The earth revolves around the sun
- 【RTKLIB 2.4.3 b34 】版本更新简介一
- 2022国赛Re1 baby_tree
- All in one 1405: sum and product of prime numbers
- Special palindromes of daily practice of Blue Bridge Cup
- Record: Navicat premium can't connect to MySQL for the first time
猜你喜欢
![[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等](/img/11/ee0628a68542236fc641966579a31a.png)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]

抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
![[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k](/img/65/fc3fb5a217a3b44f506b695af53e2c.png)
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k

RTKLIB: demo5 b34f.1 vs b33

The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan

面试必备:聊聊分布式锁的多种实现!
![[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数](/img/64/0f352232359c7d44f12b20a64c7bb4.png)
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
![[algorithm] sword finger offer2 golang interview question 5: maximum product of word length](/img/e0/cea31070d6365eb57013cdead4a175.png)
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length

Fgui project packaging and Publishing & importing unity & the way to display the UI
随机推荐
VLSM variable length subnet mask partition tips
Chromatic judgement bipartite graph
FairyGUI复选框与进度条的组合使用
[GNSS] robust estimation (robust estimation) principle and program implementation
记录:下一不小心写了个递归
记录:动态Web项目servlet访问数据库404错误之解决
[Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
Edit distance (multi-source BFS)
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
记录:newInstance()过时的代替方法
The port is occupied because the service is not shut down normally
Fairygui bar subfamily (scroll bar, slider, progress bar)
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
【GNSS】抗差估计(稳健估计)原理及程序实现
《软件测试》习题答案:第一章
NovAtel 板卡OEM617D配置步骤记录
Pride-pppar source code analysis
KF UD分解之伪代码实现进阶篇【2】
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
Acwing-116 pilot brother