Finding Class Loader Leaks in Java Applications Jevgeni Kabanov
Based on Work in progress on class loader leak detection tool “Computing Dominators and Dominance Frontiers” by P. Briggs, T. Harvey “A Fast Algorithm for Finding Dominators in a Flowgraph” by T. Lengauer and R. Tarjan “A Simple, Fast Dominance Algorithm” by Cooper et al
Class loader API public abstract class ClassLoader { public Class loadClass(String name); protected Class defineClass(byte[] b); public URL getResource(String name); public Enumeration getResources(String name); public ClassLoader getParent() }
Class loading public class A { public void doSmth() { B b = new B(); b.doSmthElse(); } Causes a call to A.class.getClassLoader().loadClass(“B”);
Java EE Delegation ContainerApp1.earWAR1WAR2App2.earWAR3App3.earWAR4
Reloading an Object MyObject MyObject.clas s OldClassLoade r NewClassLoad er MyObject.clas s MyObject Recreate the object
Leaking ClassLoaders Class1.class ClassLoader Class2.class Class3.class Static Fields
Leaking ClassLoaders Leak Leak.class ExampleFactory$1 Example.class
Web Deployment Classes Libraries OldClassLoader NewClassLoader Sevlet New Classes New Libraries Sevlet Session init() App State Serialize/deserialize
Leak detection How are leaked class loaders different?
Dominators What are dominators useful for? –SSA –CPS Naïve algorithm O(N^2) Fixpoint algorithm O(N^2) Lengauer-Tarjan O(E logN)
FIXPOINT
Lengauer-Tarjan
1.Construct the DFS tree and give each node a depth-first index O(E) 1.Compute semidominators using TABA O(E) 2.Compute the dominators from the semidominators O(E) 1.Find minimum along the path = O(log N)