jmap: prints memory statistics for a running jvm or core file

tips: use jps to show java processes summary currently running on host machine.

jmap -heap <pid>

heap memory statistics

jmap -permstat <pid>

permanent generation memory statistics

jmap -histo <pid>

This is super useful. It displays number of instances of each class and memory size they occupy.

jmap -dump:format=b,file=ConsoleInput.hprof <pid>

This is a must use. It can dump the runtime jvm into a binary file in such a format called hprof that another utility called jhat can analize

jhat: java hotspot analysis tool

jhat takes the heap dump file produced by jmap as input, and starts a lightweight local web server so that you can visit and query the analysis results. I have to say the analysis results is very detailed.

Just fire:

jhat <dump_file_name>

Reading from ConsoleInput.bin…
Dump file created Sun Mar 09 00:59:15 CST 2008
Snapshot read, resolving…
Resolving 5032 objects…
Chasing references, expect 1 dots.
Eliminating duplicate references.
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

And I visit the results within my firefox at http://localhost:7000, it shows:

Package name.kenyth.hello

class name.kenyth.hello.ConsoleInput [0×91149f98]

Other Queries

You can see you can query the results by writing your own OQL which is sql-style and therefore quite handy.

Others

Follow the link listed below, you can find even more.

 Resources

  1.  Troubleshooting and Diagnostic Guide. a good place to start investigating and experimenting.

Related Posts

Tags: , ,



Leave a Comment

You must be logged in to post a comment.