Skip to content

Commit 256a8fc

Browse files
committed
sync/atomic: disable GC during TestHammerStoreLoad
TestHammerStoreLoad involves a stress test of StorePointer, which has a write barrier. The "pointer" that is being written is not a real value, which is generally fine (though not *really* safe) on 64-bit systems because they never point to an actual object. On 32-bit systems, however, this is much more likely. Because I can't figure out how to rewrite the test such that it still is testing the same conditions but is also using real pointers, just disable the GC during the test, and make sure there isn't one currently in progress. Fixes #49362. Change-Id: If81883fedf06568132e6484f40c820aa69027a9c Reviewed-on: https://go-review.googlesource.com/c/go/+/361455 Trust: Michael Knyszek <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 76c48e9 commit 256a8fc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/sync/atomic/atomic_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package atomic_test
77
import (
88
"fmt"
99
"runtime"
10+
"runtime/debug"
1011
"strings"
1112
. "sync/atomic"
1213
"testing"
@@ -1196,6 +1197,11 @@ func TestHammerStoreLoad(t *testing.T) {
11961197
}
11971198
const procs = 8
11981199
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(procs))
1200+
// Disable the GC because hammerStoreLoadPointer invokes
1201+
// write barriers on values that aren't real pointers.
1202+
defer debug.SetGCPercent(debug.SetGCPercent(-1))
1203+
// Ensure any in-progress GC is finished.
1204+
runtime.GC()
11991205
for _, tt := range tests {
12001206
c := make(chan int)
12011207
var val uint64

0 commit comments

Comments
 (0)