布鲁克斯指针在Object类指针、布鲁克斯、Object

2023-09-07 04:57:13 作者:8.取一盏清酒

在Android SDK中21 Object.java code,我遇到了术语布鲁克斯指针。我读了后这里但我没有得到它的清晰画面。在帖子中,它被描述为一个参考对象本身在堆中。但有什么用呢? 在垃圾收集和对象疏散它是如何帮助?

In Android SDK 21 in Object.java code, i came across the term "Brooks Pointer". I read the post here but i am not getting a clear picture of it. In the post, it is described as a reference to the Object itself in the heap. But what is the use of it? How will it help in Garbage collection and Object evacuation?

推荐答案

罗马的博客介绍了如何自己GC实施工作。

Roman's Blog explains how his GC implementation works.

介绍

概述

布鲁克斯转发指针

这是在Shenandoah GC一项新功能,它与在堆中的对象进行交互的允许应用程序线程,当他们压缩(移动引用的对象到一个更好的位置)中四处移动 不再需要停了世界

It's a new feature in the Shenandoah GC, which allows application threads to interact with objects in heap while they're being moved around during compacting (moving referenced objects to a better location), removing the need to "stop-the-world"

在此之前,它需要prevent访问引用的对象,而GC感动他们,以确保没有人可以访问该对象,直到它在它的新位置。如果您尝试访问对象,但GC已经移动了它,就会出现问题。这就是为什么我们有停的世界时,它的时间GC(没有线程可以访问对象堆的安全措施)。虽然对象是流动的,对象图被认为是不一致的,所以最好以prevent访问它。

Before this, it was required to prevent access to referenced objects while the GC moved them, to ensure no one can access the object until it's in it's new location. If you tried accessing the object, but the GC has already moved it, problems will occur. This is why we have "stop-the-world" when it's time to GC (no threads are allowed to access objects in heap for safety measures). While objects are moving around, the object graph is considered to be inconsistent, so it's best to prevent access to it.

有了这个新系统,转发指针(向下滚动到转发指针的)被放在地方引用的对象曾经是,它引用对象的新位置。现在,我们不必担心对象不在那里,如果GC要移动它,因为我们可以通过转发指针还在引用它。 我们现在可以访问对象,而GC移动它周围,这意味着压缩过程中,我们不再需要prevent访问。

With this new system, a forwarding pointer (scroll down to forwarding pointer) is put in the place the referenced object used to be, which references the object's new location. Now we don't have to worry about the object not being there if the GC were to move it, since we can still reference it through the forwarding pointer. We can now access the object while the GC is moving it around, which means we no longer need to prevent access during compacting.

转发指针我指的是布鲁克斯指针

The "forwarding pointer" I'm referring to is Brooks Pointer