aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mbitmap.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2016-05-12 18:10:03 -0400
committerAustin Clements <austin@google.com>2016-05-14 13:49:57 +0000
commit6181db53dbfec513300a236debbdc01735f00c07 (patch)
tree7874bdc7950106a9b10a471efb6ad85fe5964a53 /src/runtime/mbitmap.go
parentd8b08c3aa49d9aaac6ff34dbb8516040cc88a13a (diff)
downloadgo-6181db53dbfec513300a236debbdc01735f00c07.tar.xz
runtime: improve heapBitsSetType documentation
Currently the heapBitsSetType documentation says that there are no races on the heap bitmap, but that isn't exactly true. There are no *write-write* races, but there are read-write races. Expand the documentation to explain this and why it's okay. Change-Id: Ibd92b69bcd6524a40a9dd4ec82422b50831071ed Reviewed-on: https://go-review.googlesource.com/23092 Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/mbitmap.go')
-rw-r--r--src/runtime/mbitmap.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go
index 27f8e66d50..ccefbcd8d6 100644
--- a/src/runtime/mbitmap.go
+++ b/src/runtime/mbitmap.go
@@ -847,10 +847,20 @@ func (s *mspan) countFree() int {
// malloc does not call heapBitsSetType when there are no pointers,
// because all free objects are marked as noscan during
// heapBitsSweepSpan.
+//
// There can only be one allocation from a given span active at a time,
-// so this code is not racing with other instances of itself, and
-// the bitmap for a span always falls on byte boundaries.
-// Hence, it can access the bitmap with racing.
+// and the bitmap for a span always falls on byte boundaries,
+// so there are no write-write races for access to the heap bitmap.
+// Hence, heapBitsSetType can access the bitmap without atomics.
+//
+// There can be read-write races between heapBitsSetType and things
+// that read the heap bitmap like scanobject. However, since
+// heapBitsSetType is only used for objects that have not yet been
+// made reachable, readers will ignore bits being modified by this
+// function. This does mean this function cannot transiently modify
+// bits that belong to neighboring objects. Also, on weakly-ordered
+// machines, callers must execute a store/store (publication) barrier
+// between calling this function and making the object reachable.
//
// TODO: This still has atomic accesses left over from when it could
// race with GC accessing mark bits in the bitmap. Remove these.