08 March 2016

Logging of class loading and unloading.

There are several useful system properties for JVM that are not very popular.

One of those is:

-verbose:class
Or:
-XX:+TraceClassLoading -XX:+TraceClassUnloading

This helps to printout all the jar files that are being used when running classes.

i.e.:
 [Opened /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.Object from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.io.Serializable from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.Comparable from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.CharSequence from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.String from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.reflect.AnnotatedElement from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.lang.reflect.GenericDeclaration from /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar]
Another approach is to printout in the code itself using ClassLoader (but this is more intrusive).

  ClassLoader cl = ClassLoader.getSystemClassLoader();

  URL[] urls = ((URLClassLoader)cl).getURLs();

  for(URL url: urls){
     System.out.println(">>>"+url.getFile());
  }
 
example:

>>> /Users/German/development/jars/HikariCP-java7-2.4.13.jar
>>> /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/lib/tools.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic_sp.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/oracle_common/modules/net.sf.antcontrib_1.1.0.0_1-0b3/lib/ant-contrib.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/modules/features/oracle.wls.common.nodemanager_2.0.0.0.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/oracle_common/modules/com.oracle.cie.config-wls-online_8.1.0.0.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/common/derby/lib/derbynet.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/common/derby/lib/derbyclient.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/common/derby/lib/derby.jar
>>> /Users/German/Oracle/Middleware/Oracle_Home/wlserver/server/lib/xqrl.jar
>>> /Users/German/bin/wlsdm.v3.1.1/jar/wlsdm_agent.jar
 
Always we can use the powerful lsof -p <pid>

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.