]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add comment
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 25 Aug 2014 16:26:32 +0000 (20:26 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 25 Aug 2014 16:26:32 +0000 (20:26 +0400)
Explain why it's safe to allocate chans with flagNoScan.

LGTM=rsc
R=golang-codereviews
CC=golang-codereviews, khr, rsc
https://golang.org/cl/125510045

src/pkg/runtime/chan.go

index bbf5e7aa83bdf0244156ee866f187c8d070eb9d5..d3fcc6d13f3bf184412c340948abe1f098a6fd81 100644 (file)
@@ -33,7 +33,11 @@ func makechan(t *chantype, size int64) *hchan {
 
        var c *hchan
        if elem.kind&kindNoPointers != 0 || size == 0 {
-               // allocate memory in one call
+               // Allocate memory in one call.
+               // Hchan does not contain pointers interesting for GC in this case:
+               // buf points into the same allocation, elemtype is persistent
+               // and SudoG's are referenced from G so can't be collected.
+               // TODO(dvyukov,rlh): Rethink when collector can move allocated objects.
                c = (*hchan)(gomallocgc(hchanSize+uintptr(size)*uintptr(elem.size), nil, flagNoScan))
                if size > 0 && elem.size != 0 {
                        c.buf = (*uint8)(add(unsafe.Pointer(c), hchanSize))