diff options
author | Russ Cox <rsc@golang.org> | 2014-12-22 10:53:51 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2015-01-06 00:26:35 +0000 |
commit | dcec123a4923437242c52d2693ace80d2f3c704e (patch) | |
tree | 9f1d6a2a5bcf75e86e84a657a7aca5b522947ab5 /src/runtime/panic.go | |
parent | 3191a235158233bb6f6d960d7ae0cb925606f817 (diff) | |
download | go-git-dcec123a4923437242c52d2693ace80d2f3c704e.tar.gz |
runtime: add GODEBUG wbshadow for finding missing write barriers
This is the detection code. It works well enough that I know of
a handful of missing write barriers. However, those are subtle
enough that I'll address them in separate followup CLs.
GODEBUG=wbshadow=1 checks for a write that bypassed the
write barrier at the next write barrier of the same word.
If a bug can be detected in this mode it is typically easy to
understand, since the crash says quite clearly what kind of
word has missed a write barrier.
GODEBUG=wbshadow=2 adds a check of the write barrier
shadow copy during garbage collection. Bugs detected at
garbage collection can be difficult to understand, because
there is no context for what the found word means.
Typically you have to reproduce the problem with allocfreetrace=1
in order to understand the type of the badly updated word.
Change-Id: If863837308e7c50d96b5bdc7d65af4969bf53a6e
Reviewed-on: https://go-review.googlesource.com/2061
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/panic.go')
-rw-r--r-- | src/runtime/panic.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go index 2e3ed3f5e8..393c7695c7 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -177,6 +177,16 @@ func newdefer(siz int32) *_defer { d = (*_defer)(mallocgc(total, deferType, 0)) } d.siz = siz + if mheap_.shadow_enabled { + // This memory will be written directly, with no write barrier, + // and then scanned like stacks during collection. + // Unlike real stacks, it is from heap spans, so mark the + // shadow as explicitly unusable. + p := deferArgs(d) + for i := uintptr(0); i+ptrSize <= uintptr(siz); i += ptrSize { + writebarrierptr_noshadow((*uintptr)(add(p, i))) + } + } gp := mp.curg d.link = gp._defer gp._defer = d @@ -194,6 +204,12 @@ func freedefer(d *_defer) { if d.fn != nil { freedeferfn() } + if mheap_.shadow_enabled { + // Undo the marking in newdefer. + systemstack(func() { + clearshadow(uintptr(deferArgs(d)), uintptr(d.siz)) + }) + } sc := deferclass(uintptr(d.siz)) if sc < uintptr(len(p{}.deferpool)) { mp := acquirem() |