mirror of
https://github.com/golang/go
synced 2024-11-26 05:07:59 -07:00
[dev.typeparams] cmd/compile, runtime: simplify opendefer metadata
Now that deferred functions are always argumentless, we don't need the metadata for the frame size, number of arguments, and the information about each argument. Change-Id: I99e75248a22bda6efbdf2012a2f35beca4c18fd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/326061 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
c0a86c10f1
commit
b20747334a
@ -324,43 +324,21 @@ func dvarint(x *obj.LSym, off int, v int64) int {
|
||||
// for stack variables are specified as the number of bytes below varp (pointer to the
|
||||
// top of the local variables) for their starting address. The format is:
|
||||
//
|
||||
// - Max total argument size among all the defers
|
||||
// - Offset of the deferBits variable
|
||||
// - Number of defers in the function
|
||||
// - Information about each defer call, in reverse order of appearance in the function:
|
||||
// - Total argument size of the call
|
||||
// - Offset of the closure value to call
|
||||
// - Number of arguments (including interface receiver or method receiver as first arg)
|
||||
// - Information about each argument
|
||||
// - Offset of the stored defer argument in this function's frame
|
||||
// - Size of the argument
|
||||
// - Offset of where argument should be placed in the args frame when making call
|
||||
func (s *state) emitOpenDeferInfo() {
|
||||
x := base.Ctxt.Lookup(s.curfn.LSym.Name + ".opendefer")
|
||||
s.curfn.LSym.Func().OpenCodedDeferInfo = x
|
||||
off := 0
|
||||
|
||||
// Compute maxargsize (max size of arguments for all defers)
|
||||
// first, so we can output it first to the funcdata
|
||||
var maxargsize int64
|
||||
for i := len(s.openDefers) - 1; i >= 0; i-- {
|
||||
r := s.openDefers[i]
|
||||
argsize := r.n.X.Type().ArgWidth() // TODO register args: but maybe use of abi0 will make this easy
|
||||
if argsize > maxargsize {
|
||||
maxargsize = argsize
|
||||
}
|
||||
}
|
||||
off = dvarint(x, off, maxargsize)
|
||||
off = dvarint(x, off, -s.deferBitsTemp.FrameOffset())
|
||||
off = dvarint(x, off, int64(len(s.openDefers)))
|
||||
|
||||
// Write in reverse-order, for ease of running in that order at runtime
|
||||
for i := len(s.openDefers) - 1; i >= 0; i-- {
|
||||
r := s.openDefers[i]
|
||||
off = dvarint(x, off, r.n.X.Type().ArgWidth())
|
||||
off = dvarint(x, off, -r.closureNode.FrameOffset())
|
||||
numArgs := 0
|
||||
off = dvarint(x, off, int64(numArgs))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -720,8 +720,7 @@ func addOneOpenDeferFrame(gp *g, pc uintptr, sp unsafe.Pointer) {
|
||||
throw("missing deferreturn")
|
||||
}
|
||||
|
||||
maxargsize, _ := readvarintUnsafe(fd)
|
||||
d1 := newdefer(int32(maxargsize))
|
||||
d1 := newdefer(0)
|
||||
d1.openDefer = true
|
||||
d1._panic = nil
|
||||
// These are the pc/sp to set after we've
|
||||
@ -782,27 +781,15 @@ func runOpenDeferFrame(gp *g, d *_defer) bool {
|
||||
done := true
|
||||
fd := d.fd
|
||||
|
||||
// Skip the maxargsize
|
||||
_, fd = readvarintUnsafe(fd)
|
||||
deferBitsOffset, fd := readvarintUnsafe(fd)
|
||||
nDefers, fd := readvarintUnsafe(fd)
|
||||
deferBits := *(*uint8)(unsafe.Pointer(d.varp - uintptr(deferBitsOffset)))
|
||||
|
||||
for i := int(nDefers) - 1; i >= 0; i-- {
|
||||
// read the funcdata info for this defer
|
||||
var argWidth, closureOffset, nArgs uint32
|
||||
argWidth, fd = readvarintUnsafe(fd)
|
||||
var closureOffset uint32
|
||||
closureOffset, fd = readvarintUnsafe(fd)
|
||||
nArgs, fd = readvarintUnsafe(fd)
|
||||
if argWidth != 0 || nArgs != 0 {
|
||||
throw("defer with non-empty frame")
|
||||
}
|
||||
if deferBits&(1<<i) == 0 {
|
||||
for j := uint32(0); j < nArgs; j++ {
|
||||
_, fd = readvarintUnsafe(fd)
|
||||
_, fd = readvarintUnsafe(fd)
|
||||
_, fd = readvarintUnsafe(fd)
|
||||
}
|
||||
continue
|
||||
}
|
||||
closure := *(*func())(unsafe.Pointer(d.varp - uintptr(closureOffset)))
|
||||
|
Loading…
Reference in New Issue
Block a user