]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] Revert "[dev.typeparams] runtime: make deferproc take a func() argument"
authorCherry Mui <cherryyz@google.com>
Mon, 14 Jun 2021 16:39:14 +0000 (12:39 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 16 Jun 2021 15:27:43 +0000 (15:27 +0000)
Temprary revert CL 325918.

Delve relies on the _defer.fn.fn field to get defer frames.
CL 325918 changes the type of _defer.fn to func(), which no
longer has an fn field.

Change-Id: If6c71b15a27bac579593f5273c9a49715e6e35b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/327775
Trust: Cherry Mui <cherryyz@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/runtime/heapdump.go
src/runtime/panic.go
src/runtime/runtime2.go
src/runtime/stubs.go

index 47e4b6b0d1dba40a2c7f736a4d1d9e697cced361..934e55f49523061a8787551c0aff15d3e92a0ffa 100644 (file)
@@ -381,13 +381,12 @@ func dumpgoroutine(gp *g) {
                dumpint(uint64(uintptr(unsafe.Pointer(gp))))
                dumpint(uint64(d.sp))
                dumpint(uint64(d.pc))
-               fn := *(**funcval)(unsafe.Pointer(&d.fn))
-               dumpint(uint64(uintptr(unsafe.Pointer(fn))))
-               if fn == nil {
+               dumpint(uint64(uintptr(unsafe.Pointer(d.fn))))
+               if d.fn == nil {
                        // d.fn can be nil for open-coded defers
                        dumpint(uint64(0))
                } else {
-                       dumpint(uint64(uintptr(unsafe.Pointer(fn.fn))))
+                       dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn))))
                }
                dumpint(uint64(uintptr(unsafe.Pointer(d.link))))
        }
index 86d41c4e1c525c237494e34f936e559c84617c15..04b95e51e53735218157c7cfb97768431758807f 100644 (file)
@@ -226,7 +226,7 @@ func panicmemAddr(addr uintptr) {
 
 // Create a new deferred function fn, which has no arguments and results.
 // The compiler turns a defer statement into a call to this.
-func deferproc(fn func()) {
+func deferproc(fn *funcval) { // TODO: Make deferproc just take a func().
        gp := getg()
        if gp.m.curg != gp {
                // go code on the system stack can't defer
@@ -302,6 +302,16 @@ func deferprocStack(d *_defer) {
        // been set and must not be clobbered.
 }
 
+// deferFunc returns d's deferred function. This is temporary while we
+// support both modes of GOEXPERIMENT=regabidefer. Once we commit to
+// that experiment, we should change the type of d.fn.
+//go:nosplit
+func deferFunc(d *_defer) func() {
+       var fn func()
+       *(**funcval)(unsafe.Pointer(&fn)) = d.fn
+       return fn
+}
+
 // Each P holds a pool for defers.
 
 // Allocate a Defer, usually using per-P pool.
@@ -461,9 +471,7 @@ func deferreturn() {
        // called with a callback on an LR architecture and jmpdefer is on the
        // stack, because the stack trace can be incorrect in that case - see
        // issue #8153).
-       if fn == nil {
-               fn()
-       }
+       _ = fn.fn
        jmpdefer(fn, argp)
 }
 
@@ -527,7 +535,7 @@ func Goexit() {
                } else {
                        // Save the pc/sp in deferCallSave(), so we can "recover" back to this
                        // loop if necessary.
-                       deferCallSave(&p, d.fn)
+                       deferCallSave(&p, deferFunc(d))
                }
                if p.aborted {
                        // We had a recursive panic in the defer d we started, and
@@ -719,12 +727,12 @@ func runOpenDeferFrame(gp *g, d *_defer) bool {
                if deferBits&(1<<i) == 0 {
                        continue
                }
-               closure := *(*func())(unsafe.Pointer(d.varp - uintptr(closureOffset)))
+               closure := *(**funcval)(unsafe.Pointer(d.varp - uintptr(closureOffset)))
                d.fn = closure
                deferBits = deferBits &^ (1 << i)
                *(*uint8)(unsafe.Pointer(d.varp - uintptr(deferBitsOffset))) = deferBits
                p := d._panic
-               deferCallSave(p, d.fn)
+               deferCallSave(p, deferFunc(d))
                if p != nil && p.aborted {
                        break
                }
@@ -845,7 +853,8 @@ func gopanic(e interface{}) {
                        }
                } else {
                        p.argp = unsafe.Pointer(getargp())
-                       d.fn()
+                       fn := deferFunc(d)
+                       fn()
                }
                p.argp = nil
 
index 75c4818599071dbcbbc0c384af40dbeea854b2cb..f13c649a0903bc1ff3fe6aaab9348aab44148a03 100644 (file)
@@ -953,10 +953,10 @@ type _defer struct {
        // defers. We have only one defer record for the entire frame (which may
        // currently have 0, 1, or more defers active).
        openDefer bool
-       sp        uintptr // sp at time of defer
-       pc        uintptr // pc at time of defer
-       fn        func()  // can be nil for open-coded defers
-       _panic    *_panic // panic that is running defer
+       sp        uintptr  // sp at time of defer
+       pc        uintptr  // pc at time of defer
+       fn        *funcval // can be nil for open-coded defers
+       _panic    *_panic  // panic that is running defer
        link      *_defer
 
        // If openDefer is true, the fields below record values about the stack
index b94acdea1f65f2a58588d86011174c45387663d4..16d758320294509575295ad3388b747d5e159d85 100644 (file)
@@ -177,7 +177,7 @@ func cgocallback(fn, frame, ctxt uintptr)
 func gogo(buf *gobuf)
 
 //go:noescape
-func jmpdefer(fv func(), argp uintptr)
+func jmpdefer(fv *funcval, argp uintptr)
 func asminit()
 func setg(gg *g)
 func breakpoint()