13

cms remark 时长比较长的优化_马力2020的博客-CSDN博客

 3 years ago
source link: https://blog.csdn.net/ma_ru_long/article/details/104009398
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
  • 原因:remark是stop the world 阶段;当之前concurrent-mark完成后,此时jvm的申请的内存比较频繁,年轻代突然涨起来了

remark需要重新扫描年轻代,查询是否有引用老年代的指针;如果年轻代比较大,导致扫描时长比较长;

  • 重新标记的内存范围是整个堆,包含younggen和oldgen 如果被新生代中的对象引用,那么就会被视为存活对象,即使新生代的对象已经不可达了,也会使用这些不可达的对象当做cms的“gc root”,来扫描老年代;
  • 解决方案 加入参数-XX:+CMSScavengeBeforeRemark  在重新标记之前进行一次youngGc

youngGc回收掉年轻代无用的对象,并将对象放入幸存带或晋升到老年代,再进行年轻带扫描时,只需要扫描幸存区的对象即可,一般幸存带非常小

  • 也可以增加了CMS回收的线程数  

-XX:ParallelGCThreads= N

-XX:ParallelCMSThreads= M

 

  • 再查看代码为啥这么短时间,引用关系变化如此之大

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK