Class Leakage Tool
clebert.suconic Mar 28, 2006 3:35 PMLast week, as I was involved on finding memory leaks on redeployments, I created some features on the JVMTIWrapper (org.jboss.profiler.jvmti.JVMTIInterface) useful to find leaks specific to redeployment.
Instead of explaining the nature of how a ClassDeployment would leak, I would like to talk about what I've added, and point this thread as a reference on ClassLeakage:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=78975
I've added two methods on JVMTIInterfaceMBean:
I - listClassesHTMLReport() what will show every class loaded on the current JVM. On the beggining of the output you will see every class loaded in more than one class loader. When you redeploy packages and they are not GCed you will see duplications.
II - exploreClassReferences
/** * @param className The name of the class to explore * @param maxLevel The number of levels to explode. Be careful as if you put this number too high, you migh endup in a forever loop, specially if your object is referencing something too generic * @param solveReferencesOnClass Will expose the tree on the class * @param solveReferencesOnClassLoader Will expode the tree on the classLoader (I mostly recommend to only look for classLoader's references) * @param useToString If true, will use toString when an object is printed. If False will use className@<System.identityHashCode(object)> * @param weakAndSoft If false, won't detail references on Weak and Soft References * @param printObject If true, Will print (with toString) every single instance of the object passed as parameter */ public String exploreClassReferences(String className, int maxLevel, boolean solveReferencesOnClasses, boolean solveReferencesOnClassLoaders, boolean useToString, boolean weakAndSoft, boolean printObjects)
I have also added a new menu item on jboss-profiler.war
- Class Loader Analysis
With this new Tool, you will be able to naviage on references for any Class/ClassLoader inside the JVM where the application is deployed.
Notice that you need to provide extra memory, as this feature will download a hashMap with a matrix between referenceHolders and referencedObjects from JVMTI. I have executed an all instance of JBoss with 400M of memory for this sucessfully. If I've used 128M GC would be so crazy that you would even have problems killing the process.
I wanted at first, to take the ClassLeakage tool outside of JBossProfiler.war, but since this is part of the project, I guess it should be okay to be part of the package.
also, it's important to understand that this tool can only be used on a JVM 5. (needs JVMTI support)
Clebert
PS: As usual my HTML design skills are terrible. I could provide the information, but if someone want to contribute with any fancy HTML, it would be really nice.