runtime: convert _func.entry to a method

A subsequent change will alter the semantics of _func.entry.
To make that change obvious and clear, change _func.entry to a method,
and rename the field to _func.entryPC.

Change-Id: I05d66b54d06c5956d4537b0729ddf4290c3e2635
Reviewed-on: https://go-review.googlesource.com/c/go/+/351460
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Josh Bleecher Snyder 2021-09-21 14:05:57 -07:00
parent 6c163e5ac9
commit 61a0a70113
12 changed files with 44 additions and 38 deletions

View file

@ -65,6 +65,7 @@ func TestIntendedInlining(t *testing.T) {
"(*bmap).keys",
"(*bmap).overflow",
"(*waitq).enqueue",
"(*_func).entry",
// GC-related ones
"cgoInRange",

View file

@ -78,7 +78,7 @@ func debugCallCheck(pc uintptr) string {
}
// Check that this isn't an unsafe-point.
if pc != f.entry {
if pc != f.entry() {
pc--
}
up := pcdatavalue(f, _PCDATA_UnsafePoint, pc, nil)

View file

@ -802,7 +802,7 @@ func printDebugLog() {
// pc is a return PC that must first be converted to a call PC.
func printDebugLogPC(pc uintptr, returnPC bool) {
fn := findfunc(pc)
if returnPC && (!fn.valid() || pc > fn.entry) {
if returnPC && (!fn.valid() || pc > fn.entry()) {
// TODO(austin): Don't back up if the previous frame
// was a sigpanic.
pc--
@ -814,7 +814,7 @@ func printDebugLogPC(pc uintptr, returnPC bool) {
} else {
name := funcname(fn)
file, line := funcline(fn, pc)
print(" [", name, "+", hex(pc-fn.entry),
print(" [", name, "+", hex(pc-fn.entry()),
" ", file, ":", line, "]")
}
}

View file

@ -259,7 +259,7 @@ func dumpframe(s *stkframe, arg unsafe.Pointer) bool {
// Figure out what we can about our stack map
pc := s.pc
pcdata := int32(-1) // Use the entry map at function entry
if pc != f.entry {
if pc != f.entry() {
pc--
pcdata = pcdatavalue(f, _PCDATA_StackMapIndex, pc, nil)
}
@ -284,7 +284,7 @@ func dumpframe(s *stkframe, arg unsafe.Pointer) bool {
dumpint(uint64(child.depth)) // # of frames deep on the stack
dumpint(uint64(uintptr(unsafe.Pointer(child.sp)))) // sp of child, or 0 if bottom of stack
dumpmemrange(unsafe.Pointer(s.sp), s.fp-s.sp) // frame contents
dumpint(uint64(f.entry))
dumpint(uint64(f.entry()))
dumpint(uint64(s.pc))
dumpint(uint64(s.continpc))
name := funcname(f)
@ -631,7 +631,7 @@ func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, allocs,
dumpint(0)
} else {
dumpstr(funcname(f))
if i > 0 && pc > f.entry {
if i > 0 && pc > f.entry() {
pc--
}
file, line := funcline(f, pc)

View file

@ -626,7 +626,7 @@ func addOneOpenDeferFrame(gp *g, pc uintptr, sp unsafe.Pointer) {
// deferreturn that runs any remaining
// defers and then returns from the
// function.
d1.pc = frame.fn.entry + uintptr(frame.fn.deferreturn)
d1.pc = frame.fn.entry() + uintptr(frame.fn.deferreturn)
d1.varp = frame.varp
d1.fd = fd
// Save the SP/PC associated with current frame,

View file

@ -112,7 +112,7 @@ func pluginftabverify(md *moduledata) {
f2 := findfunc(entry)
if f2.valid() {
name2 = funcname(f2)
entry2 = f2.entry
entry2 = f2.entry()
}
badtable = true
println("ftab entry", hex(entry), "/", hex(entry2), ": ",

View file

@ -451,7 +451,7 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) (bool, uintptr) {
return true, startpc
case _PCDATA_RestartAtEntry:
// Restart from the function entry at resumption.
return true, f.entry
return true, f.entry()
}
return true, pc
}

View file

@ -293,7 +293,7 @@ func hexdumpWords(p, end uintptr, mark func(uintptr) byte) {
// Can we symbolize val?
fn := findfunc(val)
if fn.valid() {
print("<", funcname(fn), "+", hex(val-fn.entry), "> ")
print("<", funcname(fn), "+", hex(val-fn.entry()), "> ")
}
}
minhexdigits = 0

View file

@ -858,7 +858,7 @@ const (
// Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab)
// and with package debug/gosym and with symtab.go in package runtime.
type _func struct {
entry uintptr // start pc
entryPC uintptr // start pc
nameoff int32 // function name
args int32 // in/out args size

View file

@ -966,7 +966,7 @@ func newstack() {
f := findfunc(gp.sched.pc)
if f.valid() {
pcname = funcname(f)
pcoff = gp.sched.pc - f.entry
pcoff = gp.sched.pc - f.entry()
}
print("runtime: newstack at ", pcname, "+", hex(pcoff),
" sp=", hex(gp.sched.sp), " stack=[", hex(gp.stack.lo), ", ", hex(gp.stack.hi), "]\n",
@ -1240,7 +1240,7 @@ func getStackMap(frame *stkframe, cache *pcvalueCache, debug bool) (locals, args
f := frame.fn
pcdata := int32(-1)
if targetpc != f.entry {
if targetpc != f.entry() {
// Back up to the CALL. If we're at the function entry
// point, we want to use the entry map (-1), even if
// the first instruction of the function changes the

View file

@ -206,7 +206,7 @@ func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr {
}
lastFuncID = inltree[ix].funcID
// Back up to an instruction in the "caller".
tracepc = f.entry + uintptr(inltree[ix].parentPc)
tracepc = f.entry() + uintptr(inltree[ix].parentPc)
pc = tracepc + 1
}
@ -651,7 +651,7 @@ func FuncForPC(pc uintptr) *Func {
file, line := funcline(f, pc)
fi := &funcinl{
ones: ^uintptr(0),
entry: f.entry, // entry of the real (the outermost) function.
entry: f.entry(), // entry of the real (the outermost) function.
name: name,
file: file,
line: int(line),
@ -682,7 +682,7 @@ func (f *Func) Entry() uintptr {
fi := (*funcinl)(unsafe.Pointer(fn))
return fi.entry
}
return fn.entry
return fn.entry()
}
// FileLine returns the file name and line number of the
@ -731,7 +731,12 @@ func (f funcInfo) _Func() *Func {
// isInlined reports whether f should be re-interpreted as a *funcinl.
func (f *_func) isInlined() bool {
return f.entry == ^uintptr(0) // see comment for funcinl.ones
return f.entryPC == ^uintptr(0) // see comment for funcinl.ones
}
// entry returns the entry PC for f.
func (f *_func) entry() uintptr {
return f.entryPC
}
// findfunc looks up function metadata for a PC.
@ -838,19 +843,19 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
if !f.valid() {
if strict && panicking == 0 {
print("runtime: no module data for ", hex(f.entry), "\n")
print("runtime: no module data for ", hex(f.entry()), "\n")
throw("no module data")
}
return -1, 0
}
datap := f.datap
p := datap.pctab[off:]
pc := f.entry
pc := f.entry()
prevpc := pc
val := int32(-1)
for {
var ok bool
p, ok = step(p, &pc, &val, pc == f.entry)
p, ok = step(p, &pc, &val, pc == f.entry())
if !ok {
break
}
@ -887,11 +892,11 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
print("runtime: invalid pc-encoded table f=", funcname(f), " pc=", hex(pc), " targetpc=", hex(targetpc), " tab=", p, "\n")
p = datap.pctab[off:]
pc = f.entry
pc = f.entry()
val = -1
for {
var ok bool
p, ok = step(p, &pc, &val, pc == f.entry)
p, ok = step(p, &pc, &val, pc == f.entry())
if !ok {
break
}
@ -975,7 +980,7 @@ func funcline(f funcInfo, targetpc uintptr) (file string, line int32) {
func funcspdelta(f funcInfo, targetpc uintptr, cache *pcvalueCache) int32 {
x, _ := pcvalue(f, f.pcsp, targetpc, cache, true)
if x&(goarch.PtrSize-1) != 0 {
print("invalid spdelta ", funcname(f), " ", hex(f.entry), " ", hex(targetpc), " ", hex(f.pcsp), " ", x, "\n")
print("invalid spdelta ", funcname(f), " ", hex(f.entry()), " ", hex(targetpc), " ", hex(f.pcsp), " ", x, "\n")
}
return x
}
@ -984,12 +989,12 @@ func funcspdelta(f funcInfo, targetpc uintptr, cache *pcvalueCache) int32 {
func funcMaxSPDelta(f funcInfo) int32 {
datap := f.datap
p := datap.pctab[f.pcsp:]
pc := f.entry
pc := f.entry()
val := int32(-1)
max := int32(0)
for {
var ok bool
p, ok = step(p, &pc, &val, pc == f.entry)
p, ok = step(p, &pc, &val, pc == f.entry())
if !ok {
return max
}

View file

@ -297,7 +297,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
frame.continpc = frame.pc
if waspanic {
if frame.fn.deferreturn != 0 {
frame.continpc = frame.fn.entry + uintptr(frame.fn.deferreturn) + 1
frame.continpc = frame.fn.entry() + uintptr(frame.fn.deferreturn) + 1
// Note: this may perhaps keep return variables alive longer than
// strictly necessary, as we are using "function has a defer statement"
// as a proxy for "function actually deferred something". It seems
@ -333,7 +333,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
// See issue 34123.
// The pc can be at function entry when the frame is initialized without
// actually running code, like runtime.mstart.
if (n == 0 && flags&_TraceTrap != 0) || waspanic || pc == f.entry {
if (n == 0 && flags&_TraceTrap != 0) || waspanic || pc == f.entry() {
pc++
} else {
tracepc--
@ -357,7 +357,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
lastFuncID = inltree[ix].funcID
// Back up to an instruction in the "caller".
tracepc = frame.fn.entry + uintptr(inltree[ix].parentPc)
tracepc = frame.fn.entry() + uintptr(inltree[ix].parentPc)
pc = tracepc + 1
}
}
@ -384,7 +384,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
// backup to CALL instruction to read inlining info (same logic as below)
tracepc := frame.pc
if (n > 0 || flags&_TraceTrap == 0) && frame.pc > f.entry && !waspanic {
if (n > 0 || flags&_TraceTrap == 0) && frame.pc > f.entry() && !waspanic {
tracepc--
}
// If there is inlining info, print the inner frames.
@ -412,7 +412,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
lastFuncID = inltree[ix].funcID
// Back up to an instruction in the "caller".
tracepc = frame.fn.entry + uintptr(inltree[ix].parentPc)
tracepc = frame.fn.entry() + uintptr(inltree[ix].parentPc)
}
}
if (flags&_TraceRuntimeFrames) != 0 || showframe(f, gp, nprint == 0, f.funcID, lastFuncID) {
@ -430,8 +430,8 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
printArgs(f, argp)
print(")\n")
print("\t", file, ":", line)
if frame.pc > f.entry {
print(" +", hex(frame.pc-f.entry))
if frame.pc > f.entry() {
print(" +", hex(frame.pc-f.entry()))
}
if gp.m != nil && gp.m.throwing > 0 && gp == gp.m.curg || level >= 2 {
print(" fp=", hex(frame.fp), " sp=", hex(frame.sp), " pc=", hex(frame.pc))
@ -668,7 +668,7 @@ func getArgInfo(frame *stkframe, f funcInfo, needArgMap bool, ctxt *funcval) (ar
// in the return values.
retValid = *(*bool)(unsafe.Pointer(arg0 + 4*goarch.PtrSize))
}
if mv.fn != f.entry {
if mv.fn != f.entry() {
print("runtime: confused by ", funcname(f), "\n")
throw("reflect mismatch")
}
@ -728,13 +728,13 @@ func printcreatedby(gp *g) {
func printcreatedby1(f funcInfo, pc uintptr) {
print("created by ", funcname(f), "\n")
tracepc := pc // back up to CALL instruction for funcline.
if pc > f.entry {
if pc > f.entry() {
tracepc -= sys.PCQuantum
}
file, line := funcline(f, tracepc)
print("\t", file, ":", line)
if pc > f.entry {
print(" +", hex(pc-f.entry))
if pc > f.entry() {
print(" +", hex(pc-f.entry()))
}
print("\n")
}
@ -842,8 +842,8 @@ func printAncestorTracebackFuncInfo(f funcInfo, pc uintptr) {
}
print(name, "(...)\n")
print("\t", file, ":", line)
if pc > f.entry {
print(" +", hex(pc-f.entry))
if pc > f.entry() {
print(" +", hex(pc-f.entry()))
}
print("\n")
}