Java 如何仅使用 JRE 生成堆转储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24213491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I produce a heap dump with only a JRE?
提问by Dave
We have a JRE installed on our production environment, but not a JDK. The versions of the JRE and OS are below.
我们在生产环境中安装了 JRE,但没有安装 JDK。JRE 和操作系统的版本如下。
[me@mymachine ~]$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
[me@mymachine ~]$ uname -a
Linux mymachine.mydomain.com 3.10.35-43.137.amzn1.x86_64 #1 SMP Wed Apr 2 09:36:59 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
It doesn't appear as if the “jmap” tool is present anywhere on the system, and without root access, I'm not in a position to install it in any system location. What can I do to get a heap dump (i.e. produce a .hprof file)?
“jmap”工具似乎并不存在于系统的任何位置,而且如果没有 root 访问权限,我无法将其安装在任何系统位置。我该怎么做才能获得堆转储(即生成 .hprof 文件)?
Also, we're using JBoss 7.1.3.AS if that matters.
此外,如果这很重要,我们将使用 JBoss 7.1.3.AS。
回答by M Anouti
Built-in tools like jmap
, jconsole
, and jvisualvm
are only available in a JDK. Another option is to add the VM argument -XX:+HeapDumpOnOutOfMemoryError
which tells the JVM to automatically generate a heap dump when an OutOfMemoryError occurs, and the argument -XX:HeapDumpPath
to specify the path for the heap dump.
内置工具喜欢jmap
,jconsole
和jvisualvm
只适用于JDK。另一种选择是添加 VM 参数-XX:+HeapDumpOnOutOfMemoryError
,该参数告诉 JVM 在发生 OutOfMemoryError 时自动生成堆转储,以及-XX:HeapDumpPath
指定堆转储路径的参数。
If you cannot upgrade your JRE to use tools like the ones in the server JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html), you may have to consider third-party profiling tools like JProfileror ones list here.
如果您无法升级 JRE 以使用服务器 JRE 7 中的工具(http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html),您可能有考虑使用JProfiler或此处列出的第三方分析工具。
回答by jhunovis
The only way seems to be to zip your local SDK6 and put it somewhere on the server. Then open a remote console and from within the bin directory of that SDK dump the JRE.
唯一的方法似乎是压缩本地 SDK6 并将其放在服务器上的某个位置。然后打开远程控制台并从该 SDK 的 bin 目录中转储 JRE。
If your client forbids uploading executable files, you are out of luck of course.
如果您的客户端禁止上传可执行文件,那您当然就不走运了。
回答by Jarek Przygódzki
Use jattach, a tool created by JVM hacker Andrei Pangin. It's tiny (24KB), works with just JRE and supports Linux containers.
使用jattach,这是一个由 JVM 黑客 Andrei Pangin 创建的工具。它很小 (24KB),仅适用于 JRE 并支持 Linux 容器。
jattach PID-OF-JAVA dumpheap <path to heap dump file>
jattach PID-OF-JAVA dumpheap <path to heap dump file>