Verbose GC

When running a Java program, Verbose GC options can be used to tell the JVM which kind of information to see. JVM suports three verbose options out of the box. As the name suggests, verbose is for displaying the work done by JVM. Mostly the information provided by these parameters is used for debugging purposes. Since it is used for debugging, its use is in development. One would never have to use verbose parameters in production enviornment. The three verbose options supported by JVM are:

-verbose:class
-verbose:gc
-verbose:jni

-verbose:class is used to display the information about classes being loaded by JVM. This is useful when using class loaders for loading classes dynamically or for analysing what all classes are getting loaded in a particular scenario. A very simple program which does nothing also loads so many classes as shown below:

package com.example;
public class Test {
public static void main(String args[]) {
}}
Output:
[Opened C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.Object from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
...........................................................................…
[Loaded java.lang.Void from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.Shutdown from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar]

This is only selected output from Eclipse console. Classes from java.lang, java.io and java.util packages are loaded into memory by default.
As stated earlier, one would use the verbose:class option when checking for what all classes are getting loaded which is usually a requirement when working with class loaders in Java.

-verbose:gc is used to check garbage collection event information. When used as command line argument for running Java program, the details of garbage collection are printed on the console. The following program demonstrates the usage:

package com.example;
public class Test {
public static void main(String args[]) throws InterruptedException {
Test t1 = new Test();
t1=null;
System.gc();
}}

Output:

[GC 318K->304K(61056K), 0.0081277 secs]
[Full GC 304K->225K(61056K), 0.0054004 secs]

-verbose:jni is used for printing the native methods as and when they are registered in the application. These methods include JDK as well as custom native methods. Note that jni stands for Java Native Interface. The sourcecode and output demonstrating the usage of this option is shown below:

package com.example;
public class Test {
public static void main(String args[]) throws InterruptedException {
}}

Output:

[Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
[Registering JNI native method java.lang.Object.hashCode]
[Registering JNI native method java.lang.Object.wait]
[Registering JNI native method java.lang.Object.notify]
[Registering JNI native method java.lang.Object.notifyAll]
[Registering JNI native method java.lang.Object.clone]
[Dynamic-linking native method java.lang.System.registerNatives ... JNI]
...............................................................
...............................................................
...............................................................
[Registering JNI native method sun.misc.Perf.highResCounter]
[Registering JNI native method sun.misc.Perf.highResFrequency]
[Dynamic-linking native method java.lang.ClassLoader.defineClass1 ... JNI]
[Dynamic-linking native method java.lang.Runtime.gc ... JNI]
[Dynamic-linking native method java.lang.ref.Finalizer.invokeFinalizeMethod ... JNI]

Pages: 1 2 3

Leave a Reply

Your email address will not be published. Required fields are marked *