10

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?

1 Answer 1

10

Roman's Blog explains how his GC implementation works.

Intro

Overview

Brooks Forwarding Pointers

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"

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.

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

2
  • is the forwarding pointer always updated with the new address of the object in the process of moving around?
    – Diffy
    Commented May 21, 2015 at 17:33
  • 1
    @Diffy When evacuation takes place, objects are only moved once: from "from-regions" to "to-regions". The forwarding pointers are placed in from-space to take the place of an object moved to to-space. There is no need for constant updating of the forwarding pointer. It's all mentioned in his blog :)
    – Vince
    Commented May 21, 2015 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.