Monday, May 21, 2007
Heap Dump in Java 6
Just experimenting with the use of jmap and jhat in Java 6. The Object Query Language in jhat that allows the use of javascript closure seems pretty powerful, though also pretty slow.
Practices
# Find out the jvm pid
jps
# Trigger heap dump
jmap -dump:format=b,file=/tmp/java_app-heap.bin <pid>
# Analyzing the heap dump
jhat -J-Xmx326m /tmp/java_app-heap.bin
http://localhost:7000/showInstanceCounts/
http://localhost:7000/oql
More info
How to find java memory leaks
Troubleshooting Guide for Java SE 6 with HotSpot VM
HeapDumpOnOutOfMemoryError option in 5.0u7 and 1.4.2_12
Permanent generation analysis with OQL
What's in my Java heap?
Querying Java heap with OQL
JavaOne 2007 BOF on Memory Leaks
BOF9982: The java.lang.OutOfMemoryError: PermGen Space error demystified
Practices
# Find out the jvm pid
jps
# Trigger heap dump
jmap -dump:format=b,file=/tmp/java_app-heap.bin <pid>
# Analyzing the heap dump
jhat -J-Xmx326m /tmp/java_app-heap.bin
http://localhost:7000/showInstanceCounts/
http://localhost:7000/oql
#Find out the total size of MyClass instances
select sum(map(heap.objects('foo.bar.MyClass'), 'sizeof(it)'))
# List out all class names matching "foo.bar"
select filter(heap.classes(), "/foo.bar/(it.name)")
# Ditto
select map(filter(heap.classes(), "/foo.bar/(it.name)"),
function(c) {
return "<br>"+ c.name;
})
# List classes that match "foo.bar" with instances > 0
select map(filter(heap.classes(), "/foo.bar/(it.name)"),
function(c) {
var len = length(heap.objects(c));
if (len == 0) return "";
return "<br>" + c.name + ", instances:" + len;
})
# List classes that match "foo.bar" with instance sizes > 0
select map(filter(heap.classes(), "/foo.bar/(it.name)"),
function(c) {
var totalsize = sum(map(heap.objects(c),
function(o) {
return sizeof(o);
}
));
if (totalsize == 0) return "";
return "<br>" + c.name + ", size:" + totalsize;
})
More info
How to find java memory leaks
Troubleshooting Guide for Java SE 6 with HotSpot VM
HeapDumpOnOutOfMemoryError option in 5.0u7 and 1.4.2_12
Permanent generation analysis with OQL
What's in my Java heap?
Querying Java heap with OQL
JavaOne 2007 BOF on Memory Leaks
BOF9982: The java.lang.OutOfMemoryError: PermGen Space error demystified