Monitoring the class loaders and
Hello,
I know that the ClassLoadingMXBean allows monitoring of the number of classes loaded in the JVM. However what I want to do is to monitor the exact Class loader that loaded the class. Basically I want to report the toString() method or some other attributes of ClassLoader's instance and the names of the classes loaded by it. In JVM spec there is a notion of initiating ClassLoader (See the revised Java Virtual Machine Specification section 5.3 Creation and Loading for more information on the initiating classloader). Can this information be accessed and monitored.
Does something like this already exit? If not, can anyone guide me in terms of how I would go about implementing such MXBean? Do I need to instrument the JVM itself somehow to achieve this?
How is the ClassLoadingMXBean itself implemented?
thanks,
Sandip
Message was edited by:
chitale
[911 byte] By [
chitalea] at [2007-10-3 4:13:59]

Hi Sandip,
The VM is instrumented to maintain the counter information. Currently the ClassLoadingMXBean only provides the statistics about class loading which is obtained directly from the VM counters. It doesn't provide the support to obtain the initiating class loader of a given class.
How would you use the initiating class loader information? What problem are you trying diagnose with this information?
Are you looking for the location where a class is being loaded? FYI. JDK 5.0 -verbose:class option was enhanced to provide the location where a class is loaded from. You can also turn on -verbose:class dynamically by using ClassLoadingMXBean.setVerbose() method.
Regards
Mandy
Hi Mandy,
Thanks for the info. I knew about the -verbose:class etc. The information as to where the class was loaded from is interesting but that is different from what I am looking for. In a complex, hierarchical-multi-ClassLoader applications such as Netbeans module system sometimes it is essential (e.g. for fine tuning of module dependencies etc.) to know which class loader first initiated the request for a particular class etc. That is what I was looking for. It seems to me that JMX may not be the right mechanism for getting this information. It turns out JPDA (Java Platform Debugger Architecture) /JDI already has the required APIs to get this info (See: http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ClassLoaderReference.html#visibleClasses()). In fact I have already written an extension module (See: http://blogs.sun.com/scblog/entry/updated_view_classes_and_classloader) for Netbeans (JPDA) Debugger to display initiating class loader information.
Thanks for your help,
Sandip