This section provides a tutorial example on how to the '-verbose:class' option on the 'java' command to see when and where classes are loaded into the JVM.
If you want to know when and where classes are loaded into the JVM,
you can use the "-verbose:class" option on the "java" command.
Let's try it without launching Java application:
C:\herong\jvm>java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
C:\herong\jvm>java -verbose:class -version
[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
... 260 lines deleted ...
[Loaded sun.misc.URLClassPath from shared objects file]
[Loaded sun.net.www.protocol.jar.Handler from shared objects file]
[Loaded sun.misc.Launcher$AppClassLoader from shared objects file]
[Loaded sun.misc.Launcher$AppClassLoader$1 from shared objects file]
[Loaded java.lang.SystemClassLoaderAction from shared objects file]
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
[Loaded java.util.AbstractList$Itr from shared objects file]
[Loaded java.util.IdentityHashMap$KeySet from shared objects file]
[Loaded java.util.IdentityHashMap$IdentityHashMapIterator from shar...
[Loaded java.util.IdentityHashMap$KeyIterator from shared objects f...
[Loaded java.io.DeleteOnExitHook from shared objects file]
[Loaded java.util.LinkedHashSet from shared objects file]
[Loaded java.util.HashMap$KeySet from shared objects file]
[Loaded java.util.LinkedHashMap$LinkedHashIterator from shared obje...
[Loaded java.util.LinkedHashMap$KeyIterator from shared objects file]
The output is very interesting. It shows that the JVM loaded 279 classes
to just print the version information. But all of them are loaded from
the shared objects file, generated by the Class Data Sharing (CDS) module.
See other tutorials in this book to learn more about CDS.
Now try -verbose:class with a simple Java application:
C:\herong\jvm>javac Hello.java
C:\herong\jvm>java -verbose:class Hello
[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
... 293 lines deleted ...
[Loaded java.security.AllPermission from shared objects file]
[Loaded java.security.UnresolvedPermission from shared objects file]
[Loaded java.security.BasicPermissionCollection from shared objects file]
[Loaded java.security.Principal from shared objects file]
[Loaded java.security.cert.Certificate from shared objects file]
[Loaded Hello from file:/C:/herong/jvm/]
Hello world!
...
Now it tells me that the Hello class is loaded from a file in the C:/herong/jvm/ folder.