Understanding gollvm garbage collection

305 views
Skip to first unread message

Kavindu Gimhan Zoysa

unread,
Jul 9, 2021, 9:15:54 AM7/9/21
to golang-nuts
Hi all,

By looking at the source code, and other mail theads in group, I was able to understand the sopport of GC by gollvm upto some extend. 

1. If we do not enable the gc (-enable-gc=1), GC assumes all the stack memory blocks are pointed to the heap.
2. If gc is enabled, it inserts statepoints and generates the stack map (by LLVM). Using that stack map, GC can find where the actual heap references are located.

As per my understanding, GC is common for both cases (still I was unbale to find the source code for this GC). 

I really appreciate if you can correct me if I am wrong.

Thank you,
Kavindu

Than McIntosh

unread,
Jul 9, 2021, 9:44:43 AM7/9/21
to Kavindu Gimhan Zoysa, golang-nuts
>1. If we do not enable the gc (-enable-gc=1), GC assumes all the stack memory blocks are pointed to the heap.
>2. If gc is enabled, it inserts statepoints and generates the stack map (by LLVM). Using that stack map, GC can find where the actual heap references are located.

Yes, this is basically correct.


>As per my understanding, GC is common for both cases (still I was unbale to find the source code for this GC).

The GC is located in the Go runtime, the version incorporated into libgo in gofrontend. See

https://go.googlesource.com/gofrontend/+/01cb2b5e69a2d08ef3cc1ea023c22ed9b79f5114/libgo/go/runtime/mgc.go

Cheers, Than

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c57dfdf2-dfc4-4f81-b432-739165065d87n%40googlegroups.com.

Kavindu Gimhan Zoysa

unread,
Jul 9, 2021, 10:05:03 AM7/9/21
to golang-nuts
Thank you Than, Is go scheduler is responsible for running GC?

Kavindu Gimhan Zoysa

unread,
Jul 9, 2021, 11:17:13 AM7/9/21
to golang-nuts
Also does gollvm create a new stack map? I think it does not use the stack map created by LLVM.

Thank you,
Kavindu

Ian Lance Taylor

unread,
Jul 9, 2021, 10:57:57 PM7/9/21
to Kavindu Gimhan Zoysa, golang-nuts
On Fri, Jul 9, 2021 at 7:05 AM Kavindu Gimhan Zoysa
<kavin...@gmail.com> wrote:
>
> Thank you Than, Is go scheduler is responsible for running GC?

Go uses a concurrent garbage collector. There are GC worker
goroutines that work in parallel with the rest of the program. There
are also cases where an ordinary program goroutine will do some work
at memory allocation time to help the GC. For the basic framework see
https://golang.org/s/go14gc, although the GC has advanced a great deal
since then.

So: is the Go scheduler responsible for running GC? Sort of, in the
sense that the GC runs in goroutines that are managed by the Go
scheduler, but not really, in that the scheduler and the GC are
relatively independent parts of the runtime.

Ian
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3e8ac852-0653-4602-b6db-df06f0713101n%40googlegroups.com.

Than McIntosh

unread,
Jul 12, 2021, 8:55:22 AM7/12/21
to Kavindu Gimhan Zoysa, golang-nuts
>Also does gollvm create a new stack map? I think it does not use the stack map created by LLVM.

gollvm does not use stack maps of the format used by LLVM, correct.

Than


Kavindu Gimhan Zoysa

unread,
Jul 12, 2021, 9:20:01 AM7/12/21
to golang-nuts
Hi Ian and Than, 

Thank you both. 

Does it use the data available on __LLVM_STACKMAPS section to create that specific stack map? Or does it follow a different way to generate stack map information?

Thank you,
Kavindu

Reply all
Reply to author
Forward
0 new messages