Heap dump on JRE 6 (Windows) without JDK

ぐ巨炮叔叔 提交于 2019-12-05 18:37:20

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

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.

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.

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.

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.

     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.

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