mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: use built-in clear to simplify code
Change-Id: Icb6d9ca996b4119d8636d9f7f6a56e510d74d059
GitHub-Last-Rev: 08178e8ff7
GitHub-Pull-Request: golang/go#66188
Reviewed-on: https://go-review.googlesource.com/c/go/+/569979
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
69583738eb
commit
c8c46e746b
7 changed files with 12 additions and 35 deletions
|
|
@ -735,9 +735,7 @@ func makeheapobjbv(p uintptr, size uintptr) bitvector {
|
||||||
tmpbuf = (*[1 << 30]byte)(p)[:n]
|
tmpbuf = (*[1 << 30]byte)(p)[:n]
|
||||||
}
|
}
|
||||||
// Convert heap bitmap to pointer bitmap.
|
// Convert heap bitmap to pointer bitmap.
|
||||||
for i := uintptr(0); i < nptr/8+1; i++ {
|
clear(tmpbuf[:nptr/8+1])
|
||||||
tmpbuf[i] = 0
|
|
||||||
}
|
|
||||||
if goexperiment.AllocHeaders {
|
if goexperiment.AllocHeaders {
|
||||||
s := spanOf(p)
|
s := spanOf(p)
|
||||||
tp := s.typePointersOf(p, size)
|
tp := s.typePointersOf(p, size)
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,7 @@ func startCheckmarks() {
|
||||||
arena.checkmarks = bitmap
|
arena.checkmarks = bitmap
|
||||||
} else {
|
} else {
|
||||||
// Otherwise clear the existing bitmap.
|
// Otherwise clear the existing bitmap.
|
||||||
for i := range bitmap.b {
|
clear(bitmap.b[:])
|
||||||
bitmap.b[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Enable checkmarking.
|
// Enable checkmarking.
|
||||||
|
|
|
||||||
|
|
@ -1665,9 +1665,7 @@ func gcResetMarkState() {
|
||||||
unlock(&mheap_.lock)
|
unlock(&mheap_.lock)
|
||||||
for _, ai := range arenas {
|
for _, ai := range arenas {
|
||||||
ha := mheap_.arenas[ai.l1()][ai.l2()]
|
ha := mheap_.arenas[ai.l1()][ai.l2()]
|
||||||
for i := range ha.pageMarks {
|
clear(ha.pageMarks[:])
|
||||||
ha.pageMarks[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
work.bytesMarked = 0
|
work.bytesMarked = 0
|
||||||
|
|
|
||||||
|
|
@ -511,10 +511,7 @@ func (p *pageAlloc) update(base, npages uintptr, contig, alloc bool) {
|
||||||
// either totally allocated or freed.
|
// either totally allocated or freed.
|
||||||
whole := p.summary[len(p.summary)-1][sc+1 : ec]
|
whole := p.summary[len(p.summary)-1][sc+1 : ec]
|
||||||
if alloc {
|
if alloc {
|
||||||
// Should optimize into a memclr.
|
clear(whole)
|
||||||
for i := range whole {
|
|
||||||
whole[i] = 0
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for i := range whole {
|
for i := range whole {
|
||||||
whole[i] = freeChunkSum
|
whole[i] = freeChunkSum
|
||||||
|
|
|
||||||
|
|
@ -85,18 +85,14 @@ func (b *pageBits) clearRange(i, n uint) {
|
||||||
_ = b[j/64]
|
_ = b[j/64]
|
||||||
// Clear leading bits.
|
// Clear leading bits.
|
||||||
b[i/64] &^= ^uint64(0) << (i % 64)
|
b[i/64] &^= ^uint64(0) << (i % 64)
|
||||||
for k := i/64 + 1; k < j/64; k++ {
|
clear(b[i/64+1 : j/64])
|
||||||
b[k] = 0
|
|
||||||
}
|
|
||||||
// Clear trailing bits.
|
// Clear trailing bits.
|
||||||
b[j/64] &^= (uint64(1) << (j%64 + 1)) - 1
|
b[j/64] &^= (uint64(1) << (j%64 + 1)) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearAll frees all the bits of b.
|
// clearAll frees all the bits of b.
|
||||||
func (b *pageBits) clearAll() {
|
func (b *pageBits) clearAll() {
|
||||||
for i := range b {
|
clear(b[:])
|
||||||
b[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearBlock64 clears the 64-bit aligned block of bits containing the i'th bit that
|
// clearBlock64 clears the 64-bit aligned block of bits containing the i'th bit that
|
||||||
|
|
|
||||||
|
|
@ -954,9 +954,7 @@ func record(r *MemProfileRecord, b *bucket) {
|
||||||
asanwrite(unsafe.Pointer(&r.Stack0[0]), unsafe.Sizeof(r.Stack0))
|
asanwrite(unsafe.Pointer(&r.Stack0[0]), unsafe.Sizeof(r.Stack0))
|
||||||
}
|
}
|
||||||
copy(r.Stack0[:], b.stk())
|
copy(r.Stack0[:], b.stk())
|
||||||
for i := int(b.nstk); i < len(r.Stack0); i++ {
|
clear(r.Stack0[b.nstk:])
|
||||||
r.Stack0[i] = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func iterate_memprof(fn func(*bucket, uintptr, *uintptr, uintptr, uintptr, uintptr)) {
|
func iterate_memprof(fn func(*bucket, uintptr, *uintptr, uintptr, uintptr, uintptr)) {
|
||||||
|
|
@ -1012,9 +1010,7 @@ func BlockProfile(p []BlockProfileRecord) (n int, ok bool) {
|
||||||
asanwrite(unsafe.Pointer(&r.Stack0[0]), unsafe.Sizeof(r.Stack0))
|
asanwrite(unsafe.Pointer(&r.Stack0[0]), unsafe.Sizeof(r.Stack0))
|
||||||
}
|
}
|
||||||
i := copy(r.Stack0[:], b.stk())
|
i := copy(r.Stack0[:], b.stk())
|
||||||
for ; i < len(r.Stack0); i++ {
|
clear(r.Stack0[i:])
|
||||||
r.Stack0[i] = 0
|
|
||||||
}
|
|
||||||
p = p[1:]
|
p = p[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1042,9 +1038,7 @@ func MutexProfile(p []BlockProfileRecord) (n int, ok bool) {
|
||||||
r.Count = int64(bp.count)
|
r.Count = int64(bp.count)
|
||||||
r.Cycles = bp.cycles
|
r.Cycles = bp.cycles
|
||||||
i := copy(r.Stack0[:], b.stk())
|
i := copy(r.Stack0[:], b.stk())
|
||||||
for ; i < len(r.Stack0); i++ {
|
clear(r.Stack0[i:])
|
||||||
r.Stack0[i] = 0
|
|
||||||
}
|
|
||||||
p = p[1:]
|
p = p[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -367,10 +367,8 @@ func (b *profBuf) write(tagPtr *unsafe.Pointer, now int64, hdr []uint64, stk []u
|
||||||
data[0] = uint64(2 + b.hdrsize + uintptr(len(stk))) // length
|
data[0] = uint64(2 + b.hdrsize + uintptr(len(stk))) // length
|
||||||
data[1] = uint64(now) // time stamp
|
data[1] = uint64(now) // time stamp
|
||||||
// header, zero-padded
|
// header, zero-padded
|
||||||
i := uintptr(copy(data[2:2+b.hdrsize], hdr))
|
i := copy(data[2:2+b.hdrsize], hdr)
|
||||||
for ; i < b.hdrsize; i++ {
|
clear(data[2+i : 2+b.hdrsize])
|
||||||
data[2+i] = 0
|
|
||||||
}
|
|
||||||
for i, pc := range stk {
|
for i, pc := range stk {
|
||||||
data[2+b.hdrsize+uintptr(i)] = uint64(pc)
|
data[2+b.hdrsize+uintptr(i)] = uint64(pc)
|
||||||
}
|
}
|
||||||
|
|
@ -469,9 +467,7 @@ Read:
|
||||||
dst := b.overflowBuf
|
dst := b.overflowBuf
|
||||||
dst[0] = uint64(2 + b.hdrsize + 1)
|
dst[0] = uint64(2 + b.hdrsize + 1)
|
||||||
dst[1] = time
|
dst[1] = time
|
||||||
for i := uintptr(0); i < b.hdrsize; i++ {
|
clear(dst[2 : 2+b.hdrsize])
|
||||||
dst[2+i] = 0
|
|
||||||
}
|
|
||||||
dst[2+b.hdrsize] = uint64(count)
|
dst[2+b.hdrsize] = uint64(count)
|
||||||
return dst[:2+b.hdrsize+1], overflowTag[:1], false
|
return dst[:2+b.hdrsize+1], overflowTag[:1], false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue