]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: shade stack-to-stack copy when starting a goroutine
authorAustin Clements <austin@google.com>
Thu, 13 Oct 2016 19:34:56 +0000 (15:34 -0400)
committerAustin Clements <austin@google.com>
Fri, 28 Oct 2016 20:05:18 +0000 (20:05 +0000)
The hybrid barrier requires barriers on stack-to-stack copies if
either stack is grey. There are only two instances of this in the
runtime: channel sends and starting a goroutine. Channel sends already
use typedmemmove and hence have the necessary barriers. This commits
adds barriers for the stack-to-stack copy when starting a goroutine.

Updates #17503.

Change-Id: Ibb55e08127ca4d021ac54be61cb96732efa5df5b
Reviewed-on: https://go-review.googlesource.com/31455
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/proc.go

index 774801ab15682420ea08e4ba4351430117c19212..c77229b925ab6ba86bc446e9865e7766ad1524be 100644 (file)
@@ -2810,7 +2810,20 @@ func newproc1(fn *funcval, argp *uint8, narg int32, nret int32, callerpc uintptr
                prepGoExitFrame(sp)
                spArg += sys.MinFrameSize
        }
-       memmove(unsafe.Pointer(spArg), unsafe.Pointer(argp), uintptr(narg))
+       if narg > 0 {
+               memmove(unsafe.Pointer(spArg), unsafe.Pointer(argp), uintptr(narg))
+               // This is a stack-to-stack copy. If write barriers
+               // are enabled and the source stack is grey (the
+               // destination is always black), then perform a
+               // barrier copy.
+               if writeBarrier.needed && !_g_.m.curg.gcscandone {
+                       f := findfunc(fn.fn)
+                       stkmap := (*stackmap)(funcdata(f, _FUNCDATA_ArgsPointerMaps))
+                       // We're in the prologue, so it's always stack map index 0.
+                       bv := stackmapdata(stkmap, 0)
+                       bulkBarrierBitmap(spArg, uintptr(narg), 0, bv.bytedata)
+               }
+       }
 
        memclrNoHeapPointers(unsafe.Pointer(&newg.sched), unsafe.Sizeof(newg.sched))
        newg.sched.sp = sp