美文网首页
GC Roots对象

GC Roots对象

作者: 秦汉邮侠 | 来源:发表于2018-01-01 11:26 被阅读2406次

官方参考

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

关键点

  • 所有Java线程当前活跃的栈帧里指向GC堆里的对象的引用;换句话说,当前所有正在被调用的方法的引用类型的参数/局部变量/临时值。
  • VM的一些静态数据结构里指向GC堆里的对象的引用,例如说HotSpot VM里的Universe里有很多这样的引用。
  • JNI handles,包括global handles和local handles
  • (看情况)所有当前被加载的Java类
  • (看情况)Java类的引用类型静态变量
  • (看情况)Java类的运行时常量池里的引用类型常量(String或Class类型)
  • (看情况)String常量池(StringTable)里的引用

分代GC对GC roots的定义的影响

分代式GC是一种部分收集(partial collection)的做法。在执行部分收集时,从GC堆的非收集部分指向收集部分的引用,也必须作为GC roots的一部分。
具体到分两代的分代式GC来说,如果第0代叫做young gen,第1代叫做old gen,那么如果有minor GC / young GC只收集young gen里的垃圾,则young gen属于“收集部分”,而old gen属于“非收集部分”,那么从old gen指向young gen的引用就必须作为minor GC / young GC的GC roots的一部分。
继续具体到HotSpot VM里的分两代式GC来说,除了old gen到young gen的引用之外,有些带有弱引用语义的结构,例如说记录所有当前被加载的类的SystemDictionary、记录字符串常量引用的StringTable等,在young GC时必须要作为strong GC roots,而在收集整堆的full GC时则不会被看作strong GC roots。
换句话说,young GC比full GC的GC roots还要更大一些。如果不能理解这个道理,那整个讨论也就无从谈起了。

参考来源

唠叨一下

  • 完全属于面试题,对编程没有什么卵用

相关文章

  • JVM - 垃圾回收器

    JVM - 垃圾回收器 Young GC 查找GC Roots,拷贝所引用的对象到to区GC ROOTS内存区域主...

  • JVM - GC垃圾回收

    注:可达性分析法(判断对象是否存活):当一个对象到GC Roots没有任何引用链相连时。GC Roots对象:虚拟...

  • G1垃圾收集器

    初始标记暂停所有其他现场(STW),标记GC Roots能直接引用的对象 并发标记从GC Roots直接引用的对象...

  • GC Roots对象

    官方参考 Garbage Collection RootsA garbage collection root is...

  • jvm<二> 内存管理

    java虚拟机回收gc roots 查找机制gc roots对象可达, 不会被释放1.虚拟机栈本地变量表引用的对象...

  • JVM:垃圾收集器与内存分配策略(下)

    HotSpot算法实现 枚举根节点:从GC Roots节点中找出引用链的操作。GC Roots对象主要在全局性引用...

  • gc-roots-reachability-analysis-s

    savepoint, gc roots 对象是否已死?引用计数解决不了循环引用问题可达性分析(从 gc roots...

  • Gc Root对象

    1. gc root对象有那些 1.1解释 常说的GC(Garbage Collector) roots,特指的是...

  • JVM - GC Roots对象

    1,Java中的GC Roots对象(确切的说是引用) 1)虚拟机栈(栈帧中的局部变量表)中对象的引用。JVM会通...

  • 垃圾收集器和内存分配策略

    可达性分析算法 当一个对象到GC Roots没有任何引用链(用图论的话说,就是从GC Roots节点触发到某个节点...

网友评论

      本文标题:GC Roots对象

      本文链接:https://www.haomeiwen.com/subject/gmxtnxtx.html