)
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
}
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).
// 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")
}
}
-