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

栏目: Java · 发布时间: 5年前

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

概述

前两天给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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

图论导引

图论导引

韦斯特 / 机械工业出版社 / 2006-2 / 65.00元

图论起源于著名的哥尼斯堡七桥问题,在计算科学、社会科学和自然科学等各个领域都有广泛应用。本书是本科生或研究生一学期或两学期的图论课程教材。内容全面,证明与应用实例并举,不仅包括对证明技巧的讨论、1200多道习题、400多幅插图以及许多例题,而且对所有定理都给出了详细完整的证明。可以作为高等院校数学系本科生和研究生、计算机专业和其他专业研究生的图论课程教材,也可以作为有关教师和工程技术人员的参考书。......一起来看看 《图论导引》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具