Skip to content

Commit b800f20

Browse files
committed
runtime: document assumption about wbBufFlush argument slots
gcWriteBarrier and wbBufFlush assume that not writing to an argument variable is sufficient to not clobber the corresponding argument slot. This assumption lets us simplify the write barrier assembly code, speed up the flush path, and reduce the stack usage of the write barrier. But it is an assumption, so this CL documents it to make this clear. Alternatively, we could separate the register spill slots from the argument slots in the write barrier, but that loses the advantages above. On the other hand, it's extremely unlikely that we'll change the behavior of the compiler to start clobbering argument slots (if anything, we'd probably change it to *not* clobber argument slots even if you wrote to the arguments). Fixes #25512. Change-Id: Ib2cf29c0d90956ca02b997ef6e7fa56fc8044efe Reviewed-on: https://go-review.googlesource.com/127815 Reviewed-by: Cherry Zhang <[email protected]>
1 parent 1b87007 commit b800f20

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/runtime/mwbbuf.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ func wbBufFlush(dst *uintptr, src uintptr) {
163163
// Note: Every possible return from this function must reset
164164
// the buffer's next pointer to prevent buffer overflow.
165165

166+
// This *must not* modify its arguments because this
167+
// function's argument slots do double duty in gcWriteBarrier
168+
// as register spill slots. Currently, not modifying the
169+
// arguments is sufficient to keep the spill slots unmodified
170+
// (which seems unlikely to change since it costs little and
171+
// helps with debugging).
172+
166173
if getg().m.dying > 0 {
167174
// We're going down. Not much point in write barriers
168175
// and this way we can allow write barriers in the

0 commit comments

Comments
 (0)