如何在年轻一代收藏中找到活物? [英] how the live objects are figured out in young generation collection?

查看:82
本文介绍了如何在年轻一代收藏中找到活物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解YGC花费的时间与伊甸园中的活动物体数量成正比.我也了解在Major集合中如何找出活动对象(线程堆栈中的所有对象,静态对象以及可从这些对象传递而来的其他对象.)

I understand that time taken by YGC is proportional to number of live objects in Eden. I also understand that how the live objects are figured out in Major collections (All the objects in thread stacks and static objects and further objects reachable from those objects transitively.)

但是我不明白在年轻一代收藏中如何找到活物? 如果它解析线程堆栈,那么它需要解析eden +占用空间,我认为不是这种情况.那么JVM如何在eden中找到活动对象并将其复制到To Survivor空间中?

But I dont understand how the live objects are figured out in young generation collection ? if it parses the thread stacks, then it need to parse eden + tenured space which is not the case I think. So how does JVM find the live objects in eden and copies them in To Survivor space ?

推荐答案

如何在年轻一代收藏中找出活物?

how the live objects are figured out in young generation collection ?

此文章.

一般来说,世代收藏家对年轻一代的标记如下(假设我们只有两个世代):

In general a generational collector marks the young generation as follows (assuming we just have two generations):

  1. 它标记年轻对象并跟踪从线程堆栈框架和静态框架开始的引用.当找到对旧对象的引用时,它将忽略它.
  2. 然后,它对旧一代中引用年轻一代对象的引用重复此过程.棘手的是在老一代中识别这些引用,而不会标记整个老一代.
  3. 现在,我们已经标记了新一代中所有可以到达的对象...,其余(该代中的)对象都可以回收.

在HotSpot中,使用卡表"标识包含年轻代引用的旧对象.老一代被分成512字节的区域,每个区域都有一个卡".如果该区域包含任何旧的->新一代指针,则会在Card中设置一个位.然后在新一代收集期间跟踪具有卡"位设置的区域中的对象.

In HotSpot, old generation objects that contain young generation references are identified using the "Card Table". The old generation is divided into regions of 512 bytes, and each region has a "Card". If the region contains any old -> new generation pointers, a bit in the Card is set. Objects in regions with the Card bit set are then traced during a new generation collection.

棘手的事情是维护Card表,因为新的空间引用被写入了旧的对象.在HotSpot中,这是使用软件写屏障来实现的,只要将新的空间引用写入与卡相对应的内存区域,该写屏障就会设置相应卡的脏位.如链接文章所述,这会使在对象中设置参考字段更为昂贵,但由于大部分时间只能收集新一代数据而节省了时间,因此这样做显然是值得的.

The tricky thing is maintaining the Card table as new space references are written to old generation objects. In HotSpot, this is implemented using a software write-barrier that sets the appropriate Card's dirty bit whenever a new space reference is written into the memory region corresponding to the Card. As the linked article notes, this makes setting a reference field in an object more expensive, but it is apparently worth it due to the time saved by being able to collect only the new generation most of the time.

这篇关于如何在年轻一代收藏中找到活物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆