aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2014-08-13 13:20:01 +1000
committerAndrew Gerrand <adg@golang.org>2014-08-13 13:20:01 +1000
commitdf7a37efd74b3b9bca093eadf0ed596c745efce6 (patch)
tree55bbb4457a289c5d69a95557f399d0718571d55e
parent1657de2d6dbb020e15908668f209f3be7dcef151 (diff)
downloadgo-df7a37efd74b3b9bca093eadf0ed596c745efce6.tar.gz
go-df7a37efd74b3b9bca093eadf0ed596c745efce6.zip
[release-branch.go1.3] runtime: fix GC bitmap corruption
««« CL 103640044 / d2f256096d8d runtime: fix GC bitmap corruption Fixes #8299. R=golang-codereviews CC=golang-codereviews, khr, rsc https://golang.org/cl/103640044 »»» TBR=r, rsc CC=golang-codereviews https://golang.org/cl/125150044
-rw-r--r--src/pkg/runtime/mgc0.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c
index 392da535b1..9b23c53c21 100644
--- a/src/pkg/runtime/mgc0.c
+++ b/src/pkg/runtime/mgc0.c
@@ -2760,7 +2760,7 @@ runtime·markscan(void *v)
void
runtime·markfreed(void *v)
{
- uintptr *b, off, shift;
+ uintptr *b, off, shift, xbits;
if(0)
runtime·printf("markfreed %p\n", v);
@@ -2771,7 +2771,18 @@ runtime·markfreed(void *v)
off = (uintptr*)v - (uintptr*)runtime·mheap.arena_start; // word offset
b = (uintptr*)runtime·mheap.arena_start - off/wordsPerBitmapWord - 1;
shift = off % wordsPerBitmapWord;
- *b = (*b & ~(bitMask<<shift)) | (bitAllocated<<shift);
+ if(!g->m->gcing || work.nproc == 1) {
+ // During normal operation (not GC), the span bitmap is not updated concurrently,
+ // because either the span is cached or accesses are protected with MCentral lock.
+ *b = (*b & ~(bitMask<<shift)) | (bitAllocated<<shift);
+ } else {
+ // During GC other threads concurrently mark heap.
+ for(;;) {
+ xbits = *b;
+ if(runtime·casp((void**)b, (void*)xbits, (void*)((xbits & ~(bitMask<<shift)) | (bitAllocated<<shift))))
+ break;
+ }
+ }
}
// check that the block at v of size n is marked freed.