Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Brooks Pointer in Object class

Tags:

java

android

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?

like image 827
Diffy Avatar asked May 21 '15 16:05

Diffy


1 Answers

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

like image 133
Vince Avatar answered Oct 02 '22 08:10

Vince