
Saturday September 30, 2006
Use new Java 6 JDK tools to explore Netbeans runtime
Java 6 JDK has some very cool new tools:
- jps JVM Process Status Tool -
Lists instrumented HotSpot Java virtual machines on a target system.
- jmap Memory Map for Java - Prints shared object memory maps or
heap memory details of a given process or core file or a
remote debug server.
- jhat Heap Dump Browser - Starts a web server on a heap dump file (eg,
produced by jmap -dump), allowing the heap to be browsed.
I was running Netbeans 5.5 Beta2. I decided to experiment with these tools and explore the Netbeans runtime. So here is what I did:
Use
jps to find out the process id of the Netbeans IDE:
$ jps -l
2716 org/netbeans/Main
3824 sun.tools.jps.Jps
Use
jmap to dump the heap of the Netbeans IDE process:
$ jmap -dump:format=b,file=heap.bin 2716
Dumping heap to heap.bin ...
Heap dump file created
Use
jhat to run a web server so that I can run OQL queries on the information in the heap dump file:
$ jhat.exe -J-Xmx512m heap.bin
Reading from heap.bin...
Dump file created Sat Sep 30 17:32:29 PDT 2006
Snapshot read, resolving...
Resolving 603765 objects...
Chasing references, expect 120 dots...
Eliminating duplicate references...
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
Ran the browser with URL:
http://127.0.0.1:7000/oql/
Entered the following query in the OQL query text box and click Execute:
select map(
heap.objects('org.netbeans.StandardModule$OneModuleClassLoader'),
function (it) {
function printit(it, indent) {
var res = '';
if (classof(it).name == 'org.netbeans.StandardModule$OneModuleClassLoader') {
var itsModule = it.this$0;
var codeName = itsModule.codeName.value.toString();
var specVers = itsModule.specVers.digits.toString();
var jar = itsModule.jar.path.value.toString();
res += indent + '<a name="'+ escape(codeName + specVers) + '">' +
codeName + ' ' + specVers + ' [' + jar + ']'+
'</a>' + '<br>';
indent += ' ';
if (itsModule.publicPackages) {
res += '<br>' + indent + 'Public packages:' + '<br>';
for (i = 0; i < itsModule.publicPackages.length; i++) {
var publicPackage = itsModule.publicPackages[i];
res += indent + publicPackage.pkg.value.toString() +
(publicPackage.recursive ? '**' : '') +
'<br>';
}
}
if (it.parents) {
res += '<br>' + indent + 'Dependencies:' + '<br>';
for (i = 1; i < it.parents.length; i++) {
var parent = it.parents[i];
if (classof(parent).name == 'org.netbeans.StandardModule$OneModuleClassLoader') {
var parentCodeName = parent.this$0.codeName.value.toString();
var parentSpecVers = parent.this$0.specVers.digits.toString();
res += indent + '<a href="#'+ escape(parentCodeName + parentSpecVers) +
'">' + parentCodeName + ' ' +
parentSpecVers + '</a>' + '<br>';
}
}
}
}
return res;
}
return '<br>' + printit(it, '');
})
On the query page there is a link to help on the OQL syntax and supported functions.
And here is the screenshot of the query result which is a simple report on Netbeans module dependencies

This is just the tip of the iceberg. Using OQL one can explore what is going on inside Java application's heap.
Netbeans Profiler now has HeapWalker tool to look at heap dumps generated by jmap tool.
Posted by sandipchitale
( Sep 30 2006, 06:14:26 PM PDT ) Permalink
Trackback URL: http://blogs.sun.com/scblog/entry/tip_use_new_java_6
Posted by Sandip on October 04, 2006 at 09:57 PM PDT #