Understanding go garbage collector

139 views
Skip to first unread message

Ilya

unread,
Jun 2, 2023, 1:30:27 PM6/2/23
to golang-nuts
I am trying to dive deeper into golang and started looking at golang GC implementation.

I have read the article and try to wrap my head around it.

Lets look at the Reasoning part of the article.

I will quote some text from there for quick access and provide some pictures for better understanding what I dont understand.

In the hybrid barrier, the two shades and the condition work together to prevent a mutator from hiding an object:

  1. shade(*slot) prevents a mutator from hiding an object by moving the sole pointer to it from the heap to its stack. If it attempts to unlink an object from the heap, this will shade it.


  1. shade(ptr) prevents a mutator from hiding an object by moving the sole pointer to it from its stack into a black object in the heap. If it attempts to install the pointer into a black object, this will shade it.


  1. Once a goroutine's stack is black, the shade(ptr) becomes unnecessary. shade(ptr) prevents hiding an object by moving it from the stack to the heap, but this requires first having a pointer hidden on the stack. Immediately after a stack is scanned, it only points to shaded objects, so it's not hiding anything, and the shade(*slot) prevents it from hiding any other pointers on its stack.


These three points seems clear to me.

From Rationale part:

The advantage of the hybrid barrier is that it lets a stack scan permanently blacken a stack (without a STW and without write barriers to the stack), which entirely eliminates the need for stack re-scanning, in turn eliminating the need for stack barriers and re-scan lists.

Assuming this I cannot understand how GC handles the following situation:

What did I miss?

Reply all
Reply to author
Forward
0 new messages