runtime: always call slowpath for heap bits in span

This allows us to avoid calling mallocgcSmallScanNoHeader when
sizespecializedmalloc is enabled, reducing binary size.

Change-Id: I16b98bac06eccd42b3c146f3b829aae96a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/780700
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Matloob 2026-05-20 15:08:23 -04:00 committed by Gopher Robot
parent 5a1c0ee6de
commit dd1da37fa4

View file

@ -1076,17 +1076,29 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
return unsafe.Pointer(&zerobase)
}
if sizeSpecializedMallocEnabled && size < uintptr(len(mallocNoScanTable)) {
if typ == nil || !typ.Pointers() {
if size >= maxTinySize {
return mallocNoScanTable[size](size, typ, needzero)
if sizeSpecializedMallocEnabled {
if size < uintptr(len(mallocNoScanTable)) {
if typ == nil || !typ.Pointers() {
if size >= maxTinySize {
return mallocNoScanTable[size](size, typ, needzero)
}
return mallocgcTinySC2(size, typ, needzero)
} else {
if !needzero {
throw("objects with pointers must be zeroed")
}
return mallocScanTable[size](size, typ, needzero)
}
return mallocgcTinySC2(size, typ, needzero)
} else {
if !needzero {
throw("objects with pointers must be zeroed")
}
if heapBitsInSpan(size) {
noscan := typ == nil || !typ.Pointers()
sc := gc.SizeToSizeClass8[divRoundUp(size, gc.SmallSizeDiv)]
elemsize := uintptr(gc.SizeClassToSize[sc])
spc := makeSpanClass(sc, noscan)
if noscan {
return mallocgcSmallNoScanSlowPath(size, typ, needzero, spc, elemsize)
}
return mallocScanTable[size](size, typ, needzero)
return mallocgcSmallScanSlowPath(size, typ, needzero, spc, elemsize)
}
}
@ -1127,11 +1139,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
if !needzero {
throw("objects with pointers must be zeroed")
}
if heapBitsInSpan(size) {
x, elemsize = mallocgcSmallScanNoHeader(size, typ)
} else {
x, elemsize = mallocgcSmallScanHeader(size, typ)
}
x, elemsize = mallocgcSmallScanHeader(size, typ)
}
} else {
x, elemsize = mallocgcLarge(size, typ, needzero)