From ee785f03a24e0373be4c2d7256413296735c3414 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 13 Oct 2016 15:34:56 -0400 Subject: [PATCH] runtime: shade stack-to-stack copy when starting a goroutine 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 --- src/runtime/proc.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 774801ab15..c77229b925 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -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 -- 2.48.1