diff options
| author | Austin Clements <austin@google.com> | 2017-12-11 19:40:12 -0500 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2018-02-15 21:12:13 +0000 |
| commit | 058bb7ea278d8e073be1e1c73d01fbfd74c170fd (patch) | |
| tree | e7f5969e7269be71bb20b3e9837bad1128de597a /src/runtime/mbitmap.go | |
| parent | 41e6abdc61dd23ede4d3509aebf7b5a638f53712 (diff) | |
| download | go-058bb7ea278d8e073be1e1c73d01fbfd74c170fd.tar.xz | |
runtime: split object finding out of heapBitsForObject
heapBitsForObject does two things: it finds the base of the object and
it creates the heapBits for the base of the object. There are several
places where we just care about the base of the object. Furthermore,
greyobject only needs the heapBits in the checkmark path and can
easily compute them only when needed. Once we eliminate passing the
heap bits to grayobject, almost all uses of heapBitsForObject don't
need the heap bits.
Hence, this splits heapBitsForObject into findObject and
heapBitsForAddr (the latter already exists), removes the hbits
argument to grayobject, and replaces all heapBitsForObject calls with
calls to findObject.
In addition to making things cleaner overall, heapBitsForAddr is going
to get more expensive shortly, so it's important that we don't do it
needlessly.
Note that there's an interesting performance pitfall here. I had
originally moved findObject to mheap.go, since it made more sense
there. However, that leads to a ~2% slow down and a whopping 11%
increase in L1 icache misses on both the x/garbage and compilebench
benchmarks. This suggests we may want to be more principled about
this, but, for now, let's just leave findObject in mbitmap.go.
(I tried to make findObject small enough to inline by splitting out
the error case, but, sadly, wasn't quite able to get it under the
inlining budget.)
Change-Id: I7bcb92f383ade565d22a9f2494e4c66fd513fb10
Reviewed-on: https://go-review.googlesource.com/85878
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/mbitmap.go')
| -rw-r--r-- | src/runtime/mbitmap.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index 5e3a0011d9..0893afb180 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -370,17 +370,17 @@ func heapBitsForSpan(base uintptr) (hbits heapBits) { return heapBitsForAddr(base) } -// heapBitsForObject returns the base address for the heap object -// containing the address p, the heapBits for base, -// the object's span, and of the index of the object in s. -// If p does not point into a heap object, -// return base == 0 -// otherwise return the base of the object. +// findObject returns the base address for the heap object containing +// the address p, the object's span, and the index of the object in s. +// If p does not point into a heap object, it returns base == 0. +// +// If p points is an invalid heap pointer and debug.invalidptr != 0, +// findObject panics. // // refBase and refOff optionally give the base address of the object // in which the pointer p was found and the byte offset at which it // was found. These are used for error reporting. -func heapBitsForObject(p, refBase, refOff uintptr) (base uintptr, hbits heapBits, s *mspan, objIndex uintptr) { +func findObject(p, refBase, refOff uintptr) (base uintptr, s *mspan, objIndex uintptr) { arenaStart := mheap_.arena_start if p < arenaStart || p >= mheap_.arena_used { return @@ -444,8 +444,6 @@ func heapBitsForObject(p, refBase, refOff uintptr) (base uintptr, hbits heapBits base += objIndex * s.elemsize } } - // Now that we know the actual base, compute heapBits to return to caller. - hbits = heapBitsForAddr(base) return } @@ -1852,7 +1850,8 @@ func getgcmask(ep interface{}) (mask []byte) { } // heap - if base, hbits, s, _ := heapBitsForObject(uintptr(p), 0, 0); base != 0 { + if base, s, _ := findObject(uintptr(p), 0, 0); base != 0 { + hbits := heapBitsForAddr(base) n := s.elemsize mask = make([]byte, n/sys.PtrSize) for i := uintptr(0); i < n; i += sys.PtrSize { |
