]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.15] runtime: implement StorepNoWB for wasm in assembly
authorKeith Randall <khr@golang.org>
Sun, 23 Aug 2020 18:52:53 +0000 (11:52 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 9 Oct 2020 17:23:13 +0000 (17:23 +0000)
The second argument of StorepNoWB must be forced to escape.
The current Go code does not explicitly enforce that property.
By implementing in assembly, and not using go:noescape, we
force the issue.

Test is in CL 249761. Issue #40975.

This CL is needed for CL 249917, which changes how go:notinheap
works and breaks the previous StorepNoWB wasm code.

I checked for other possible errors like this. This is the only
go:notinheap that isn't in the runtime itself.

Included test from CL 249761.

Update #41432

Change-Id: I43400a806662655727c4a3baa8902b63bdc9fa57
Reviewed-on: https://go-review.googlesource.com/c/go/+/249962
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
(cherry picked from commit c0602603b20186228b4f89f265cb3f7665e06768)
Reviewed-on: https://go-review.googlesource.com/c/go/+/260878
Trust: Keith Randall <khr@golang.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/runtime/internal/atomic/asm_wasm.s [new file with mode: 0644]
src/runtime/internal/atomic/atomic_test.go
src/runtime/internal/atomic/atomic_wasm.go

diff --git a/src/runtime/internal/atomic/asm_wasm.s b/src/runtime/internal/atomic/asm_wasm.s
new file mode 100644 (file)
index 0000000..7c33cb1
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "textflag.h"
+
+TEXT runtime∕internal∕atomic·StorepNoWB(SB), NOSPLIT, $0-16
+       MOVD ptr+0(FP), R0
+       MOVD val+8(FP), 0(R0)
+       RET
index 0c1125c55831b663f29c278fbff532a22ce8c75d..b0a8fa06103ff2bf5e6c0c694e67d5e1190b08a9 100644 (file)
@@ -220,3 +220,13 @@ func TestBitwiseContended(t *testing.T) {
                }
        }
 }
+
+func TestStorepNoWB(t *testing.T) {
+       var p [2]*int
+       for i := range p {
+               atomic.StorepNoWB(unsafe.Pointer(&p[i]), unsafe.Pointer(new(int)))
+       }
+       if p[0] == p[1] {
+               t.Error("Bad escape analysis of StorepNoWB")
+       }
+}
index 9037c2f7c87c328e335d1b031b3392e725991892..2c0c3a8174055a1058d3b31bf9a09aa730b83073 100644 (file)
@@ -153,14 +153,11 @@ func Store64(ptr *uint64, val uint64) {
        *ptr = val
 }
 
-//go:notinheap
-type noWB struct{}
-
-//go:noinline
-//go:nosplit
-func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) {
-       *(**noWB)(ptr) = (*noWB)(val)
-}
+// StorepNoWB performs *ptr = val atomically and without a write
+// barrier.
+//
+// NO go:noescape annotation; see atomic_pointer.go.
+func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer)
 
 //go:nosplit
 //go:noinline