diff options
| author | Keith Randall <khr@golang.org> | 2014-06-30 18:59:24 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2014-06-30 18:59:24 -0700 |
| commit | 7c13860cd08352e785002cb97bd3baafd370e8bc (patch) | |
| tree | 326e70940dba8dfd140cc67d69461d3e9ef488e6 /src/pkg/runtime/stack_test.go | |
| parent | 54951023cb0a1743f7f3cb233ff424593bf1a131 (diff) | |
| download | go-7c13860cd08352e785002cb97bd3baafd370e8bc.tar.xz | |
runtime: stack allocator, separate from mallocgc
In order to move malloc to Go, we need to have a
separate stack allocator. If we run out of stack
during malloc, malloc will not be available
to allocate a new stack.
Stacks are the last remaining FlagNoGC objects in the
GC heap. Once they are out, we can get rid of the
distinction between the allocated/blockboundary bits.
(This will be in a separate change.)
Fixes #7468
Fixes #7424
LGTM=rsc, dvyukov
R=golang-codereviews, dvyukov, khr, dave, rsc
CC=golang-codereviews
https://golang.org/cl/104200047
Diffstat (limited to 'src/pkg/runtime/stack_test.go')
| -rw-r--r-- | src/pkg/runtime/stack_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pkg/runtime/stack_test.go b/src/pkg/runtime/stack_test.go index f0c599ac5d..424a15b3e5 100644 --- a/src/pkg/runtime/stack_test.go +++ b/src/pkg/runtime/stack_test.go @@ -281,3 +281,52 @@ func TestDeferPtrs(t *testing.T) { defer set(&y, 42) growStack() } + +// use about n KB of stack +func useStack(n int) { + if n == 0 { + return + } + var b [1024]byte // makes frame about 1KB + useStack(n - 1 + int(b[99])) +} + +func growing(c chan int, done chan struct{}) { + for n := range c { + useStack(n) + done <- struct{}{} + } + done <- struct{}{} +} + +func TestStackCache(t *testing.T) { + // Allocate a bunch of goroutines and grow their stacks. + // Repeat a few times to test the stack cache. + const ( + R = 4 + G = 200 + S = 5 + ) + for i := 0; i < R; i++ { + var reqchans [G]chan int + done := make(chan struct{}) + for j := 0; j < G; j++ { + reqchans[j] = make(chan int) + go growing(reqchans[j], done) + } + for s := 0; s < S; s++ { + for j := 0; j < G; j++ { + reqchans[j] <- 1 << uint(s) + } + for j := 0; j < G; j++ { + <-done + } + } + for j := 0; j < G; j++ { + close(reqchans[j]) + } + for j := 0; j < G; j++ { + <-done + } + } +} |
