]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert _func.entry to a method
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Sep 2021 21:05:57 +0000 (14:05 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Sep 2021 20:58:49 +0000 (20:58 +0000)
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>
12 files changed:
src/cmd/compile/internal/test/inl_test.go
src/runtime/debugcall.go
src/runtime/debuglog.go
src/runtime/heapdump.go
src/runtime/panic.go
src/runtime/plugin.go
src/runtime/preempt.go
src/runtime/print.go
src/runtime/runtime2.go
src/runtime/stack.go
src/runtime/symtab.go
src/runtime/traceback.go

index 4f20ec1bd1deb9fdc4ce7dd2aa078beb9995916f..06afe835e2f8c26be890926d80c5586a67b58717 100644 (file)
@@ -65,6 +65,7 @@ func TestIntendedInlining(t *testing.T) {
                        "(*bmap).keys",
                        "(*bmap).overflow",
                        "(*waitq).enqueue",
+                       "(*_func).entry",
 
                        // GC-related ones
                        "cgoInRange",
index ad66a18c26ce74bd9a1580d6090ae16a3ac72947..a1440f7649d44a14a39ccecf38cec9fe51b88144 100644 (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)
index 3ce3273f4def09707d447e42e79dea6ef1d6221c..588b54d1f5d8fe96d305f1a0be1179d0f483d887 100644 (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, "]")
        }
 }
index 8fb30d95b9b1be80d880e8fec575632dfc6367da..871637a09e0e904046b65c0b55735fa0d82ebb4c 100644 (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)
index e4bdceb32f1a68d4730846980e441eab6e886dfb..942898716ebb9172acfcb6ab040614826d7ec4af 100644 (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,
index cd7fc5f8489a988a52affb35d62aec12353f7f81..500663bfe2d4858fa78da31aa4c2e34c399b549f 100644 (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), ": ",
index 334bac779eec4b8627f8d6d9240aa219765f1ea9..18566a745987251ce3aae3b4262d825cef856c3c 100644 (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
 }
index 59a91203b9ff9cad9e665833d5a8e362bda68f5b..b2a642bb862f00a049757bb5d2cbf0616f9fd255 100644 (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
index 442042eb16ed71ac265b0489ccbde0be6078783e..8188872ae8b3a7acfb8886d0b0a356ffc0dc7b74 100644 (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
index 368ad6efa45403281bd259483089b3d8ac3a04f4..cccec49f8e22cb8a32ba2c67b5153a8645aa88c4 100644 (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
index 0f4ad5ab955b7146d3fe10381afc9534da1890bd..a11e22130da463296a2380dc94da5ad18f6b7a9a 100644 (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
                }
index 8c0979eec23b5bf5cdce42d9376f324cbf37e36b..530d572095b987d74fc78e0f4846b37c08fda5c6 100644 (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")
 }