原文链接: http://extreme-java.blogspot.com/2011/01/java-verbose-options-for-running.html
There are basically three sub parameters with the javac verbose parameter:
verbose参数有三个基本的子参数:
-verbose:class
-verbose:gc
-verbose:jni
To give you an idea of the number of classes loaded when you fire the java commond, here is the most simple program.
package example.java;
public class Test{
public static void main(String args[]) {
System.out.println("Hello World");
}
}
I will run it using the -verbose:class option to see how many classes have been loaded into the memory. If you are running the program from command line then you can use the command:
java -verbose:class Test
The output shown to you will be:
[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]
[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
[Loaded java.lang.reflect.Type from shared objects file]
.............
.............
[Loaded java.security.ProtectionDomain$2 from C:\Program Files (x86)\Java\jre6\lib\rt.jar]
[Loaded java.security.ProtectionDomain$Key from C:\Program Files (x86)\Java\jre6\lib\rt.jar]
[Loaded java.security.Principal from shared objects file]
[Loaded example.java.Test from file:/C:/Sandeep/Projects/Workspace/test/bin/]
Hello World
[Loaded java.lang.Shutdown from shared objects file]
[Loaded java.lang.Shutdown$Lock from shared objects file]
Thus we can see that such a huge number of classes are loaded for a simple Hello World program. You can imagine the number of classes loaded when you have very complex system to automate with web applications also comming into the picture.
The story of verbose doesn't end here. You can also see when a garbage collection runs. This option can be handy when performing garbage collection is serious to your program. The modified code will be:
当垃圾回收对你的程序很重要时,gc子参数就显得很方便了:
package example.java;
public class Test{
public static void main(String args[]) {
System.out.println("Hello World");
System.gc();
}
}
If you run the above program as java -verbose:gc Test, the you will see the following line in the output:
[Full GC 281K->123K(15872K), 0.0148661 secs]
This can suggest you when the garbage collector runs.
On the similar lines, if you run the above Test program with -verbose:jni option then the following output will be shown:
[Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
[Registering JNI native method java.lang.Object.hashCode]
..................
..................
[Dynamic-linking native method java.lang.Compiler.registerNatives ... JNI]
[Registering JNI native method java.lang.Compiler.compileClass]
[Registering JNI native method java.lang.Compiler.compileClasses]
[Registering JNI native method java.lang.Compiler.command]
[Registering JNI native method java.lang.Compiler.enable]
[Registering JNI native method java.lang.Compiler.disable]
[Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.find ...
[Dynamic-linking native method java.io.FileOutputStream.writeBytes ... JNI]
Hello World
[Dynamic-linking native method java.lang.Runtime.gc ... JNI]
[Dynamic-linking native method java.lang.ref.Finalizer.invokeFinalizeMethod ... JNI]