Skip to content

Commit 4ce8ac9

Browse files
committed
iterator itab table, remove all interface inter or type in load module
1 parent db906b6 commit 4ce8ac9

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

Diff for: iface.1.10.go

+11-17
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,20 @@ func additabs(module *moduledata) {
5858
unlock(&itabLock)
5959
}
6060

61-
func removeitab(inter *interfacetype, typ *_type) bool {
61+
func removeitabs(module *moduledata) bool {
6262
lock(&itabLock)
6363
defer unlock(&itabLock)
64-
mask := itabTable.size - 1
65-
h := itabHashFunc(inter, typ) & mask
66-
for i := uintptr(1); ; i++ {
67-
p := (**itab)(add(unsafe.Pointer(&itabTable.entries), h*PtrSize))
68-
// Use atomic read here so if we see m != nil, we also see
69-
// the initializations of the fields of m.
70-
// m := *p
64+
for i := uintptr(0); i < itabTable.size; i++ {
65+
p := (**itab)(add(unsafe.Pointer(&itabTable.entries), i*PtrSize))
7166
m := (*itab)(loadp(unsafe.Pointer(p)))
72-
if m == nil {
73-
return false
74-
}
75-
if m.inter == inter && m._type == typ {
76-
atomicstorep(unsafe.Pointer(p), unsafe.Pointer(nil))
77-
itabTable.count = itabTable.count - 1
78-
return true
67+
if m != nil {
68+
inter := uintptr(unsafe.Pointer(m.inter))
69+
_type := uintptr(unsafe.Pointer(m._type))
70+
if (inter >= module.types && inter <= module.etypes) || (_type >= module.types && _type <= module.etypes) {
71+
atomicstorep(unsafe.Pointer(p), unsafe.Pointer(nil))
72+
itabTable.count = itabTable.count - 1
73+
}
7974
}
80-
h += i
81-
h &= mask
8275
}
76+
return true
8377
}

Diff for: iface.1.8.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,25 @@ func additabs(module *moduledata) {
5555
unlock(&ifaceLock)
5656
}
5757

58-
func removeitab(inter *interfacetype, typ *_type) bool {
58+
func removeitabs(module *moduledata) bool {
5959
lock(&ifaceLock)
6060
defer unlock(&ifaceLock)
61-
h := itabhash(inter, typ)
62-
var m, last *itab = nil, nil
63-
for m = (*itab)(loadp(unsafe.Pointer(&hash[h]))); m != nil; m = m.link {
64-
if m.inter == inter && m._type == typ {
65-
if last == nil {
66-
atomicstorep(unsafe.Pointer(&hash[h]), unsafe.Pointer(nil))
67-
} else {
68-
last.link = m.link
61+
62+
//the itab alloc by runtime.persistentalloc, can't free
63+
for index, h := range &hash {
64+
last := h
65+
for m := h; m != nil; m = m.link {
66+
inter := uintptr(unsafe.Pointer(m.inter))
67+
_type := uintptr(unsafe.Pointer(m._type))
68+
if (inter >= module.types && inter <= module.etypes) || (_type >= module.types && _type <= module.etypes) {
69+
if m == h {
70+
hash[index] = m.link
71+
} else {
72+
last.link = m.link
73+
}
6974
}
70-
return true
75+
last = m
7176
}
72-
last = m
7377
}
74-
return false
78+
return true
7579
}

Diff for: iface.go

-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,3 @@ func unlock(l *mutex)
2121

2222
//go:linkname atomicstorep runtime.atomicstorep
2323
func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer)
24-
25-
func removeitabs(module *moduledata) {
26-
for i := 0; i < len(module.itablinks); i++ {
27-
inter := module.itablinks[i].inter
28-
typ := module.itablinks[i]._type
29-
removeitab(inter, typ)
30-
}
31-
}

0 commit comments

Comments
 (0)