Tuesday, December 16, 2008

Yet another reason to move to JDK 1.6

My first production memory leak analysis with Java 1.6 was almost a very pleasant experience.
While in previous versions of java I  needed to restart the JVM and set appropriate profiler command line option,  Java 6 comes with a built in alternative.  jmap which was not available for Windows distributions is now available for use. Taking a memory snapshot is a point and click task:
jmap -dump:format=b,file=dump.hprof
Take  the hprof dump generated and use you favorite profiler to analyze it.
If you are only interested in a short summary of memory usage by class:
jmap -histo

So, why was it only an almost pleasant experience ? Because you need to make sure that you are connected to the same windows session as the process you are trying to dump. If you are using terminal services make sure you use the /console command line option, otherwise jmap will not work. Beats me why.. 


Daniel said...

I assume the resulting files can be opened in the Netbeans profiler? Also, do you know if the resulting profiles are comparable to those of YourKit?

Lifey said...

The memory snapshots can be opened with Yourkit and AFAIK they are not missing any relevant information compared to snapshots taken by yourkit
As a matter of fact yourkit has an option of taking a memory snapshot in hprof format. This can be beneficial when trying to take memory snapshots for large heaps on Windows.