1
0
mirror of https://github.com/golang/go synced 2024-09-29 21:34:28 -06:00

runtime: replace cgoCtxt slice with index in traceback

Currently, gentraceback consumes the gp.cgoCtxt slice by copying the
slice header and then sub-slicing it as it unwinds. The code for this
is nice and clear, but we're about to lift this state into a structure
and mutating it is going to introduce write barriers that are
disallowed in gentraceback.

This CL replaces the mutable slice header with an index into
gp.cgoCtxt.

For #54466.

Change-Id: I6b701bb67d657290a784baaca34ed02d8247ede2
Reviewed-on: https://go-review.googlesource.com/c/go/+/466863
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Austin Clements 2023-02-09 14:40:05 -05:00
parent ec319d6d43
commit 86b69ef329

View File

@ -76,7 +76,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
if usesLR {
frame.lr = lr0
}
cgoCtxt := gp.cgoCtxt
cgoCtxt := len(gp.cgoCtxt) - 1 // Index into gp.cgoCtxt
printing := pcbuf == nil && callback == nil
// If the PC is zero, it's likely a nil function call.
@ -175,7 +175,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
flag = f.flag
frame.lr = gp.sched.lr
frame.sp = gp.sched.sp
cgoCtxt = gp.cgoCtxt
cgoCtxt = len(gp.cgoCtxt) - 1
case funcID_systemstack:
// systemstack returns normally, so just follow the
// stack transition.
@ -192,7 +192,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
gp = gp.m.curg
frame.sp = gp.sched.sp
cgoCtxt = gp.cgoCtxt
cgoCtxt = len(gp.cgoCtxt) - 1
flag &^= funcFlag_SPWRITE
}
}
@ -390,9 +390,9 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
n++
if f.funcID == funcID_cgocallback && len(cgoCtxt) > 0 {
ctxt := cgoCtxt[len(cgoCtxt)-1]
cgoCtxt = cgoCtxt[:len(cgoCtxt)-1]
if f.funcID == funcID_cgocallback && cgoCtxt >= 0 {
ctxt := gp.cgoCtxt[cgoCtxt]
cgoCtxt--
// skip only applies to Go frames.
// callback != nil only used when we only care