【翻译】java verbose options

原文链接: 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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值