diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2025-03-04 19:18:22 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-04-23 08:06:33 -0700 |
| commit | e90ba1d208f400eee6a9d14d4f41d54166255320 (patch) | |
| tree | d1c7fd7cc4404866834330c6e3406e31c1bf0872 /src/runtime/malloc.go | |
| parent | 528bafa0498bb26a3b3961fa5bf50d02bd7101bb (diff) | |
| download | go-e90ba1d208f400eee6a9d14d4f41d54166255320.tar.xz | |
runtime: move some malloc constants to internal/runtime/gc
These constants are needed by some future generator programs.
Change-Id: I5dccd009cbb3b2f321523bc0d8eaeb4c82e5df81
Reviewed-on: https://go-review.googlesource.com/c/go/+/655276
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/malloc.go')
| -rw-r--r-- | src/runtime/malloc.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 554cfa6fcf..010f20bf94 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -116,7 +116,11 @@ const ( maxSmallSize = gc.MaxSmallSize pageSize = 1 << gc.PageShift pageMask = pageSize - 1 - _PageSize = pageSize // Unused. Left for viewcore. + + // Unused. Left for viewcore. + _PageSize = pageSize + minSizeForMallocHeader = gc.MinSizeForMallocHeader + mallocHeaderSize = gc.MallocHeaderSize // _64bit = 1 on 64-bit systems, 0 on 32-bit systems _64bit = 1 << (^uintptr(0) >> 63) / 2 @@ -434,7 +438,7 @@ func mallocinit() { if gc.SizeClassToNPages[i] > 1 { sizeClassesUpToMinSizeForMallocHeaderAreOnePage = false } - if minSizeForMallocHeader == uintptr(gc.SizeClassToSize[i]) { + if gc.MinSizeForMallocHeader == uintptr(gc.SizeClassToSize[i]) { minSizeForMallocHeaderIsSizeClass = true break } @@ -447,7 +451,7 @@ func mallocinit() { } // Check that the pointer bitmap for all small sizes without a malloc header // fits in a word. - if minSizeForMallocHeader/goarch.PtrSize > 8*goarch.PtrSize { + if gc.MinSizeForMallocHeader/goarch.PtrSize > 8*goarch.PtrSize { throw("max pointer/scan bitmap size for headerless objects is too large") } @@ -1042,7 +1046,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer { // Actually do the allocation. var x unsafe.Pointer var elemsize uintptr - if size <= maxSmallSize-mallocHeaderSize { + if size <= maxSmallSize-gc.MallocHeaderSize { if typ == nil || !typ.Pointers() { if size < maxTinySize { x, elemsize = mallocgcTiny(size, typ) @@ -1074,8 +1078,8 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer { // Poison the space between the end of the requested size of x // and the end of the slot. Unpoison the requested allocation. frag := elemsize - size - if typ != nil && typ.Pointers() && !heapBitsInSpan(elemsize) && size <= maxSmallSize-mallocHeaderSize { - frag -= mallocHeaderSize + if typ != nil && typ.Pointers() && !heapBitsInSpan(elemsize) && size <= maxSmallSize-gc.MallocHeaderSize { + frag -= gc.MallocHeaderSize } asanpoison(unsafe.Add(x, size-asanRZ), asanRZ) asanunpoison(x, size-asanRZ) @@ -1449,7 +1453,7 @@ func mallocgcSmallScanHeader(size uintptr, typ *_type) (unsafe.Pointer, uintptr) checkGCTrigger := false c := getMCache(mp) - size += mallocHeaderSize + size += gc.MallocHeaderSize var sizeclass uint8 if size <= gc.SmallSizeMax-8 { sizeclass = gc.SizeToSizeClass8[divRoundUp(size, gc.SmallSizeDiv)] @@ -1468,8 +1472,8 @@ func mallocgcSmallScanHeader(size uintptr, typ *_type) (unsafe.Pointer, uintptr) memclrNoHeapPointers(x, size) } header := (**_type)(x) - x = add(x, mallocHeaderSize) - c.scanAlloc += heapSetTypeSmallHeader(uintptr(x), size-mallocHeaderSize, typ, header, span) + x = add(x, gc.MallocHeaderSize) + c.scanAlloc += heapSetTypeSmallHeader(uintptr(x), size-gc.MallocHeaderSize, typ, header, span) // Ensure that the stores above that initialize x to // type-safe memory and set the heap bits occur before |
