察看工具加載其他類
我嘗試了以下程序:
package test;
public class MainSleep {
public static void main(String[] args) throws InterruptedException {
synchronized (MainSleep.class) {
MainSleep.class.wait(5*1000);
}
}
}
當我運行它:
"c:\Program Files\Java\jdk1.8.0_131\bin\java" \
-verbose:class -cp target\classes test.MainSleep
我得到詳細的類加載消息,則暫停5秒,然後關機確實會加載更多類別:
...
[Loaded sun.misc.PerfCounter from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.misc.Perf$GetPerfAction from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.misc.Perf from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.misc.PerfCounter$CoreCounters from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.nio.ch.DirectBuffer from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.nio.MappedByteBuffer from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.nio.DirectByteBuffer from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.nio.LongBuffer from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.nio.DirectLongBufferU from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.security.PermissionCollection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.security.Permissions from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.net.URLConnection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.net.www.URLConnection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.net.www.protocol.file.FileURLConnection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded sun.net.www.MessageHeader from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.io.FilePermission from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.io.FilePermission$1 from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.io.FilePermissionCollection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.security.AllPermission from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.security.UnresolvedPermission from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.security.BasicPermissionCollection from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded test.MainSleep from file:/D:/ws/BIS65/test-java8/target/classes/]
[Loaded sun.launcher.LauncherHelper$FXHelper from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.lang.Class$MethodArray from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.lang.Void from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
...
[Loaded java.lang.Shutdown from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from c:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar]
所以這將是基準。當我現在在該文件上使用jstack
或jmap
並檢查詳細的類加載消息時,我可以看到它是否引入了新類(不確定當然是實例)。
隨着jstack -l
和jstack
,以下附加的一個類被加載:
[Loaded java.lang.Class$MethodArray from
[Loaded java.lang.Void from
[Loaded java.util.concurrent.locks.AbstractOwnableSynchronizer ...
[Loaded java.lang.Shutdown from
[Loaded java.lang.Shutdown$Lock from
隨着jstack -F
或jstack -m
沒有額外的類裝載(!):
無的
jmap
-clstat
[Loaded java.lang.Class$MethodArray from
[Loaded java.lang.Void from
[Loaded java.lang.Shutdown from
[Loaded java.lang.Shutdown$Lock from
,-finalizerinfo
,-heap
,-histo
或-histo:live
加載其他類:
[Loaded java.lang.Class$MethodArray from
[Loaded java.lang.Void from
[Loaded java.lang.Shutdown from
[Loaded java.lang.Shutdown$Lock from
這同樣適用於jmap -dump:format=b,file=ignore.hprof
使用和不使用-F選項以及與不live
標誌真。
只是爲了保持完整性,如果我用jvisualvm或JConsole的它總是會引發很多JMX類負載線程,堆和應用程序快照。很有可能是因爲它總是打開進程的儀表板。
所以,現在,我們已經建立了這個我接過一看jmap -dump:format=b
(非實時,非強制)堆與MAT轉儲,尋找字段你一直有興趣研究堆內容
:
的MAT 不可獲得的對象直方圖(其示出在堆找到,但不連接到任何GC根,它基本上是所有的尚未收集垃圾實例)具有3038點的對象,並且頂部10:
Class Name | Objects | Shallow Heap
------------------------------------------------------------------
char[] | 1.026 | 113.848
java.lang.String | 599 | 14.376
int[] | 423 | 7.664
java.lang.Object[] | 220 | 14.192
java.lang.StringBuilder | 137 | 3.288
java.lang.reflect.Field | 115 | 8.280
java.lang.ProcessEnvironment$CheckedEntry| 66 | 1.056
java.io.File | 59 | 1.888
java.lang.Class | 32 | 0
java.lang.StringBuffer | 30 | 720
目前沒有單一的實時Field
實例可見與MAT和只有非常有限的Class
實例。這看起來很像.hprof或MAT問題:類實例似乎不顯示堆轉儲中的任何字段。我認爲他們應該被軟弱(!)引用Class#reflectionData : SoftReference<ReflectionData<T>>
,但我認爲這應該在堆轉儲中可見,而不是丟失115個字段。 (有一個在現場堆沒有Class$ReflectionData
和14 Class$ReflectionData
無法到達HISTO,這可與115個字段吻合。
(我想我會回來檢查與維修性-dev的@對OpenJDK的,這不適合在一個評論,所以這是一個不完整的答案,但我打算加強它)
一個java.lang.Class有java.lang.Fields,所以爲什麼不會有Field實例?Hashtable用了很多因爲程序非常簡單,垃圾收集器可能甚至沒有運行過一次,所以你可以看到虛擬機啓動過程中創建的每一個*單個對象 – Durandal