本机内存泄漏分析工具
我怀疑我的 java 代码中存在本机内存泄漏。有没有可以进行本机内存分析的工具?另外,是否有任何工具支持对正在运行的 java 进程进行本机内存分析?
谢谢!!
编辑: 我已经尝试过 Memory Validator 和 Purify,但它们似乎只支持 32 位进程。是否有一些类似于上述工具的工具可以简单地附加到正在运行的 Windows 进程并为我们提供该特定进程的本机内存分析?
I am suspecting a native memory leak in my java code. Are there any tools which do native memory profiling? Also, does any tool support native memory analysis of a running java process?
Thanks!!
Edit:
I have already tried Memory Validator and Purify but it seems they support only 32-bit processes. Is there some tool similar to the above ones which can simply attach to a running windows process and give us native memory analysis for that particular process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
带有 Hotspot VM 的 Java SE 6 故障排除指南包含关于帮助检测本机内存泄漏的技术的相当详细的部分。其中包括:
除其他外。值得注意的是,文章提到不存在适用于所有平台的理想解决方案。
另外,请考虑使用大多数 JVM 中都可用的
-Xcheck:jni
标志。-X
标志本身表明该标志是非标准的,但该标志似乎在 IBM JDK, Oracle JRockit R28,甚至 Oracle/ Sun JVM。启用该标志会开启在 JNI 调用周围添加包装器的模式,从而允许您跟踪传递给 JVM 调用的非法参数,如 JNI 程序员指南和规范。虽然它在检测内存泄漏中的使用是主观的,但如果您怀疑由于发出无效参数而导致泄漏,那么它肯定会有所帮助。The Troubleshooting guide for Java SE 6 with Hotspot VM contains a fairly elaborate section on techniques to aid in detecting native memory leaks. These include:
among others. Notably, the article mentions that no ideal solution exists for all platforms.
Also, consider using the
-Xcheck:jni
flag that appears to be available in most JVMs. The-X
flag itself indicates that the flag is non-standard, but the flag appears to be available in the IBM JDK, Oracle JRockit R28, and even the Oracle/Sun JVM. Enabling the flag switches on a mode where wrappers are added around JNI calls, thereby allowing you to track illegal arguments passed to JVM calls as noted in the JNI programmers' guide and specification. While, it's use in detecting memory leaks is subjective, it would definitely help if you suspect that the leak is being caused due to invalid parameters being issued.AFAIK 您无法使用 JProfiler、JVisualVM 等 Java 工具来完成此操作。如果本机代码中存在内存泄漏,请使用本机代码工具。你即。可以从C运行它(即加载jvm.dll)。您可以查看这篇文章 使用 Visual 查找内存泄漏Studio 或 C++ 中的内存泄漏检测 (Linux)
注意:当然,如果你的泄漏与堆泄漏有关(忘记了deleteglobalref),你可以用Java工具找到它,但在JNI中很少见。
AFAIK you can't do it with Java tools like JProfiler, JVisualVM etc. If you have memory leak in native code use tools for native code. You ie. can run it from C (i.e. loading jvm.dll). You can look at this articles finding memory leaks using Visual Studio or Memory Leak Detection in C++ (Linux)
Note: of course if you leak is connected to heap leak (forgot about deleteglobalref) you can find it with Java tools, but it is very rare in JNI.
我一直在致力于一个名为“MySafe”的开源项目(https://github.com/serkan- ozal/mysafe) 它基本上拦截和监视“不安全”的调用。 (事实上,它赚的还不止)。在 2.0 版本中,它对于跟踪和检测基于“不安全”的本机内存泄漏非常有用。
演示代码: https://github.com/serkan-ozal/mysafe/blob/master/src/test/java/tr/com/serkanozal/mysafe/NativeMemoryLeakHuntingDemo.java
显示源的图表泄漏:https://github.com /serkan-ozal/mysafe/blob/master/src/test/resources/native-memory-leak-hunting.png
I have been working on an open-source project named "MySafe" (https://github.com/serkan-ozal/mysafe) It basicly intercepts and monitors "Unsafe" calls. (In fact, it makes more than). With version 2.0, it can be useful for tracking and detecting "Unsafe" based native memory leaks.
Demo code: https://github.com/serkan-ozal/mysafe/blob/master/src/test/java/tr/com/serkanozal/mysafe/NativeMemoryLeakHuntingDemo.java
Diagram showing source of the leak: https://github.com/serkan-ozal/mysafe/blob/master/src/test/resources/native-memory-leak-hunting.png
要诊断本机内存泄漏,需要 JIT 代码符号映射和 Linux 最新的分析工具:
perf
、perf-map-agent
和bcc
。请参阅相关答案中的详细信息https://stackoverflow.com/a/52767721/737790
非常感谢布伦丹·格雷格
To diagnose native memory leak, JIT code symbol mapping and Linux recent profiling tools are required:
perf
,perf-map-agent
andbcc
.Please refer to details in related answer https://stackoverflow.com/a/52767721/737790
Many thanks to Brendan Gregg
这些是可用于调试
可以在此处找到更多详细信息
https://www.bro-code.in/blog/ java-调试-本机内存泄漏
http://www.oracle.com/technetwork/java/ javase/memleaks-137499.html#gbyvk
These are tools you can use for debugging
Further details can be found out here
https://www.bro-code.in/blog/java-debugging-native-memory-leak
http://www.oracle.com/technetwork/java/javase/memleaks-137499.html#gbyvk
我是 JProfiler 的忠实粉丝。这是分析和内存泄漏的最佳工具。相对于大多数工具来说,它相当便宜,非常容易学习,并且有很多功能。
http://www.ej-technologies.com/products/jprofiler/overview.html
I'm a big fan of JProfiler. That's the best tool for profiling and memory leaks. It's fairly cheap relative to most tools, really easy to learn, and lots of features.
http://www.ej-technologies.com/products/jprofiler/overview.html