Skip to content

Commit

Permalink
iterator itab table, remove all interface inter or type in load module
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Jun 29, 2020
1 parent db906b6 commit 4ce8ac9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
28 changes: 11 additions & 17 deletions iface.1.10.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,20 @@ func additabs(module *moduledata) {
unlock(&itabLock)
}

func removeitab(inter *interfacetype, typ *_type) bool {
func removeitabs(module *moduledata) bool {
lock(&itabLock)
defer unlock(&itabLock)
mask := itabTable.size - 1
h := itabHashFunc(inter, typ) & mask
for i := uintptr(1); ; i++ {
p := (**itab)(add(unsafe.Pointer(&itabTable.entries), h*PtrSize))
// Use atomic read here so if we see m != nil, we also see
// the initializations of the fields of m.
// m := *p
for i := uintptr(0); i < itabTable.size; i++ {
p := (**itab)(add(unsafe.Pointer(&itabTable.entries), i*PtrSize))
m := (*itab)(loadp(unsafe.Pointer(p)))
if m == nil {
return false
}
if m.inter == inter && m._type == typ {
atomicstorep(unsafe.Pointer(p), unsafe.Pointer(nil))
itabTable.count = itabTable.count - 1
return true
if m != nil {
inter := uintptr(unsafe.Pointer(m.inter))
_type := uintptr(unsafe.Pointer(m._type))
if (inter >= module.types && inter <= module.etypes) || (_type >= module.types && _type <= module.etypes) {
atomicstorep(unsafe.Pointer(p), unsafe.Pointer(nil))
itabTable.count = itabTable.count - 1
}
}
h += i
h &= mask
}
return true
}
28 changes: 16 additions & 12 deletions iface.1.8.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,25 @@ func additabs(module *moduledata) {
unlock(&ifaceLock)
}

func removeitab(inter *interfacetype, typ *_type) bool {
func removeitabs(module *moduledata) bool {
lock(&ifaceLock)
defer unlock(&ifaceLock)
h := itabhash(inter, typ)
var m, last *itab = nil, nil
for m = (*itab)(loadp(unsafe.Pointer(&hash[h]))); m != nil; m = m.link {
if m.inter == inter && m._type == typ {
if last == nil {
atomicstorep(unsafe.Pointer(&hash[h]), unsafe.Pointer(nil))
} else {
last.link = m.link

//the itab alloc by runtime.persistentalloc, can't free
for index, h := range &hash {
last := h
for m := h; m != nil; m = m.link {
inter := uintptr(unsafe.Pointer(m.inter))
_type := uintptr(unsafe.Pointer(m._type))
if (inter >= module.types && inter <= module.etypes) || (_type >= module.types && _type <= module.etypes) {
if m == h {
hash[index] = m.link
} else {
last.link = m.link
}
}
return true
last = m
}
last = m
}
return false
return true
}
8 changes: 0 additions & 8 deletions iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,3 @@ func unlock(l *mutex)

//go:linkname atomicstorep runtime.atomicstorep
func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer)

func removeitabs(module *moduledata) {
for i := 0; i < len(module.itablinks); i++ {
inter := module.itablinks[i].inter
typ := module.itablinks[i]._type
removeitab(inter, typ)
}
}

0 comments on commit 4ce8ac9

Please sign in to comment.