diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-10-26 23:57:58 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-10-26 23:57:58 +0000 |
commit | d8f412571f8768df2d3239e72392dfeabbad1559 (patch) | |
tree | 19d182df05ead7ff8ba7ee00a7d57555e1383fdf /libgo/go/runtime | |
parent | e0c39d66d4f0607177b1cf8995dda56a667e07b3 (diff) | |
download | gcc-d8f412571f8768df2d3239e72392dfeabbad1559.zip gcc-d8f412571f8768df2d3239e72392dfeabbad1559.tar.gz gcc-d8f412571f8768df2d3239e72392dfeabbad1559.tar.bz2 |
Update Go library to last weekly.
From-SVN: r180552
Diffstat (limited to 'libgo/go/runtime')
-rw-r--r-- | libgo/go/runtime/chan_test.go | 51 | ||||
-rw-r--r-- | libgo/go/runtime/extern.go | 7 | ||||
-rw-r--r-- | libgo/go/runtime/gc_test.go | 24 | ||||
-rw-r--r-- | libgo/go/runtime/mfinal_test.go | 64 | ||||
-rw-r--r-- | libgo/go/runtime/pprof/pprof_test.go | 3 |
5 files changed, 141 insertions, 8 deletions
diff --git a/libgo/go/runtime/chan_test.go b/libgo/go/runtime/chan_test.go index 46ddfd7..7cea906 100644 --- a/libgo/go/runtime/chan_test.go +++ b/libgo/go/runtime/chan_test.go @@ -59,6 +59,57 @@ func TestPseudoRandomSend(t *testing.T) { t.Errorf("Want pseudo random, got %d zeros and %d ones", n0, n1) } +func TestMultiConsumer(t *testing.T) { + const nwork = 23 + const niter = 271828 + + pn := []int{2, 3, 7, 11, 13, 17, 19, 23, 27, 31} + + q := make(chan int, nwork*3) + r := make(chan int, nwork*3) + + // workers + var wg sync.WaitGroup + for i := 0; i < nwork; i++ { + wg.Add(1) + go func(w int) { + for v := range q { + // mess with the fifo-ish nature of range + if pn[w%len(pn)] == v { + runtime.Gosched() + } + r <- v + } + wg.Done() + }(i) + } + + // feeder & closer + expect := 0 + go func() { + for i := 0; i < niter; i++ { + v := pn[i%len(pn)] + expect += v + q <- v + } + close(q) // no more work + wg.Wait() // workers done + close(r) // ... so there can be no more results + }() + + // consume & check + n := 0 + s := 0 + for v := range r { + n++ + s += v + } + if n != niter || s != expect { + t.Errorf("Expected sum %d (got %d) from %d iter (saw %d)", + expect, s, niter, n) + } +} + func BenchmarkSelectUncontended(b *testing.B) { const CallsPerSched = 1000 procs := runtime.GOMAXPROCS(-1) diff --git a/libgo/go/runtime/extern.go b/libgo/go/runtime/extern.go index 9da3423..7c986da 100644 --- a/libgo/go/runtime/extern.go +++ b/libgo/go/runtime/extern.go @@ -131,8 +131,8 @@ func Semrelease(s *uint32) // The argument x must be a pointer to an object allocated by // calling new or by taking the address of a composite literal. // The argument f must be a function that takes a single argument -// of x's type and returns no arguments. If either of these is not -// true, SetFinalizer aborts the program. +// of x's type and can have arbitrary ignored return values. +// If either of these is not true, SetFinalizer aborts the program. // // Finalizers are run in dependency order: if A points at B, both have // finalizers, and they are otherwise unreachable, only the finalizer @@ -156,9 +156,6 @@ func Semrelease(s *uint32) // A single goroutine runs all finalizers for a program, sequentially. // If a finalizer must run for a long time, it should do so by starting // a new goroutine. -// -// TODO(rsc): allow f to have (ignored) return values -// func SetFinalizer(x, f interface{}) func getgoroot() string diff --git a/libgo/go/runtime/gc_test.go b/libgo/go/runtime/gc_test.go new file mode 100644 index 0000000..fad60a3 --- /dev/null +++ b/libgo/go/runtime/gc_test.go @@ -0,0 +1,24 @@ +package runtime_test + +import ( + "runtime" + "testing" +) + +func TestGcSys(t *testing.T) { + for i := 0; i < 1000000; i++ { + workthegc() + } + + // Should only be using a few MB. + runtime.UpdateMemStats() + sys := runtime.MemStats.Sys + t.Logf("using %d MB", sys>>20) + if sys > 10e6 { + t.Fatalf("using too much memory: %d MB", sys>>20) + } +} + +func workthegc() []byte { + return make([]byte, 1029) +} diff --git a/libgo/go/runtime/mfinal_test.go b/libgo/go/runtime/mfinal_test.go new file mode 100644 index 0000000..de63271 --- /dev/null +++ b/libgo/go/runtime/mfinal_test.go @@ -0,0 +1,64 @@ +// Copyright 2011 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. + +package runtime_test + +import ( + "runtime" + "sync" + "sync/atomic" + "testing" +) + +func fin(v *int) { +} + +func BenchmarkFinalizer(b *testing.B) { + const CallsPerSched = 1000 + procs := runtime.GOMAXPROCS(-1) + N := int32(b.N / CallsPerSched) + var wg sync.WaitGroup + wg.Add(procs) + for p := 0; p < procs; p++ { + go func() { + var data [CallsPerSched]*int + for i := 0; i < CallsPerSched; i++ { + data[i] = new(int) + } + for atomic.AddInt32(&N, -1) >= 0 { + runtime.Gosched() + for i := 0; i < CallsPerSched; i++ { + runtime.SetFinalizer(data[i], fin) + } + for i := 0; i < CallsPerSched; i++ { + runtime.SetFinalizer(data[i], nil) + } + } + wg.Done() + }() + } + wg.Wait() +} + +func BenchmarkFinalizerRun(b *testing.B) { + const CallsPerSched = 1000 + procs := runtime.GOMAXPROCS(-1) + N := int32(b.N / CallsPerSched) + var wg sync.WaitGroup + wg.Add(procs) + for p := 0; p < procs; p++ { + go func() { + for atomic.AddInt32(&N, -1) >= 0 { + runtime.Gosched() + for i := 0; i < CallsPerSched; i++ { + v := new(int) + runtime.SetFinalizer(v, fin) + } + runtime.GC() + } + wg.Done() + }() + } + wg.Wait() +} diff --git a/libgo/go/runtime/pprof/pprof_test.go b/libgo/go/runtime/pprof/pprof_test.go index 4486d55..5f128c0 100644 --- a/libgo/go/runtime/pprof/pprof_test.go +++ b/libgo/go/runtime/pprof/pprof_test.go @@ -22,9 +22,6 @@ func TestCPUProfile(t *testing.T) { case "plan9": // unimplemented return - case "windows": - // unimplemented - return } buf := make([]byte, 100000) |