aboutsummaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2014-08-25 20:26:32 +0400
committerDmitriy Vyukov <dvyukov@google.com>2014-08-25 20:26:32 +0400
commit4064d5e9a3dce1b88866f1364a94a02f13db6162 (patch)
tree33339f5249e5f8c874c6276f8196c03227fefff7 /src/pkg
parent9601abaf8b3d454f6bf84ba9f5e07c11de16ef14 (diff)
downloadgo-4064d5e9a3dce1b88866f1364a94a02f13db6162.tar.xz
runtime: add comment
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
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/runtime/chan.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/pkg/runtime/chan.go b/src/pkg/runtime/chan.go
index bbf5e7aa83..d3fcc6d13f 100644
--- a/src/pkg/runtime/chan.go
+++ b/src/pkg/runtime/chan.go
@@ -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))