当前位置:网站首页>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)

边栏推荐
- FairyGUI循环列表
- FairyGUI增益BUFF数值改变的显示
- On March 15, the official version of go 1.18 was released to learn about the latest features and usage
- 地球围绕太阳转
- Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
- FairyGUI按钮动效的混用
- Fairygui bar subfamily (scroll bar, slider, progress bar)
- Basic DOS commands
- NovAtel 板卡OEM617D配置步骤记录
- [algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
猜你喜欢

Problems and solutions of robust estimation in rtklib single point location spp
![[algorithm] sword finger offer2 golang interview question 10: subarray with sum K](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K

rtklib单点定位spp使用抗差估计遇到的问题及解决

Fairygui gain buff value change display
![Heap sort [handwritten small root heap]](/img/f0/6efda3c6f499a32671a935dd2f21db.png)
Heap sort [handwritten small root heap]
![[算法] 剑指offer2 golang 面试题4:只出现一次的数字](/img/f7/23ffc81ec8e9161c15d863c1a67916.png)
[算法] 剑指offer2 golang 面试题4:只出现一次的数字

3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法

Fabrication of fairygui simple Backpack

PR 2021 quick start tutorial, first understanding the Premiere Pro working interface

抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
随机推荐
341. Flatten nested list iterator
记录:初次cmd启动MySQL拒接访问之解决
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
Fairygui loop list
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
[Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
FairyGUI增益BUFF数值改变的显示
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
错误:排序与角标越界
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
Introduction to the daily practice column of the Blue Bridge Cup
Devops' future: six trends in 2022 and beyond
wsl常用命令
堆排序【手写小根堆】
[算法] 劍指offer2 golang 面試題2:二進制加法
[algorithm] sword finger offer2 golang interview question 1: integer division
FairyGUI复选框与进度条的组合使用
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
FairyGUI人物状态弹窗