runtime: copy some functions from math/bits to runtime/internal/sys

CL 201765 activated calls from the runtime to functions in math/bits.
When coverage and race detection were simultaneously enabled,
this caused a crash when the covered+race-checked code in
math/bits was called from the runtime before there was even a P.

PS Win for gdlv in helping sort this out.

TODO - next CL intrinsifies the new functions in
runtime/internal/sys

TODO/Would-be-nice - Ctz64 and TrailingZeros64 are the same
function; 386.s is intrinsified; clean all that up.

Fixes #35461.
Updates #35112.

Change-Id: I750a54dba493130ad3e68a06530ede7687d41e1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/206199
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David Chase 2019-11-08 16:11:29 -05:00 committed by Michael Knyszek
parent 42db1da8e9
commit 11da2b227a
7 changed files with 232 additions and 106 deletions

View file

@ -7,7 +7,6 @@
package runtime
import (
"math/bits"
"runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
@ -360,7 +359,7 @@ func ReadMemStatsSlow() (base, slow MemStats) {
slow.HeapReleased += uint64(pg) * pageSize
}
for _, p := range allp {
pg := bits.OnesCount64(p.pcache.scav)
pg := sys.OnesCount64(p.pcache.scav)
slow.HeapReleased += uint64(pg) * pageSize
}
@ -894,7 +893,7 @@ func PageCachePagesLeaked() (leaked uintptr) {
// Since we're going past len(allp) we may see nil Ps.
// Just ignore them.
if p != nil {
leaked += uintptr(bits.OnesCount64(p.pcache.cache))
leaked += uintptr(sys.OnesCount64(p.pcache.cache))
}
}