Valgrind 和 Java [英] Valgrind and Java
问题描述
我想使用 Valgrind 3.7.0 来查找 Java 本机代码中的内存泄漏.我正在使用 jdk1.6.0._29.
I want to use Valgrind 3.7.0 to find memory leaks in my Java native code. I'm using jdk1.6.0._29.
为此,我必须设置 --trace-children=yes 标志.设置该标志,我不再可以在任何 Java 应用程序上运行 valgrind,甚至是像这样的命令:
To do that, I have to set the --trace-children=yes flag. Setting that flag, I no longer can run valgrind on any java application, even a command like:
valgrind --trace-children=yes --smc-check=all java -version
会得到错误信息:
Error occurred during initialization of VM
Unknown x64 processor: SSE2 not supported
我看过这个链接:https://bugs.kde.org/show_bug.cgi?id=249943,但没有用.
I've seen this link: https://bugs.kde.org/show_bug.cgi?id=249943, but it was not useful.
在没有 Valgrind 或没有 --trace-children 标志的情况下运行程序是可以的.
Running the program without Valgrind or without the --trace-children flag is fine.
有人知道我能做什么吗?
Does anyone has any idea on what I can do?
推荐答案
必须禁用 JIT 才能在 valgrind 下运行 JVM,如下所示:
You must disable JIT to run the JVM under valgrind, like so:
valgrind java -Djava.compiler=NONE ...
此外,如果您最终使用生成的抑制(而且您很可能会使用!),则生成的抑制中调用堆栈的深度可能会出现问题,这在 JVM 下运行时更有可能发生.
Also, if you end up using generated suppressions (and you most likely will!), there can be a problem with the depth of the call stacks in the generated suppressions, which is more likely to occur when running under the JVM.
在 valgrind 的最新版本中,生成的抑制可以包含比 valgrind/memcheck 本身可以处理的更深的调用堆栈.此问题的症状是 valgrind 意外终止并显示消息堆栈跟踪中的调用方过多".
In recent versions of valgrind, generated suppressions can contain deeper call stacks than can be processed by valgrind/memcheck itself. The symptom of this problem is that valgrind terminates unexpectedly with the message "too many callers in stack trace".
这个问题很容易解决:在构建valgrind之前,编辑文件coregrind/m_errormgr.c并将#define中的硬编码值更改为更大的值(我使用99):
This problem is easily fixed: before building valgrind, edit the file coregrind/m_errormgr.c and change the hard-coded value in the #define to a larger value (I use 99):
/* Max number of callers for context in a suppression. */
#define VG_MAX_SUPP_CALLERS 99
然后按照文档构建和安装 valgrind.
Then build and install valgrind as per the docs.
这篇关于Valgrind 和 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!