From d8b08c3aa49d9aaac6ff34dbb8516040cc88a13a Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 11 May 2016 14:57:33 -0400 Subject: [PATCH] runtime: perform publication barrier even for noscan objects Currently we only execute a publication barrier for scan objects (and skip it for noscan objects). This used to be okay because GC would never consult the object itself (so it wouldn't observe uninitialized memory even if it found a pointer to a noscan object), and the heap bitmap was pre-initialized to noscan. However, now we explicitly initialize the heap bitmap for noscan objects when we allocate them. While the GC will still never consult the contents of a noscan object, it does need to see the initialized heap bitmap. Hence, we need to execute a publication barrier to make the bitmap visible before user code can expose a pointer to the newly allocated object even for noscan objects. Change-Id: Ie4133c638db0d9055b4f7a8061a634d970627153 Reviewed-on: https://go-review.googlesource.com/23043 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/malloc.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index ae81b8681b..b079a07d51 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -699,16 +699,16 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer { scanSize = typ.ptrdata } c.local_scan += scanSize - - // Ensure that the stores above that initialize x to - // type-safe memory and set the heap bits occur before - // the caller can make x observable to the garbage - // collector. Otherwise, on weakly ordered machines, - // the garbage collector could follow a pointer to x, - // but see uninitialized memory or stale heap bits. - publicationBarrier() } + // Ensure that the stores above that initialize x to + // type-safe memory and set the heap bits occur before + // the caller can make x observable to the garbage + // collector. Otherwise, on weakly ordered machines, + // the garbage collector could follow a pointer to x, + // but see uninitialized memory or stale heap bits. + publicationBarrier() + // Allocate black during GC. // All slots hold nil so no scanning is needed. // This may be racing with GC so do it atomically if there can be -- 2.48.1