简体   繁体   English

如何使用 Eclipse OpenJ9 进行堆转储?

[英]How to take a heap dump with Eclipse OpenJ9?

With Oracle's Hotspot JVM, it looks like jmap -dump:file=/tmp/dump.txt <pid> can be used to take a heap dump.使用 Oracle 的 Hotspot JVM,看起来jmap -dump:file=/tmp/dump.txt <pid>可用于进行堆转储。

However, Eclipse OpenJ9 doesn't include the jmap tool - and if you try to use the regular jmap with OpenJ9's jvm, it gives the exception:但是,Eclipse OpenJ9 不包含jmap工具 - 如果您尝试将常规jmap与 OpenJ9 的 jvm 一起使用,则会出现异常:

Exception in thread "main" java.lang.ClassCastException: com.ibm.tools.attach.attacher.OpenJ9VirtualMachine incompatible with sun.tools.attach.HotSpotVirtualMachine
    at java.lang.ClassCastException.<init>(java.base@10.0.2-adoptopenjdk/ClassCastException.java:71)
    at sun.tools.jmap.JMap.executeCommandForPid(jdk.jcmd@10.0.2-adoptopenjdk/JMap.java:128)
    at sun.tools.jmap.JMap.dump(jdk.jcmd@10.0.2-adoptopenjdk/JMap.java:192)
    at sun.tools.jmap.JMap.main(jdk.jcmd@10.0.2-adoptopenjdk/JMap.java:110)

So, how can one take a heap dump with OpenJ9?那么,如何使用 OpenJ9 进行堆转储呢?

You can use -Xdump:heap:events=user to enable heap dump when signal 3 is passed to OpenJ9 JVM. 当信号3传递给OpenJ9 JVM时,可以使用-Xdump:heap:events=user启用堆转储。 So, start you application with this option and then issue kill -3 <pid> to get the heap dump. 因此,使用此选项启动应用程序,然后发出kill -3 <pid>来获取堆转储。

You can also use Xdump Option Builder tool for generating the -Xdump options based on your requirement. 您还可以根据需要使用Xdump Option Builder工具生成-Xdump选项。

An OpenJ9 heap dump can be created with the command jcmd <PID> Dump.heap <path>.phd .可以使用命令jcmd <PID> Dump.heap <path>.phd创建 OpenJ9 堆转储。

For example:例如:

jcmd 1 Dump.heap /tmp/heap-dump.phd

Notice:注意:

  • It must be run as the same user that the JVM is running as.它必须以运行 JVM 的同一用户身份运行。
  • The PID must be the ID of the JVM process to be inspected. PID 必须是要检查的 JVM 进程的 ID。 jps -l will list the available processes. jps -l将列出可用的进程。

Alternatively, use YourKit to take a memory snapshot:或者,使用 YourKit 拍摄内存快照:

  • Download YourKit and extract it下载 YourKit并解压
  • Use the Console Attach Wizard eg bash ./YourKit-JavaProfiler-2021.3/bin/attach.sh使用控制台附加向导,例如bash ./YourKit-JavaProfiler-2021.3/bin/attach.sh
  • Capture a memory snapshot: java -jar ./YourKit-JavaProfiler-2021.3/lib/yjp-controller-api-redist.jar localhost 10001 capture-memory-snapshot捕获内存快照: java -jar ./YourKit-JavaProfiler-2021.3/lib/yjp-controller-api-redist.jar localhost 10001 capture-memory-snapshot

Sources:资料来源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM