mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: during map delete, update entries after new last element
When we delete an element, and it was the last element in the bucket, update the slots between the new last element and the old last element with the marker that says "no more elements beyond here". Change-Id: I8efeeddf4c9b9fc491c678f84220a5a5094c9c76 Reviewed-on: https://go-review.googlesource.com/c/142438 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
62b850f1c5
commit
df2bb9817b
6 changed files with 187 additions and 4 deletions
|
|
@ -477,3 +477,39 @@ func stackOverflow(x *byte) {
|
|||
var buf [256]byte
|
||||
stackOverflow(&buf[0])
|
||||
}
|
||||
|
||||
func MapTombstoneCheck(m map[int]int) {
|
||||
// Make sure emptyOne and emptyRest are distributed correctly.
|
||||
// We should have a series of filled and emptyOne cells, followed by
|
||||
// a series of emptyRest cells.
|
||||
h := *(**hmap)(unsafe.Pointer(&m))
|
||||
i := interface{}(m)
|
||||
t := *(**maptype)(unsafe.Pointer(&i))
|
||||
|
||||
for x := 0; x < 1<<h.B; x++ {
|
||||
b0 := (*bmap)(add(h.buckets, uintptr(x)*uintptr(t.bucketsize)))
|
||||
n := 0
|
||||
for b := b0; b != nil; b = b.overflow(t) {
|
||||
for i := 0; i < bucketCnt; i++ {
|
||||
if b.tophash[i] != emptyRest {
|
||||
n++
|
||||
}
|
||||
}
|
||||
}
|
||||
k := 0
|
||||
for b := b0; b != nil; b = b.overflow(t) {
|
||||
for i := 0; i < bucketCnt; i++ {
|
||||
if k < n && b.tophash[i] == emptyRest {
|
||||
panic("early emptyRest")
|
||||
}
|
||||
if k >= n && b.tophash[i] != emptyRest {
|
||||
panic("late non-emptyRest")
|
||||
}
|
||||
if k == n-1 && b.tophash[i] == emptyOne {
|
||||
panic("last non-emptyRest entry is emptyOne")
|
||||
}
|
||||
k++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue