The jhat command
parses a java heap dump file and launches a web server. jhat enables you to
browse heap dumps using your favorite web browser
This tool helps you
to debug and anaiyze the objets running in the java program. This is usefull in
debugging memory leaks and high object creations. The tool when started allows
one to view the object allocation in a
browser. It also provides a Query based syntax for extracting various level of
information from the Heap dump.
Noramlly a Heap
File generated by the jmap command are not readable. jhat command helps to read
the file. Once the jhat command is started , a server is started at 7000 .Once
the command says,server is ready.Open a browser and type , localhost:7000 to
see all about object information.
Dev:localhost:root-~
$ jhat -J-Xmx2G hprof.bin
Reading from
myA2.hprof...
Dump file created
Tue Sep 02 03:08:19 CDT 2014
Snapshot read,
resolving...
Resolving 2208439
objects...
Chasing references,
expect 441 dots................................................................................
...................................................................................................................
................
Eliminating
duplicate references...................................................................................
...................................................................................................................
...................................................................................................................
.............
Snapshot resolved.
Started HTTP server
on port 7000
Server is ready.
Some times when
processing bigger dumps it is necessary to provide heap size for the jhat
command itself. This can be done by passing the heap size as jhat -J-Xmx2G.
Once we open the
browser with URL "http://localhost:7000" we can see the object
allocation obtained from the heap dump.
The main page shows you all the
classes and objects present leaving platform classes. The list is sorted by
Full-Qualified class name and broken out package.
http://localhost:7000/histo/
This url provides
the information about the heap
http://localhost:7000/finalizerSummary/
Provides the
details about the finalizer object information
This URL provides
us the information about the Class name myNameClass
http://localhost:7000/instances/MyNameClass
http://localhost:7000/allInstances/MyNameClass
The instances query
shows you all instances of a given class. The "allInstances" variant
includes instances of subclasses of the given class as well
http://localhost:7000/object/myObject
The object query
gives you information about an object that was on the heap.
http://localhost:7000/showInstanceCounts/
This query shows
the count of instances for every class in the system
Normally during
OOMR we will look for "our" classes. We will need to exclude platform
classes to easily detect abnormalities in our classes quantity (or size) use,
http://localhost:7000/showInstanceCounts/excludePlatform/
Query Language
As we said earlier
there is a Query syntax facility available which will allow us to Extract
various levels of information. Use the below url to see the Text box where we
can enter the Queries
http://localhost:7000/oql/
Here are some of
the sample Queries that we can use to extract information
select
filter(heap.classes(),"/com.pack/(it.name)") : Show all classes that
are loaded in heap that have com.pack pattern
select
heap.findClass("com.pack.app.pqs.PQSLookupColumn").statics
lists the static
variables in the class
select i from
[Ljava.lang.Object; i where i.length == 10
select
count(heap.objects('java.lang.String')) : Total Number of String objects in a
Heap
select
file.path.toString() from java.io.File file : show path value of all File objects
show names of all
ClassLoader classes : select classof(cl).name from instanceof
java.lang.ClassLoader cl
select o from
instanceof 0xd404b198 o : show instances of the Class identified by given id
string
Note that
0xd404b198 is id of a Class (in a session). This is found by looking at the id
shown in that class's page.
select
heap.findClass("java.lang.String").fields.length : get number of
fields of java.lang.String class
select
heap.findObject("0xf3800b58") : find the object whose object id is
given
select
filter(heap.classes(), "/java.net./(it.name)") : select all classes that have name pattern
java.net.*
System properties
select map(filter(heap.findClass('java.lang.System').props.table,
'it != null && it.key != null && it.value != null'),
function (it) {
var res = it.key.toString() + '
= ' + it.value.toString();
return res;
});
More to Come ,Happy learning :-)
Hi there, after reading this awesome article i
ReplyDeleteam as well delighted to share my know-how here with friends.
my blog CT limo
Awesome blog !
ReplyDeleteI am reading about JVM heap and performance tuning.
I generated heap dump and hosted it in my local server.
And then didnt know how to proceed..
Thanks for your efforts !
Is there a way to find a find a String in the Instance Data member of a class?
ReplyDeleteGreat post.
ReplyDeleteThanks.
Informatie article, just what I wanted to find.
ReplyDeleteVery useful blog.
ReplyDeleteThanks.
You actually make it seem so easy with your presentation but I find this matter to be actually something which I think I would never understand.
ReplyDeleteIt seems too complicated and extremely broad for me.
I'm looking forward for your next post, I will try to get the hang of it!
Informative Article.Heap Hero,World's first memory dump analysis tool to find out amount of memory wasted by the application due to inefficient programming. Tool’s inbuilt AI intelligence recommends solution to fix the identified inefficiency.Java & Android Heap Dump Analyzer
ReplyDeleteHi there, yeah this article is in fact fastidious and I have learned lot
ReplyDeleteof things from it about blogging. thanks.
Greetings! Very useful adfice within this post! It is the little
ReplyDeletechanges tnat make tthe grreatest changes. Many thanks for sharing!