GCRoots 是由哪些对象组成的

参考文档

GCRoot 是一个可以从堆外访问的对象

1. System Class (被boostrap 类加载器加载的系统类。如rt.jar)
    Class loaded by bootstrap/system class loader. For example, everything from the rt.jar like java.util.* .
   
2. JNI Local( 一些用户定义jni code或者jvm的内部代码局部变量)
    Local variable in native code, such as user defined JNI code or JVM internal code.
    
3. JNI Global( jni 代码中的全局变量)
    Global variable in native code, such as user defined JNI code or 4. JVM internal code.(jvm内部的代码)
     
5. Thread Block(被阻塞的线程类 Thread.state)
    Object referred to from a currently active thread block.

6. Thread 正在运行的线程
    A started, but not stopped, thread.
    
7. Busy Monitor(正在等待的线程。Thread.state ==WAITING)
    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.
    
8. Java Local(局部变量,比如一些方法传入参数或线程栈中方法创建的对象)
    Local variable. For example, input parameters or locally created objects of methods that are still in the stack of a thread.

9.Native Stack(本地方法栈中输入或输出参数,如io、文件方法或反射的参数)
    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.
    
10.Finalizable(在回收队列中的对象)
    An object which is in a queue awaiting its finalizer to be run.
    
11. Unfinalized(覆盖了finalize方法的对象但是还没有被放入回收队列中的对象)
    An object which has a finalize method, but has not been finalized and is not yet on the finalizer queue.

12.Unreachable(从任何其他根无法访问的对象,但由Memory Analyzer标记为根,以便该对象可以包含在分析中)
    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.

13. Java Stack Frame(java栈帧的举报变量,仅当您将“首选项”设置为将Java堆栈帧视为对象时,才会生成此类型的垃圾收集根)
    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.
    
14. 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.

总结来说:

  • 活着的线程,包含处于等待或阻塞的线程
  • java方法区/本地方法区中静态变量、常量引用的对象
  • 虚拟机栈中的变量的对象引用
上一篇:MySQL常用30种SQL查询语句优化方法


下一篇:PostgreSQL物理同步 12.2