]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: copy stack before adjusting
authorAustin Clements <austin@google.com>
Tue, 16 Feb 2016 17:23:33 +0000 (12:23 -0500)
committerAustin Clements <austin@google.com>
Mon, 14 Mar 2016 16:29:47 +0000 (16:29 +0000)
Currently copystack adjusts pointers in the old stack and then copies
the adjusted stack to the new stack. In addition to being generally
confusing, this is going to make concurrent stack shrinking harder.

Switch this around so that we first copy the stack and then adjust
pointers on the new stack (never writing to the old stack).

This reprises CL 15996, but takes a different and simpler approach. CL
15996 still walked the old stack while adjusting pointers on the new
stack. In this CL, we adjust auxiliary structures before walking the
stack, so we can just walk the new stack.

For #12967.

Change-Id: I94fa86f823ba9ee478e73b2ba509eed3361c43df
Reviewed-on: https://go-review.googlesource.com/20033
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/stack.go

index b89dc591427cfe9e3e6a4b4b6ef750d5f160b40b..d37bc7d08b362811cc01768b91ae83d0d8a74128 100644 (file)
@@ -748,29 +748,27 @@ func copystack(gp *g, newsize uintptr) {
                print("copystack gp=", gp, " [", hex(old.lo), " ", hex(old.hi-used), " ", hex(old.hi), "]/", gp.stackAlloc, " -> [", hex(new.lo), " ", hex(new.hi-used), " ", hex(new.hi), "]/", newsize, "\n")
        }
 
-       // Disallow sigprof scans of this stack and block if there's
-       // one in progress.
-       gcLockStackBarriers(gp)
-
-       // adjust pointers in the to-be-copied frames
+       // Compute adjustment.
        var adjinfo adjustinfo
        adjinfo.old = old
        adjinfo.delta = new.hi - old.hi
-       gentraceback(^uintptr(0), ^uintptr(0), 0, gp, 0, nil, 0x7fffffff, adjustframe, noescape(unsafe.Pointer(&adjinfo)), 0)
 
-       // adjust other miscellaneous things that have pointers into stacks.
+       // copy the stack to the new location
+       memmove(unsafe.Pointer(new.hi-used), unsafe.Pointer(old.hi-used), used)
+
+       // Disallow sigprof scans of this stack and block if there's
+       // one in progress.
+       gcLockStackBarriers(gp)
+
+       // Adjust structures that have pointers into stacks. We have
+       // to do most of these before we traceback the new stack
+       // because gentraceback uses them.
        adjustctxt(gp, &adjinfo)
        adjustdefers(gp, &adjinfo)
        adjustpanics(gp, &adjinfo)
        adjustsudogs(gp, &adjinfo)
        adjuststkbar(gp, &adjinfo)
 
-       // copy the stack to the new location
-       if stackPoisonCopy != 0 {
-               fillstack(new, 0xfb)
-       }
-       memmove(unsafe.Pointer(new.hi-used), unsafe.Pointer(old.hi-used), used)
-
        // copy old stack barriers to new stack barrier array
        newstkbar = newstkbar[:len(gp.stkbar)]
        copy(newstkbar, gp.stkbar)
@@ -784,6 +782,9 @@ func copystack(gp *g, newsize uintptr) {
        gp.stkbar = newstkbar
        gp.stktopsp += adjinfo.delta
 
+       // Adjust pointers in the new stack.
+       gentraceback(^uintptr(0), ^uintptr(0), 0, gp, 0, nil, 0x7fffffff, adjustframe, noescape(unsafe.Pointer(&adjinfo)), 0)
+
        gcUnlockStackBarriers(gp)
 
        // free old stack