1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44:43 -07:00
go/test/fixedbugs/issue10958.go
David Chase d71f36b5aa cmd/compile: check loop rescheduling with stack bound, not counter
After benchmarking with a compiler modified to have better
spill location, it became clear that this method of checking
was actually faster on (at least) two different architectures
(ppc64 and amd64) and it also provides more timely interruption
of loops.

This change adds a modified FOR loop node "FORUNTIL" that
checks after executing the loop body instead of before (i.e.,
always at least once).  This ensures that a pointer past the
end of a slice or array is not made visible to the garbage
collector.

Without the rescheduling checks inserted, the restructured
loop from this  change apparently provides a 1% geomean
improvement on PPC64 running the go1 benchmarks; the
improvement on AMD64 is only 0.12%.

Inserting the rescheduling check exposed some peculiar bug
with the ssa test code for s390x; this was updated based on
initial code actually generated for GOARCH=s390x to use
appropriate OpArg, OpAddr, and OpVarDef.

NaCl is disabled in testing.

Change-Id: Ieafaa9a61d2a583ad00968110ef3e7a441abca50
Reviewed-on: https://go-review.googlesource.com/36206
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-03-08 18:52:12 +00:00

96 lines
1.8 KiB
Go

// +build !nacl
// buildrun -t 10 -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
// Copyright 2016 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.
// Test is disabled because it flakes when run in all.bash
// on some platforms, but is useful standalone to verify
// that rescheduling checks are working (and we may wish
// to investigate the flake, since it suggests that the
// loop rescheduling check may not work right on those
// platforms).
// This checks to see that call-free infinite loops do not
// block garbage collection. IF YOU RUN IT STANDALONE without
// -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
// build, it should hang.
package main
import (
"runtime"
)
var someglobal1 int
var someglobal2 int
var someglobal3 int
//go:noinline
func f() {}
func standinacorner1() {
for someglobal1&1 == 0 {
someglobal1++
someglobal1++
}
}
func standinacorner2(i int) {
// contains an irreducible loop containing changes to memory
if i != 0 {
goto midloop
}
loop:
if someglobal2&1 != 0 {
goto done
}
someglobal2++
midloop:
someglobal2++
goto loop
done:
return
}
func standinacorner3() {
for someglobal3&1 == 0 {
if someglobal3&2 != 0 {
for someglobal3&3 == 2 {
someglobal3++
someglobal3++
someglobal3++
someglobal3++
}
}
someglobal3++
someglobal3++
someglobal3++
someglobal3++
}
}
func main() {
go standinacorner1()
go standinacorner2(0)
go standinacorner3()
// println("About to stand in a corner1")
for someglobal1 == 0 {
runtime.Gosched()
}
// println("About to stand in a corner2")
for someglobal2 == 0 {
runtime.Gosched()
}
// println("About to stand in a corner3")
for someglobal3 == 0 {
runtime.Gosched()
}
// println("About to GC")
runtime.GC()
// println("Success")
}