为什么将堆分为伊甸园,幸存者空间和旧时代? [英] Why is heap divided into Eden, Survivor spaces and Old Generation?

查看:453
本文介绍了为什么将堆分为伊甸园,幸存者空间和旧时代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您回答有关JVM垃圾收集流程的问题?

Could you please answer me a question about JVM Garbage Collection process?

为什么将堆划分为伊甸园,幸存者空间和旧时代?

Why is heap divided into Eden, Survivor spaces and Old Generation?

处理完新的疏散对象后,将通过从根部开始的引用来访问对象,以找出无法到达的对象.可到达的对象被标记为有效",不可到达的对象未被标记并且将被消除.

When a young evacuation is processed objects are visited through references starting from the roots to find out unreachable ones. Reachable objects are marked as ‘alive’ and unreachable are not marked and will be eliminated.

因此,将考虑 ALL 个对象,包括在旧一代"中分配的对象也将被访问并标记是否可达.

As a result, ALL objects are considered, including objects allocated in Old Generation are also visited and marked if they are reachable.

据我了解,立即回收年轻一代和老一代是很困难的,因为这些世代位于内存的不同连续部分.

As I understand reclaiming Young Generation and Old Generation at once is demanding because these generations are located in different contiguous parts of memory.

但是,即使在扬氏疏散级别上进行了最简单的标记之后,如果知道了所有可到达和不可到达的对象并可以将其删除,那么即使拥有了所有活动对象和死亡对象的整个位图,为什么我们仍需要进行这种划分?

But why do we need this division if even after the simplest marking on the Young evacuation level we have the entire bitmap with all alive and dead objects if all reachable and unreachable objects are known and can be deleted?

我也知道弱的世代假设,但是为什么我们需要除法呢?

I also know weak generational hypothesis about but why do we need the division?

推荐答案

基本前提是,当创建新对象时,不存在从旧对象到新对象的引用,并且对于很多对象,甚至大多数对象他们,这永远不会改变.这意味着,如果可以证明仍然没有从旧对象到新对象的引用,或者当您确切知道已创建了哪些引用时,则可以仅扫描年轻一代进行次要"垃圾收集.

The basic premise is that when new objects are created, no reference from an old object to the new one exists and for a lot of objects, or even most of them, this never changes. This implies that you can do a "minor" garbage collection scanning the young generation only, if you can prove that there are still no references from old objects to new objects or when you know precisely which references have been created.

这意味着必须跟踪并记住对旧对象的引用更改(但要记住前提是此类更改不会经常发生).

This implies that reference changes to old objects must be tracked and remembered (but recall the premise that such changes don’t happen so often).

一种实施策略是卡片标记:

如果垃圾收集器没有收集整个堆(增量收集),则垃圾收集器需要知道从堆的未收集部分到堆的那一部分的指针在哪里正在收集中.这通常用于分代垃圾收集器,其中堆的未收集部分通常是旧的一代,而堆的收集部分是年轻的一代.用于保存此信息的数据结构(指向年轻一代对象的老一代指针)是一个记忆集. 卡片表是一种特殊的记忆集. Java HotSpot VM使用字节数组作为卡表.每个字节称为 card .卡与堆中的地址范围相对应. 使卡变脏意味着将字节的值更改为脏值;脏值可能会在卡所覆盖的地址范围内包含从旧一代到年轻一代的新指针.

If a garbage collector does not collect the entire heap (an incremental collection), the garbage collector needs to know where there are pointers from the uncollected part of the heap into the part of the heap that is being collected. This is typically for a generational garbage collector in which the uncollected part of the heap is usually the old generation, and the collected part of the heap is the young generation. The data structure for keeping this information (old generation pointers to young generation objects), is a remembered set. A card table is a particular type of remembered set. Java HotSpot VM uses an array of bytes as a card table. Each byte is referred to as a card. A card corresponds to a range of addresses in the heap. Dirtying a card means changing the value of the byte to a dirty value; a dirty value might contain a new pointer from the old generation to the young generation in the address range covered by the card.

处理卡意味着查看卡以查看是否存在老一代指针到年轻一代指针,并可能对该信息进行了处理,例如将其传输到另一个数据结构.

Processing a card means looking at the card to see if there is an old generation to young generation pointer and perhaps doing something with that information such as transferring it to another data structure.

当然,使用世代只会带来好处,如果它使我们能够在扫描过程中跳过某些内存区域,并且维护这些记忆的集并不能超过节省的空间.

Of course, using generations only provides a benefit, if it enables us to skip certain memory regions during the scan and if maintaining these remembered sets does not outweigh the savings.

这篇关于为什么将堆分为伊甸园,幸存者空间和旧时代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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