diff options
author | Keith Randall <khr@google.com> | 2018-11-27 12:40:16 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2018-11-29 22:23:02 +0000 |
commit | 2140975ebde164ea1eaa70fc72775c03567f2bc9 (patch) | |
tree | 132712d538bebb752042e10ddbdf4a7fae7aab68 /test/writebarrier.go | |
parent | 438b9544a079576c539cdc040cbf337966a0b25d (diff) | |
download | go-2140975ebde164ea1eaa70fc72775c03567f2bc9.tar.gz go-2140975ebde164ea1eaa70fc72775c03567f2bc9.zip |
cmd/compile: eliminate write barriers when writing non-heap ptrs
We don't need a write barrier if:
1) The location we're writing to doesn't hold a heap pointer, and
2) The value we're writing isn't a heap pointer.
The freshly returned value from runtime.newobject satisfies (1).
Pointers to globals, and the contents of the read-only data section satisfy (2).
This is particularly helpful for code like:
p := []string{"abc", "def", "ghi"}
Where the compiler generates:
a := new([3]string)
move(a, statictmp_) // eliminates write barriers here
p := a[:]
For big slice literals, this makes the code a smaller and faster to
compile.
Update #13554. Reduces the compile time by ~10% and RSS by ~30%.
Change-Id: Icab81db7591c8777f68e5d528abd48c7e44c87eb
Reviewed-on: https://go-review.googlesource.com/c/151498
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/writebarrier.go')
-rw-r--r-- | test/writebarrier.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/writebarrier.go b/test/writebarrier.go index 55ba81e764..8d262dd203 100644 --- a/test/writebarrier.go +++ b/test/writebarrier.go @@ -250,3 +250,14 @@ func f23c() { // also test partial assignments t23 = T23{p: &i23} // ERROR "write barrier" } + +var g int + +func f24() **int { + p := new(*int) + *p = &g // no write barrier here + return p +} +func f25() []string { + return []string{"abc", "def", "ghi"} // no write barrier here +} |