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/cgocall.go | |
parent | 41e6abdc61dd23ede4d3509aebf7b5a638f53712 (diff) | |
download | go-058bb7ea278d8e073be1e1c73d01fbfd74c170fd.tar.gz go-058bb7ea278d8e073be1e1c73d01fbfd74c170fd.zip |
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/cgocall.go')
-rw-r--r-- | src/runtime/cgocall.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index 02c4cb3622..8e4b0dea65 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -583,11 +583,12 @@ func cgoCheckUnknownPointer(p unsafe.Pointer, msg string) (base, i uintptr) { return } - b, hbits, span, _ := heapBitsForObject(uintptr(p), 0, 0) + b, span, _ := findObject(uintptr(p), 0, 0) base = b if base == 0 { return } + hbits := heapBitsForAddr(base) n := span.elemsize for i = uintptr(0); i < n; i += sys.PtrSize { if i != 1*sys.PtrSize && !hbits.morePointers() { |