aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2018-06-03 13:00:19 +0200
committerMartin Möhrmann <moehrmann@google.com>2018-08-24 08:13:47 +0000
commit4363c98f62e9e315ed20b12d2ce47021fd2bf7bc (patch)
tree796e10da765724eeb3fb695176a378c83c94a16a /src/runtime/slice.go
parent96dcc4457b9aad418abc0eb4316c21fefdbf08e1 (diff)
downloadgo-4363c98f62e9e315ed20b12d2ce47021fd2bf7bc.tar.gz
go-4363c98f62e9e315ed20b12d2ce47021fd2bf7bc.zip
runtime: do not execute write barrier on newly allocated slice in growslice
The new slice created in growslice is cleared during malloc for element types containing pointers and therefore can only contain nil pointers. This change avoids executing write barriers for these nil pointers by adding and using a special bulkBarrierPreWriteSrcOnly function that does not enqueue pointers to slots in dst to the write barrier buffer. Change-Id: If9b18248bfeeb6a874b0132d19520adea593bfc4 Reviewed-on: https://go-review.googlesource.com/115996 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index 737aab5704..4206f4384a 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -202,7 +202,9 @@ func growslice(et *_type, old slice, cap int) slice {
// Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory.
p = mallocgc(capmem, et, true)
if writeBarrier.enabled {
- bulkBarrierPreWrite(uintptr(p), uintptr(old.array), lenmem)
+ // Only shade the pointers in old.array since we know the destination slice p
+ // only contains nil pointers because it has been cleared during alloc.
+ bulkBarrierPreWriteSrcOnly(uintptr(p), uintptr(old.array), lenmem)
}
}
memmove(p, old.array, lenmem)