垃圾回收中的幾個概念(未完,待補充)

大對象:(概念取自深入理解java虛擬機 jvm最佳實踐)所謂的大對象是指需要大量連續內存空間的java對象,最典型的大對象就是那種很長的字符串以及數組。大對象對虛擬機的內存分配來說是一個壞消息,經常出現的大對象容易導致內存還有不少空間時就提前觸發垃圾收集以及獲取足夠的連續的內存空間來存放

 

 

GC ROOTS

  訪問連接Help - Eclipse Platform  中的解釋是:

Garbage Collection Roots
A garbage collection root is an object that is accessible from outside the heap. The following reasons make an object a GC root:

System Class
Class loaded by bootstrap/system class loader. For example, everything from the rt.jar like java.util.* .
JNI Local
Local variable in native code, such as user defined JNI code or JVM internal code.
JNI Global
Global variable in native code, such as user defined JNI code or JVM internal code.
Thread Block
Object referred to from a currently active thread block.
Thread
A started, but not stopped, thread.
Busy Monitor
Everything that has called wait() or notify() or that is synchronized. For example, by calling synchronized(Object) or by entering a synchronized method. Static method means class, non-static method means object.
Java Local
Local variable. For example, input parameters or locally created objects of methods that are still in the stack of a thread.
Native Stack
In or out parameters in native code, such as user defined JNI code or JVM internal code. This is often the case as many methods have native parts and the objects handled as method parameters become GC roots. For example, parameters used for file/network I/O methods or reflection.
Finalizable
An object which is in a queue awaiting its finalizer to be run.
Unfinalized
An object which has a finalize method, but has not been finalized and is not yet on the finalizer queue.
Unreachable
An object which is unreachable from any other root, but has been marked as a root by MAT to retain objects which otherwise would not be included in the analysis.
Java Stack Frame
A Java stack frame, holding local variables. Only generated when the dump is parsed with the preference set to treat Java stack frames as objects.
Unknown
An object of unknown root type. Some dumps, such as IBM Portable Heap Dump files, do not have root information. For these dumps the MAT parser marks objects which are have no inbound references or are unreachable from any other root as roots of this type. This ensures that MAT retains all the objects in the dump.

                  常說的GC(Garbage Collector) Roots,特指的是垃圾收集器(Garbage Collector)的對象,GC會收集那些不是GC Roots且沒有被GC Roots引用的對象。

      一個對象可以屬於多個root,GC Roots有以下幾種:

  • Class - 由系統類加載器(system class loader)加載的對象,這些類是不能夠被回收的,他們可以以靜態字段的方式保存持有其它對象。我們需要注意的一點就是,通過用戶自定義的類加載器加載的類,除非相應的Java.lang.Class實例以其它的某種(或多種)方式成爲roots,否則它們並不是roots。
  • Thread - 活着的線程
  • Stack Local - Java方法的local變量或參數
  • JNI Local - JNI方法的local變量或參數
  • JNI Global - 全局JNI引用
  • Monitor Used - 用於同步的監控對象
  • Held by JVM - 用於JVM特殊目的由GC保留的對象,但實際上這個與JVM的實現是有關的。可能已知的一些類型是:系統類加載器、一些JVM知道的重要的異常類、一些用於處理異常的預分配對象以及一些自定義的類加載器等。然而,JVM並沒有爲這些對象提供其它的信息,因此需要去確定哪些是屬於"JVM持有"的了。

 

           到這裏對gc roots 應該基本瞭解了

對象可達

   對象可達是基於gc roots,通過以一系列的gc roots爲起始點,從這些節點向下搜索,搜索所走過的路徑稱爲引用鏈,一個對象到gc roots 沒有任何引用鏈相連就說這個對象不可達,也就是這個對象空間是可以被gc 回收的

圈起來的是跟gc roots 不可達的

 

 

*********************************************************************分割線**********************************************************************

 

在jdk1.9 中G1成了默認的垃圾收集器,替換了原來的cms垃圾收集器。可以說G1的改變很大。以後會詳細的補充

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

https://gceasy.io/可以用來分析gc日誌

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章