diff options
author | Austin Clements <austin@google.com> | 2017-10-24 17:11:32 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2017-10-29 20:21:49 +0000 |
commit | b78b54ff83bab4587f0df5747f432d1b3e7e6846 (patch) | |
tree | 52ce1b564851d0672ae884ce28312c0edc6cd4c1 /test/notinheap3.go | |
parent | 316e3036a7dda449ed9e64b3ab86ef686080a343 (diff) | |
download | go-b78b54ff83bab4587f0df5747f432d1b3e7e6846.tar.gz go-b78b54ff83bab4587f0df5747f432d1b3e7e6846.zip |
cmd/compile: elide write barriers for copy of notinheap pointers
Currently copy and append for types containing only scalars and
notinheap pointers still get compiled to have write barriers, even
though those write barriers are unnecessary. Fix these to use
HasHeapPointer instead of just Haspointer so that they elide write
barriers when possible.
This fixes the unnecessary write barrier in runtime.recordspan when it
grows the h.allspans slice. This is important because recordspan gets
called (*very* indirectly) from (*gcWork).tryGet, which is
go:nowritebarrierrec. Unfortunately, the compiler's analysis has no
hope of seeing this because it goes through the indirect call
fixalloc.first, but I saw it happen.
Change-Id: Ieba3abc555a45f573705eab780debcfe5c4f5dd1
Reviewed-on: https://go-review.googlesource.com/73413
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/notinheap3.go')
-rw-r--r-- | test/notinheap3.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/notinheap3.go b/test/notinheap3.go index e01c7a0a82..b37d73df6d 100644 --- a/test/notinheap3.go +++ b/test/notinheap3.go @@ -30,6 +30,9 @@ type ih struct { // In-heap type var ( v1 t1 v2 t2 + + v1s []t1 + v2s []t2 ) func f() { @@ -43,3 +46,11 @@ func g() { v1 = t1{x: nil} // no barrier v2 = t2{x: nil} // ERROR "write barrier" } + +func h() { + // Test copies and appends. + copy(v1s, v1s[1:]) // no barrier + copy(v2s, v2s[1:]) // ERROR "write barrier" + _ = append(v1s, v1s...) // no barrier + _ = append(v2s, v2s...) // ERROR "write barrier" +} |