diff options
author | Austin Clements <austin@google.com> | 2015-03-12 13:09:30 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2015-03-19 15:55:21 +0000 |
commit | cadd4f81a8a637bda2ea22176e11604ceea14a0d (patch) | |
tree | a904d061cec0e44c9d6972957fa1196ddd1c5de0 /src/runtime/mgcwork.go | |
parent | 77fcf36a5ece3eb2a3c2a427d0b63f417ae7c8c8 (diff) | |
download | go-git-cadd4f81a8a637bda2ea22176e11604ceea14a0d.tar.gz |
runtime: combine gcWorkProducer into gcWork
The distinction between gcWorkProducer and gcWork (producer and
consumer) is not serving us as originally intended, so merge these
into just gcWork.
The original intent was to replace the currentwbuf cache with a
gcWorkProducer. However, with gchelpwork (aka mutator assists),
mutators can both produce and consume work, so it will make more sense
to cache a whole gcWork.
Change-Id: I6e633e96db7cb23a64fbadbfc4607e3ad32bcfb3
Reviewed-on: https://go-review.googlesource.com/7733
Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/mgcwork.go')
-rw-r--r-- | src/runtime/mgcwork.go | 74 |
1 files changed, 25 insertions, 49 deletions
diff --git a/src/runtime/mgcwork.go b/src/runtime/mgcwork.go index 5d725a5c82..970020ece4 100644 --- a/src/runtime/mgcwork.go +++ b/src/runtime/mgcwork.go @@ -35,36 +35,25 @@ func (wp wbufptr) ptr() *workbuf { return (*workbuf)(unsafe.Pointer(wp)) } -// A gcWorkProducer provides the interface to produce work for the +// A gcWork provides the interface to produce and consume work for the // garbage collector. // -// The usual pattern for using gcWorkProducer is: +// The usual pattern for using gcWork is: // -// var gcw gcWorkProducer -// .. call gcw.put() .. +// var gcw gcWork +// .. call gcw.put() to produce and gcw.get() to consume .. // gcw.dispose() -type gcWorkProducer struct { +type gcWork struct { // Invariant: wbuf is never full or empty wbuf wbufptr } -// A gcWork provides the interface to both produce and consume work -// for the garbage collector. -// -// The pattern for using gcWork is the same as gcWorkProducer. -type gcWork struct { - gcWorkProducer -} - -// Note that there is no need for a gcWorkConsumer because everything -// that consumes pointers also produces them. - // initFromCache fetches work from this M's currentwbuf cache. //go:nowritebarrier -func (w *gcWorkProducer) initFromCache() { - // TODO: Instead of making gcWorkProducer pull from the - // currentwbuf cache, use a gcWorkProducer as the cache and - // make shade pass around that gcWorkProducer. +func (w *gcWork) initFromCache() { + // TODO: Instead of making gcWork pull from the currentwbuf + // cache, use a gcWork as the cache and make shade pass around + // that gcWork. if w.wbuf == 0 { w.wbuf = wbufptr(xchguintptr(&getg().m.currentwbuf, 0)) } @@ -72,8 +61,8 @@ func (w *gcWorkProducer) initFromCache() { // put enqueues a pointer for the garbage collector to trace. //go:nowritebarrier -func (ww *gcWorkProducer) put(obj uintptr) { - w := (*gcWorkProducer)(noescape(unsafe.Pointer(ww))) // TODO: remove when escape analysis is fixed +func (ww *gcWork) put(obj uintptr) { + w := (*gcWork)(noescape(unsafe.Pointer(ww))) // TODO: remove when escape analysis is fixed wbuf := w.wbuf.ptr() if wbuf == nil { @@ -90,28 +79,6 @@ func (ww *gcWorkProducer) put(obj uintptr) { } } -// dispose returns any cached pointers to the global queue. -//go:nowritebarrier -func (w *gcWorkProducer) dispose() { - if wbuf := w.wbuf; wbuf != 0 { - putpartial(wbuf.ptr(), 58) - w.wbuf = 0 - } -} - -// disposeToCache returns any cached pointers to this M's currentwbuf. -// It calls throw if currentwbuf is non-nil. -//go:nowritebarrier -func (w *gcWorkProducer) disposeToCache() { - if wbuf := w.wbuf; wbuf != 0 { - wbuf = wbufptr(xchguintptr(&getg().m.currentwbuf, uintptr(wbuf))) - if wbuf != 0 { - throw("m.currentwbuf non-nil in disposeToCache") - } - w.wbuf = 0 - } -} - // tryGet dequeues a pointer for the garbage collector to trace. // // If there are no pointers remaining in this gcWork or in the global @@ -175,11 +142,20 @@ func (ww *gcWork) get() uintptr { //go:nowritebarrier func (w *gcWork) dispose() { if wbuf := w.wbuf; wbuf != 0 { - // Even though wbuf may only be partially full, we - // want to keep it on the consumer's queues rather - // than putting it back on the producer's queues. - // Hence, we use putfull here. - putfull(wbuf.ptr(), 133) + putpartial(wbuf.ptr(), 167) + w.wbuf = 0 + } +} + +// disposeToCache returns any cached pointers to this M's currentwbuf. +// It calls throw if currentwbuf is non-nil. +//go:nowritebarrier +func (w *gcWork) disposeToCache() { + if wbuf := w.wbuf; wbuf != 0 { + wbuf = wbufptr(xchguintptr(&getg().m.currentwbuf, uintptr(wbuf))) + if wbuf != 0 { + throw("m.currentwbuf non-nil in disposeToCache") + } w.wbuf = 0 } } |