aboutsummaryrefslogtreecommitdiff
path: root/test/tinyfin.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2015-11-02 07:46:44 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2015-11-02 16:08:33 +0000
commitd2fa937a2188fdfcf1b81857eb297ba53b3a7867 (patch)
treea1eabf85314b61eed0a3b01cb1707f780d854003 /test/tinyfin.go
parenta4fb8c13db3f1501f8195306de571b64ed1aeb73 (diff)
downloadgo-d2fa937a2188fdfcf1b81857eb297ba53b3a7867.tar.gz
go-d2fa937a2188fdfcf1b81857eb297ba53b3a7867.zip
test: update tinyfin test
* use new(int32) to be pedantic about documented SetFinalizer rules: "The argument x must be a pointer to an object allocated by calling new or by taking the address of a composite literal" * remove the amd64-only restriction. The GC is fully precise everywhere now, even on 32-bit. (keep the gccgo restriction, though) * remove a data race (perhaps the actual bug) and use atomic.LoadInt32 for the final check. The race detector is now happy, too. Updates #13100 Change-Id: I8d05c0ac4f046af9ba05701ad709c57984b34893 Reviewed-on: https://go-review.googlesource.com/16535 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/tinyfin.go')
-rw-r--r--test/tinyfin.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/test/tinyfin.go b/test/tinyfin.go
index 8fb109fc06..d9ffa7cab2 100644
--- a/test/tinyfin.go
+++ b/test/tinyfin.go
@@ -15,12 +15,8 @@ import (
)
func main() {
- // Does not work on 32-bits due to partially conservative GC.
+ // Does not work on gccgo due to partially conservative GC.
// Try to enable when we have fully precise GC.
- if runtime.GOARCH != "amd64" {
- return
- }
- // Likewise for gccgo.
if runtime.Compiler == "gccgo" {
return
}
@@ -28,9 +24,10 @@ func main() {
count := N
done := make([]bool, N)
for i := int32(0); i < N; i++ {
- x := i // subject to tiny alloc
+ x := new(int32) // subject to tiny alloc
+ *x = i
// the closure must be big enough to be combined
- runtime.SetFinalizer(&x, func(p *int32) {
+ runtime.SetFinalizer(x, func(p *int32) {
// Check that p points to the correct subobject of the tiny allocation.
// It's a bit tricky, because we can't capture another variable
// with the expected value (it would be combined as well).
@@ -54,9 +51,8 @@ func main() {
// if the outermost allocations are combined with something persistent.
// Currently 4 int32's are combined into a 16-byte block,
// ensure that most of them are finalized.
- if count >= N/4 {
+ if atomic.LoadInt32(&count) >= N/4 {
println(count, "out of", N, "finalizer are not called")
panic("not all finalizers are called")
}
}
-