PerfMa 给 OpenJDK 社区提交的第一个 Patch

概述

前两天给openjdk gc-dev的email list提交了一个问题,主要是针对Full GC之后,GC日志里Metaspace的大小在GC前后都一直不变的问题,我在邮件里大概也提了下如何修复该问题,以及猜测了下为什么会有这个问题,内容比较简单,就不翻译啦,直接把邮件贴出来,PerfMa在后面会提交越来越多的patch给官方吧,虽然不一定每个patch都会被官方所接受,不过也希望为社区的发展贡献一份我们的力量。

PerfMa 给 OpenJDK 社区提交的第一个 Patch

邮件内容

Hi, all

We use metaspace instead of perm since JDK8, I found that after the Full GC, the size of the metaspace has always been the same from the GC log. I have looked at the source code of hotspot roughly. It has not bean fixed in the latest version. The problem which may have some impact on us to troubleshoot some metaspace problems.

I wrote a test case, and simply analyzed the hotspot code, and showed the output before and after the modification. I hope this problem can be fixed as soon as possible.

Demo:

PerfMa 给 OpenJDK 社区提交的第一个 Patch

My demo is very simple, just constantly create a new class loader to load a specific class, after loading, execute a System GC, so that we can see the relevant GC log output, the JVM parameters we run are

PerfMa 给 OpenJDK 社区提交的第一个 Patch

The GC log is

PerfMa 给 OpenJDK 社区提交的第一个 Patch

Let’s look at the source code of hotspot,

GenCollectedHeap::do_collection:

PerfMa 给 OpenJDK 社区提交的第一个 Patch

We see that metaspace’s gc log output is executed before ClassLoaderDataGraph::purge(); , that means the size of the metaspace is printed without reclaiming the memory of the metaspace, so the GC log seems no change before and after the GC metaspace.

After knowing the specific problem, we can make an adjustment to the code to move the logic of the output of metaspace size  after to ClassLoaderDataGraph::purge(),just like this:

PerfMa 给 OpenJDK 社区提交的第一个 Patch

At this point we recompile hotspot, execute the above demo again, you can see the correct output as follows

PerfMa 给 OpenJDK 社区提交的第一个 Patch

I also probably thought about why this problem is caused. This is the version before JDK8, such as JDK7, you can see the same code location:

PerfMa 给 OpenJDK 社区提交的第一个 Patch

It can be seen that the GC engineer at that time simply replaced print_perm_heap_change(perm_prev_used); with MetaspaceAux::print_metaspace_change(metadata_prev_used); but forgot the difference between Perm and Metaspace.

结语

大家也可以关注我们公司PerfMa的微信公众号,后面会给大家带来更多有意思有深度的技术文章

PerfMa 给 OpenJDK 社区提交的第一个 Patch

原文 

https://mp.weixin.qq.com/s/j7nFwwRT2OkBJxWkwP9F9g

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。

PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » PerfMa 给 OpenJDK 社区提交的第一个 Patch

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址