Skip to content

Commit 05dc6b2

Browse files
committed
runtime: improve diagnostics for "scan missed a g"
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/33339 Reviewed-by: Rick Hudson <[email protected]>
1 parent 7061dc3 commit 05dc6b2

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
@@ -126,26 +126,32 @@ func gcMarkRootCheck() {
126126

127127
lock(&allglock)
128128
// Check that stacks have been scanned.
129+
var gp *g
129130
if gcphase == _GCmarktermination && debug.gcrescanstacks > 0 {
130131
for i := 0; i < len(allgs); i++ {
131-
gp := allgs[i]
132+
gp = allgs[i]
132133
if !(gp.gcscandone && gp.gcscanvalid) && readgstatus(gp) != _Gdead {
133-
println("gp", gp, "goid", gp.goid,
134-
"status", readgstatus(gp),
135-
"gcscandone", gp.gcscandone,
136-
"gcscanvalid", gp.gcscanvalid)
137-
throw("scan missed a g")
134+
goto fail
138135
}
139136
}
140137
} else {
141138
for i := 0; i < work.nStackRoots; i++ {
142-
gp := allgs[i]
139+
gp = allgs[i]
143140
if !gp.gcscandone {
144-
throw("scan missed a g")
141+
goto fail
145142
}
146143
}
147144
}
148145
unlock(&allglock)
146+
return
147+
148+
fail:
149+
println("gp", gp, "goid", gp.goid,
150+
"status", readgstatus(gp),
151+
"gcscandone", gp.gcscandone,
152+
"gcscanvalid", gp.gcscanvalid)
153+
unlock(&allglock) // Avoid self-deadlock with traceback.
154+
throw("scan missed a g")
149155
}
150156

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

0 commit comments

Comments
 (0)