Heap dump on JRE 6 (Windows) without JDK

ぃ、小莉子 提交于 2019-12-07 13:32:15

问题


Is there a way to create a heap dump on a remote machine without JDK installed?

I can't change the installation / settings and it's running on Windows. So I have pnly access to commandline tools.

Problem is that a Java app on a remote machine freezes (no out of memory exception so -XX:-HeapDumpOnOutOfMemoryError is useless) and we need to create a dump.

-XX:+HeapDumpOnCtrlBreak 

is no option too, because it's not supported anymore on JDK6+.

JMX is not allowed due to security reasons.

Any Ideas? Thank you for your help!

Edit:

  • Windows
  • No JDK
  • No JMX

回答1:


I think I solved the problem.

You have to "patch" your JRE with some files of the JDK (the same version of course - if you are running jre6uXX you need the corresponding files from jdk6uXX )

Copy the following files:

  • \JDK6uXX\bin\attach.dll --> %JAVAJRE_HOME%\bin\
  • \JDK6uXX\bin\jmap.exe --> %JAVAJRE_HOME%\bin\
  • \JDK6uXX\lib\tools.jar --> %JAVAJRE_HOME%\lib\

No files are overwritten, JRE shouldn't be affected by this.

Now you can use jmap just fine to take dumps ;-)

I appreciate your help! Bye




回答2:


The simplest solution is to use jmap -dump:liv,format=b,file=app.dump on the command line. You can use jps -lvm to find the process id.

An alternative is to connect to it to jvisualvm This will take the dump and analyse it for you. You can also use this tool to read a dump written by jmap so you may end up using it anyway.

Where jvisualvm struggles is for large heap dumps i.e. more than about half you main memory size. I have found using YourKit to handle larger dumps and also give more useful information. An evaluation license might be all you need to diagnose this.

jmx is not allowed due to security reasons

In that case, you can't do this remotely, unless you use YourKit or some other commercial profiler.




回答3:


You have start your application with jmx console enabled in a port to debug your application. Execute jconsole and connect to the port which you have enabled for debugging. You can also use of jmap to collect heapdump.




回答4:


JProfiler has a command line utility bin/jpdump that can take an HPROF heap dump. There is no need to install JDK. There is also no need to run the GUI installer of JProfiler, just extract the ZIP distribution and execute jpdump on the command line.

Disclaimer: My company develops JProfiler.


Update 2016-06-23

As of JProfiler 9.2, jpdump and jpenable run with Java 6 as well.




回答5:


You could use jvisualvm, just enable jmx port and connect to your application, then you will be able to generate a heap file.

You can do that by adding the following parameters:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8484
-Dcom.sun.management.jmxremote.ssl=false

Then You need to add your tomcat process manually, So right click on you localhost node -> Add JMX Connection -> type your port -> OK.

Your tomcat process will be listed in under localhost node.




回答6:


     jmap -dump:format=b,file=snapshot.jmap  
     process-pid

Regardless of how the Java VM was started, the jmap tool will produce a head dump snapshot, in the above example in a file called snapshot.jmap. The jmap output files should contain all the primitive data, but will not include any stack traces showing where the objects have been created.



来源:https://stackoverflow.com/questions/30025936/heap-dump-on-jre-6-windows-without-jdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!