Skip to content

Commit 70e9806

Browse files
aclementsbradfitz
authored andcommitted
[release-branch.go1.7] runtime: improve diagnostics for "scan missed a g"
Updates #18700 (backport) Currently there are no diagnostics for mark root check during marking. Fix this by printing out the same diagnostics we print during mark termination. Also, drop the allglock before throwing. Holding that across a throw causes a self-deadlock with tracebackothers. For #16083. Change-Id: Ib605f3ae0c17e70704b31d8378274cfaa2307dc2 Reviewed-on: https://go-review.googlesource.com/35677 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 230a376 commit 70e9806

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/runtime/mgcmark.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,32 @@ func gcMarkRootCheck() {
106106

107107
lock(&allglock)
108108
// Check that stacks have been scanned.
109+
var gp *g
109110
if gcphase == _GCmarktermination {
110111
for i := 0; i < len(allgs); i++ {
111-
gp := allgs[i]
112+
gp = allgs[i]
112113
if !(gp.gcscandone && gp.gcscanvalid) && readgstatus(gp) != _Gdead {
113-
println("gp", gp, "goid", gp.goid,
114-
"status", readgstatus(gp),
115-
"gcscandone", gp.gcscandone,
116-
"gcscanvalid", gp.gcscanvalid)
117-
throw("scan missed a g")
114+
goto fail
118115
}
119116
}
120117
} else {
121118
for i := 0; i < work.nStackRoots; i++ {
122-
gp := allgs[i]
119+
gp = allgs[i]
123120
if !gp.gcscandone {
124-
throw("scan missed a g")
121+
goto fail
125122
}
126123
}
127124
}
128125
unlock(&allglock)
126+
return
127+
128+
fail:
129+
println("gp", gp, "goid", gp.goid,
130+
"status", readgstatus(gp),
131+
"gcscandone", gp.gcscandone,
132+
"gcscanvalid", gp.gcscanvalid)
133+
unlock(&allglock) // Avoid self-deadlock with traceback.
134+
throw("scan missed a g")
129135
}
130136

131137
// ptrmask for an allocation containing a single pointer.

0 commit comments

Comments
 (0)