]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: adopt race detector for runtime written in Go
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 3 Sep 2014 16:47:30 +0000 (20:47 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 3 Sep 2014 16:47:30 +0000 (20:47 +0400)
Ignore memory access on g0/gsignal.
See the issue for context and explanation.
Fixes #8627.

LGTM=khr
R=golang-codereviews, mdempsky, khr
CC=golang-codereviews, rsc
https://golang.org/cl/137070043

src/pkg/runtime/cpuprof.go
src/pkg/runtime/proc.c
src/pkg/runtime/race.c

index b397eafbe039bf0aeb5361a83800a9f02b0cbe7c..4325d7e1c304b64e1f90341072fafd5847cefb0e 100644 (file)
@@ -239,9 +239,7 @@ Assoc:
        // Reuse the newly evicted entry.
        e.depth = uintptr(len(pc))
        e.count = 1
-       for i := range pc {
-               e.stack[i] = pc[i]
-       }
+       copy(e.stack[:], pc)
 }
 
 // evict copies the given entry's data into the log, so that
@@ -266,10 +264,8 @@ func (p *cpuProfile) evict(e *cpuprofEntry) bool {
        q++
        log[q] = d
        q++
-       for i := uintptr(0); i < d; i++ {
-               log[q] = e.stack[i]
-               q++
-       }
+       copy(log[q:], e.stack[:d])
+       q += d
        p.nlog = q
        e.count = 0
        return true
index 53d3d23d1e7ac3328acee2a56b0255e20ce2b3ff..b159215d1b7c35a16702af68d575e3876b413f52 100644 (file)
@@ -214,7 +214,11 @@ void
 runtime·main(void)
 {
        Defer d;
-       
+
+       // Racectx of m0->g0 is used only as the parent of the main goroutine.
+       // It must not be used for anything else.
+       g->m->g0->racectx = 0;
+
        // Max stack size is 1 GB on 64-bit, 250 MB on 32-bit.
        // Using decimal instead of binary GB and MB because
        // they look nicer in the stack overflow failure message.
@@ -1166,8 +1170,6 @@ newm(void(*fn)(void), P *p)
        mp = runtime·allocm(p);
        mp->nextp = p;
        mp->mstartfn = fn;
-       if(raceenabled)
-               mp->g0->racectx = runtime·racegostart(newm);
 
        if(runtime·iscgo) {
                CgoThreadStart ts;
index a773addb07c5f4ba04cfd93a21c50c5410d79fc8..d5e77c756809e9d144ba2450827960a0dc9f18b9 100644 (file)
@@ -153,6 +153,11 @@ runtime·racegoend(void)
 void
 runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc)
 {
+       if(g != g->m->curg) {
+               // The call is coming from manual instrumentation of Go code running on g0/gsignal.
+               // Not interesting.
+               return;
+       }
        if(callpc != nil)
                runtime·racefuncenter(callpc);
        runtime·racewriterangepc1(addr, sz, pc);
@@ -163,6 +168,11 @@ runtime·racewriterangepc(void *addr, uintptr sz, void *callpc, void *pc)
 void
 runtime·racereadrangepc(void *addr, uintptr sz, void *callpc, void *pc)
 {
+       if(g != g->m->curg) {
+               // The call is coming from manual instrumentation of Go code running on g0/gsignal.
+               // Not interesting.
+               return;
+       }
        if(callpc != nil)
                runtime·racefuncenter(callpc);
        runtime·racereadrangepc1(addr, sz, pc);