mirror of
https://github.com/golang/go
synced 2024-11-26 05:07:59 -07:00
runtime: clean up funcID assignment
Large enum sets should be sorted by name when the values don't matter, as they don't here. Do that. Also replace the large switch with a map lookup. This CL is part of a stack adding windows/arm64 support (#36439), intended to land in the Go 1.17 cycle. This CL is, however, not windows/arm64-specific. It is cleanup meant to make the port (and future ports) easier. Change-Id: Ibe727b5d8866bf4c40c96020e1f4632bde7efd59 Reviewed-on: https://go-review.googlesource.com/c/go/+/288798 Trust: Russ Cox <rsc@golang.org> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
c80da0a33a
commit
229695a283
@ -4,6 +4,8 @@
|
||||
|
||||
package objabi
|
||||
|
||||
import "strings"
|
||||
|
||||
// A FuncID identifies particular functions that need to be treated
|
||||
// specially by the runtime.
|
||||
// Note that in some situations involving plugins, there may be multiple
|
||||
@ -13,88 +15,69 @@ type FuncID uint8
|
||||
|
||||
const (
|
||||
FuncID_normal FuncID = iota // not a special function
|
||||
FuncID_runtime_main
|
||||
FuncID_asmcgocall
|
||||
FuncID_asyncPreempt
|
||||
FuncID_cgocallback
|
||||
FuncID_debugCallV1
|
||||
FuncID_externalthreadhandler
|
||||
FuncID_gcBgMarkWorker
|
||||
FuncID_goexit
|
||||
FuncID_gogo
|
||||
FuncID_gopanic
|
||||
FuncID_handleAsyncEvent
|
||||
FuncID_jmpdefer
|
||||
FuncID_mcall
|
||||
FuncID_morestack
|
||||
FuncID_mstart
|
||||
FuncID_rt0_go
|
||||
FuncID_asmcgocall
|
||||
FuncID_sigpanic
|
||||
FuncID_runfinq
|
||||
FuncID_gcBgMarkWorker
|
||||
FuncID_systemstack_switch
|
||||
FuncID_systemstack
|
||||
FuncID_cgocallback
|
||||
FuncID_gogo
|
||||
FuncID_externalthreadhandler
|
||||
FuncID_debugCallV1
|
||||
FuncID_gopanic
|
||||
FuncID_panicwrap
|
||||
FuncID_handleAsyncEvent
|
||||
FuncID_asyncPreempt
|
||||
FuncID_rt0_go
|
||||
FuncID_runfinq
|
||||
FuncID_runtime_main
|
||||
FuncID_sigpanic
|
||||
FuncID_systemstack
|
||||
FuncID_systemstack_switch
|
||||
FuncID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
|
||||
)
|
||||
|
||||
var funcIDs = map[string]FuncID{
|
||||
"asmcgocall": FuncID_asmcgocall,
|
||||
"asyncPreempt": FuncID_asyncPreempt,
|
||||
"cgocallback": FuncID_cgocallback,
|
||||
"debugCallV1": FuncID_debugCallV1,
|
||||
"externalthreadhandler": FuncID_externalthreadhandler,
|
||||
"gcBgMarkWorker": FuncID_gcBgMarkWorker,
|
||||
"go": FuncID_rt0_go,
|
||||
"goexit": FuncID_goexit,
|
||||
"gogo": FuncID_gogo,
|
||||
"gopanic": FuncID_gopanic,
|
||||
"handleAsyncEvent": FuncID_handleAsyncEvent,
|
||||
"jmpdefer": FuncID_jmpdefer,
|
||||
"main": FuncID_runtime_main,
|
||||
"mcall": FuncID_mcall,
|
||||
"morestack": FuncID_morestack,
|
||||
"mstart": FuncID_mstart,
|
||||
"panicwrap": FuncID_panicwrap,
|
||||
"runfinq": FuncID_runfinq,
|
||||
"sigpanic": FuncID_sigpanic,
|
||||
"switch": FuncID_systemstack_switch,
|
||||
"systemstack": FuncID_systemstack,
|
||||
|
||||
// Don't show in call stack but otherwise not special.
|
||||
"deferreturn": FuncID_wrapper,
|
||||
"runOpenDeferFrame": FuncID_wrapper,
|
||||
"reflectcallSave": FuncID_wrapper,
|
||||
}
|
||||
|
||||
// Get the function ID for the named function in the named file.
|
||||
// The function should be package-qualified.
|
||||
func GetFuncID(name string, isWrapper bool) FuncID {
|
||||
if isWrapper {
|
||||
return FuncID_wrapper
|
||||
}
|
||||
switch name {
|
||||
case "runtime.main":
|
||||
return FuncID_runtime_main
|
||||
case "runtime.goexit":
|
||||
return FuncID_goexit
|
||||
case "runtime.jmpdefer":
|
||||
return FuncID_jmpdefer
|
||||
case "runtime.mcall":
|
||||
return FuncID_mcall
|
||||
case "runtime.morestack":
|
||||
return FuncID_morestack
|
||||
case "runtime.mstart":
|
||||
return FuncID_mstart
|
||||
case "runtime.rt0_go":
|
||||
return FuncID_rt0_go
|
||||
case "runtime.asmcgocall":
|
||||
return FuncID_asmcgocall
|
||||
case "runtime.sigpanic":
|
||||
return FuncID_sigpanic
|
||||
case "runtime.runfinq":
|
||||
return FuncID_runfinq
|
||||
case "runtime.gcBgMarkWorker":
|
||||
return FuncID_gcBgMarkWorker
|
||||
case "runtime.systemstack_switch":
|
||||
return FuncID_systemstack_switch
|
||||
case "runtime.systemstack":
|
||||
return FuncID_systemstack
|
||||
case "runtime.cgocallback":
|
||||
return FuncID_cgocallback
|
||||
case "runtime.gogo":
|
||||
return FuncID_gogo
|
||||
case "runtime.externalthreadhandler":
|
||||
return FuncID_externalthreadhandler
|
||||
case "runtime.debugCallV1":
|
||||
return FuncID_debugCallV1
|
||||
case "runtime.gopanic":
|
||||
return FuncID_gopanic
|
||||
case "runtime.panicwrap":
|
||||
return FuncID_panicwrap
|
||||
case "runtime.handleAsyncEvent":
|
||||
return FuncID_handleAsyncEvent
|
||||
case "runtime.asyncPreempt":
|
||||
return FuncID_asyncPreempt
|
||||
case "runtime.deferreturn":
|
||||
// Don't show in the call stack (used when invoking defer functions)
|
||||
return FuncID_wrapper
|
||||
case "runtime.runOpenDeferFrame":
|
||||
// Don't show in the call stack (used when invoking defer functions)
|
||||
return FuncID_wrapper
|
||||
case "runtime.reflectcallSave":
|
||||
// Don't show in the call stack (used when invoking defer functions)
|
||||
return FuncID_wrapper
|
||||
if strings.HasPrefix(name, "runtime.") {
|
||||
if id, ok := funcIDs[name[len("runtime."):]]; ok {
|
||||
return id
|
||||
}
|
||||
}
|
||||
return FuncID_normal
|
||||
}
|
||||
|
@ -308,27 +308,27 @@ type funcID uint8
|
||||
|
||||
const (
|
||||
funcID_normal funcID = iota // not a special function
|
||||
funcID_runtime_main
|
||||
funcID_asmcgocall
|
||||
funcID_asyncPreempt
|
||||
funcID_cgocallback
|
||||
funcID_debugCallV1
|
||||
funcID_externalthreadhandler
|
||||
funcID_gcBgMarkWorker
|
||||
funcID_goexit
|
||||
funcID_gogo
|
||||
funcID_gopanic
|
||||
funcID_handleAsyncEvent
|
||||
funcID_jmpdefer
|
||||
funcID_mcall
|
||||
funcID_morestack
|
||||
funcID_mstart
|
||||
funcID_rt0_go
|
||||
funcID_asmcgocall
|
||||
funcID_sigpanic
|
||||
funcID_runfinq
|
||||
funcID_gcBgMarkWorker
|
||||
funcID_systemstack_switch
|
||||
funcID_systemstack
|
||||
funcID_cgocallback
|
||||
funcID_gogo
|
||||
funcID_externalthreadhandler
|
||||
funcID_debugCallV1
|
||||
funcID_gopanic
|
||||
funcID_panicwrap
|
||||
funcID_handleAsyncEvent
|
||||
funcID_asyncPreempt
|
||||
funcID_rt0_go
|
||||
funcID_runfinq
|
||||
funcID_runtime_main
|
||||
funcID_sigpanic
|
||||
funcID_systemstack
|
||||
funcID_systemstack_switch
|
||||
funcID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user