I am trying to dive deeper into golang and started looking at golang GC 
implementation.

I have read the article 
<https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md>
 and 
try to wrap my head around it.

Lets look at the Reasoning 
<https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md#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.


Moving pointer to an object from the heap to scanned(black) stack 
<https://i.stack.imgur.com/tfsur.png>


   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.


Moving pointer to an object from grey stack into a black object in the heap 
<https://i.stack.imgur.com/KsU5D.png>


   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.


Only Yuasa barier comes to play <https://i.stack.imgur.com/4kqxj.png>

These three points seems clear to me.

>From Rationale 
<https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md#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:
Moving pointer to an object from grey stack object to black(scanned) object 
<https://i.stack.imgur.com/oU10N.png>

What did I miss?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fc3b2c82-6a37-4ed2-b001-19df9c5fe18bn%40googlegroups.com.

Reply via email to