98percentmonkey
98percentmonkey

Reputation: 555

Heap dump on JRE 6 (Windows) without JDK

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:

Upvotes: 3

Views: 3175

Answers (6)

98percentmonkey
98percentmonkey

Reputation: 555

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

Upvotes: 5

Ingo Kegel
Ingo Kegel

Reputation: 47995

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.

Upvotes: 1

Mohan Raj
Mohan Raj

Reputation: 1132

     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.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533500

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.

Upvotes: 2

Salah
Salah

Reputation: 8657

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.

Upvotes: 0

Shriram
Shriram

Reputation: 4411

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.

Upvotes: 1

Related Questions