From: Josh Bleecher Snyder Date: Tue, 21 Sep 2021 21:22:51 +0000 (-0700) Subject: runtime: move entry method from _func to funcInfo X-Git-Tag: go1.18beta1~1164 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f0c79caa1398b6a840ec9406eb34b46a125ecb82;p=gostls13.git runtime: move entry method from _func to funcInfo This will be required when we change from storing entry PCs in _func to entry PC offsets, which are relative to the containing module. Notably, almost all uses of the entry method were already called on a funcInfo. Only Func.Entry incurs the additional module lookup cost. This makes Entry considerably slower, but it is probably still fast enough in absolute terms that it is OK. name old time/op new time/op delta Func/Name-8 8.86ns ± 0% 8.33ns ± 2% -5.92% (p=0.000 n=12+13) Func/Entry-8 0.64ns ± 0% 2.62ns ±36% +310.07% (p=0.000 n=14+15) Func/FileLine-8 24.5ns ± 0% 25.0ns ± 4% +2.21% (p=0.015 n=14+13) Change-Id: Ia2d5de5f2f83fab334f1875452b9e8e87651d340 Reviewed-on: https://go-review.googlesource.com/c/go/+/351461 Trust: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder TryBot-Result: Go Bot Reviewed-by: Cherry Mui --- diff --git a/src/cmd/compile/internal/test/inl_test.go b/src/cmd/compile/internal/test/inl_test.go index 06afe835e2..89247fbabf 100644 --- a/src/cmd/compile/internal/test/inl_test.go +++ b/src/cmd/compile/internal/test/inl_test.go @@ -65,7 +65,7 @@ func TestIntendedInlining(t *testing.T) { "(*bmap).keys", "(*bmap).overflow", "(*waitq).enqueue", - "(*_func).entry", + "funcInfo.entry", // GC-related ones "cgoInRange", diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index a11e22130d..7a9bb3e06b 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -272,11 +272,14 @@ func (f *Func) raw() *_func { } func (f *Func) funcInfo() funcInfo { - fn := f.raw() + return f.raw().funcInfo() +} + +func (f *_func) funcInfo() funcInfo { // Find the module containing fn. fn is located in the pclntable. // The unsafe.Pointer to uintptr conversions and arithmetic // are safe because we are working with module addresses. - ptr := uintptr(unsafe.Pointer(fn)) + ptr := uintptr(unsafe.Pointer(f)) var mod *moduledata for datap := &firstmoduledata; datap != nil; datap = datap.next { if len(datap.pclntable) == 0 { @@ -288,7 +291,7 @@ func (f *Func) funcInfo() funcInfo { break } } - return funcInfo{fn, mod} + return funcInfo{f, mod} } // PCDATA and FUNCDATA table indexes. @@ -682,7 +685,7 @@ func (f *Func) Entry() uintptr { fi := (*funcinl)(unsafe.Pointer(fn)) return fi.entry } - return fn.entry() + return fn.funcInfo().entry() } // FileLine returns the file name and line number of the @@ -735,7 +738,7 @@ func (f *_func) isInlined() bool { } // entry returns the entry PC for f. -func (f *_func) entry() uintptr { +func (f funcInfo) entry() uintptr { return f.entryPC }