diff options
| author | Cherry Mui <cherryyz@google.com> | 2022-11-16 17:32:08 -0500 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-10-02 20:39:21 +0000 |
| commit | 340a4f55c4afac5b74c8df8365decb0c0237d710 (patch) | |
| tree | 6c323e9e445ec5693c9c58e102dbe677e2735c6a /src/runtime/malloc.go | |
| parent | 32b6d2d9a849a0f0120e9139b403831669373b79 (diff) | |
| download | go-340a4f55c4afac5b74c8df8365decb0c0237d710.tar.xz | |
runtime: use smaller fields for mspan.freeindex and nelems
mspan.freeindex and nelems can fit into uint16 for all possible
values. Use uint16 instead of uintptr.
Change-Id: Ifce20751e81d5022be1f6b5cbb5fbe4fd1728b1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/451359
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@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 | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index ec2e547d3f..a071428391 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -886,7 +886,7 @@ var zerobase uintptr func nextFreeFast(s *mspan) gclinkptr { theBit := sys.TrailingZeros64(s.allocCache) // Is there a free object in the allocCache? if theBit < 64 { - result := s.freeindex + uintptr(theBit) + result := s.freeindex + uint16(theBit) if result < s.nelems { freeidx := result + 1 if freeidx%64 == 0 && freeidx != s.nelems { @@ -895,7 +895,7 @@ func nextFreeFast(s *mspan) gclinkptr { s.allocCache >>= uint(theBit + 1) s.freeindex = freeidx s.allocCount++ - return gclinkptr(result*s.elemsize + s.base()) + return gclinkptr(uintptr(result)*s.elemsize + s.base()) } } return 0 @@ -916,7 +916,7 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo freeIndex := s.nextFreeIndex() if freeIndex == s.nelems { // The span is full. - if uintptr(s.allocCount) != s.nelems { + if s.allocCount != s.nelems { println("runtime: s.allocCount=", s.allocCount, "s.nelems=", s.nelems) throw("s.allocCount != s.nelems && freeIndex == s.nelems") } @@ -931,9 +931,9 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo throw("freeIndex is not valid") } - v = gclinkptr(freeIndex*s.elemsize + s.base()) + v = gclinkptr(uintptr(freeIndex)*s.elemsize + s.base()) s.allocCount++ - if uintptr(s.allocCount) > s.nelems { + if s.allocCount > s.nelems { println("s.allocCount=", s.allocCount, "s.nelems=", s.nelems) throw("s.allocCount > s.nelems") } |
