diff options
| author | Rick Hudson <rlh@golang.org> | 2014-11-20 12:08:13 -0500 |
|---|---|---|
| committer | Rick Hudson <rlh@golang.org> | 2014-11-20 12:08:13 -0500 |
| commit | 8cfb084534c764f02c8a3b5c72d2b164d22591fd (patch) | |
| tree | 1f351d2ccbe28ccc9434c3c667c6d0f6b624a596 /src/runtime/malloc2.go | |
| parent | 3034be60d87cb927a6fcded5ffb6663ca5f93674 (diff) | |
| download | go-8cfb084534c764f02c8a3b5c72d2b164d22591fd.tar.xz | |
[dev.garbage] runtime: Turn concurrent GC on by default. Avoid write barriers for GC internal structures such as free lists.
LGTM=rsc
R=rsc
CC=golang-codereviews, rsc
https://golang.org/cl/179000043
Diffstat (limited to 'src/runtime/malloc2.go')
| -rw-r--r-- | src/runtime/malloc2.go | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/runtime/malloc2.go b/src/runtime/malloc2.go index 4ac0207b1e..511638d3d3 100644 --- a/src/runtime/malloc2.go +++ b/src/runtime/malloc2.go @@ -139,10 +139,35 @@ const ( ) // A generic linked list of blocks. (Typically the block is bigger than sizeof(MLink).) +// Since assignments to mlink.next will result in a write barrier being preformed +// this can not be used by some of the internal GC structures. For example when +// the sweeper is placing an unmarked object on the free list it does not want the +// write barrier to be called since that could result in the object being reachable. type mlink struct { next *mlink } +// A gclink is a node in a linked list of blocks, like mlink, +// but it is opaque to the garbage collector. +// The GC does not trace the pointers during collection, +// and the compiler does not emit write barriers for assignments +// of gclinkptr values. Code should store references to gclinks +// as gclinkptr, not as *gclink. +type gclink struct { + next gclinkptr +} + +// A gclinkptr is a pointer to a gclink, but it is opaque +// to the garbage collector. +type gclinkptr uintptr + +// ptr returns the *gclink form of p. +// The result should be used for accessing fields, not stored +// in other data structures. +func (p gclinkptr) ptr() *gclink { + return (*gclink)(unsafe.Pointer(p)) +} + // sysAlloc obtains a large chunk of zeroed memory from the // operating system, typically on the order of a hundred kilobytes // or a megabyte. @@ -275,8 +300,8 @@ type mcachelist struct { } type stackfreelist struct { - list *mlink // linked list of free stacks - size uintptr // total size of stacks in list + list gclinkptr // linked list of free stacks + size uintptr // total size of stacks in list } // Per-thread (in Go, per-P) cache for small objects. @@ -346,11 +371,11 @@ const ( ) type mspan struct { - next *mspan // in a span linked list - prev *mspan // in a span linked list - start pageID // starting page number - npages uintptr // number of pages in span - freelist *mlink // list of free objects + next *mspan // in a span linked list + prev *mspan // in a span linked list + start pageID // starting page number + npages uintptr // number of pages in span + freelist gclinkptr // list of free objects // sweep generation: // if sweepgen == h->sweepgen - 2, the span needs sweeping // if sweepgen == h->sweepgen - 1, the span is currently being swept |
