本机内存泄漏分析工具

发布于 2024-11-26 23:45:41 字数 215 浏览 1 评论 0原文

我怀疑我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

弥枳 2024-12-03 23:45:41

带有 Hotspot VM 的 Java SE 6 故障排除指南包含关于帮助检测本机内存泄漏的技术的相当详细的部分。其中包括:

  • 包装所有内存分配和释放调用以跟踪所使用的内存量。
  • 依靠特定于平台的支持(例如 Microsoft Visual C++ 编译器提供的调试支持)或 mtrace(和 MALLOC_TRACE)来调试 Linux 上的内存分配。
  • 使用 Rational Purify 等内存泄漏分析工具。

除其他外。值得注意的是,文章提到不存在适用于所有平台的理想解决方案。

另外,请考虑使用大多数 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:

  • wrapping all memory allocation and deallocation calls to track the amount of memory used.
  • relying on platform specific support like the debug support provided by the Microsoft Visual C++ compiler or on mtrace (and MALLOC_TRACE) to debug memory allocations on Linux.
  • using memory leak analysis tools like Rational Purify.

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.

沐歌 2024-12-03 23:45:41

AFAIK 您无法使用 JProfiler、JVisualVM 等 Java 工具来完成此操作。如果本机代码中存在内存泄漏,请使用本机代码工具。你即。可以从C运行它(即加载jvm.dll)。您可以查看这篇文章 使用 Visual 查找内存泄漏StudioC++ 中的内存泄漏检测 (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.

執念 2024-12-03 23:45:41

我一直在致力于一个名为“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

风为裳 2024-12-03 23:45:41

要诊断本机内存泄漏,需要 JIT 代码符号映射和 Linux 最新的分析工具:perfperf-map-agentbcc

请参阅相关答案中的详细信息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 and bcc.

Please refer to details in related answer https://stackoverflow.com/a/52767721/737790

Many thanks to Brendan Gregg

猫腻 2024-12-03 23:45:41

这些是可用于调试

  1. libtcmalloc HPROF 的工具:用于堆分析
  2. jcmd 实用程序、进程的 PSS:可以帮助确认本机泄漏。
  3. 本机内存跟踪:跟踪 JVM 中的本机内存泄漏(仅适用于 JVM 内部的分配)
  4. 核心转储分析、pmap 和 gdb 检查匿名块和进程内存超时
  5. -Xcheck:jni

可以在此处找到更多详细信息
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

  1. libtcmalloc HPROF: For heap profiling
  2. The jcmd Utility, PSS for the process: Can help in confirming a native leak.
  3. Native Memory Tracking: Tracking native memory leak in JVM (only works for allocation inside JVM)
  4. Core dump analysis, pmap and gdb checking for anon blocks and process memory overtime
  5. -Xcheck:jni

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

披肩女神 2024-12-03 23:45:41

我是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文