How does go GC identify GC roots

336 views
Skip to first unread message

Kavindu Gimhan Zoysa

unread,
Aug 11, 2021, 12:02:44 PM8/11/21
to golang-dev
Hi all,

Currently, I am learning how GC works in golang. I was still unable to find how golang identifies GC roots(heaps references) to mark. Can you please explain or point me to the correct documentation? 

Thank you,
Kavindu

Ian Lance Taylor

unread,
Aug 11, 2021, 4:37:47 PM8/11/21
to Kavindu Gimhan Zoysa, golang-dev
On Wed, Aug 11, 2021 at 9:02 AM Kavindu Gimhan Zoysa
<kavin...@gmail.com> wrote:
>
> Currently, I am learning how GC works in golang. I was still unable to find how golang identifies GC roots(heaps references) to mark. Can you please explain or point me to the correct documentation?

General questions and discussions about how Go works should be on
golang-nuts. golang-dev is focused on the development of the Go
toolchain and standard library. Thanks.

To answer the immediate question, in the current implementation, there
is a bitmap of pointers in the data and BSS sections, found in
moduledata.gcdatamask and moduledata.bssmask. Those bitmaps are built
by the linker. Also of course stacks are GC roots; the compiler
builds liveness bitmasks for each function's stack frame, and the
garbage collector uses them as it unwinds the stack.

Ian
Reply all
Reply to author
Forward
0 new messages