1
0
mirror of https://github.com/golang/go synced 2024-11-13 12:30:21 -07:00

runtime: use wb flag instead of gcphase for allocate-black check

This is an allocator microoptimization. There's no reason to check
gcphase in general, since it's mostly for debugging anyway.
writeBarrier.enabled is set in all the same cases here, and we force one
fewer cache line (probably) to be touched during malloc.

Conceptually, it also makes a bit more sense. The allocate-black policy
is partly informed by the write barrier design.

Change-Id: Ia5ff593d64c29cf7f4d1bced3204056566444a98
Reviewed-on: https://go-review.googlesource.com/c/go/+/617875
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Michael Anthony Knyszek 2024-10-03 18:18:11 +00:00 committed by Gopher Robot
parent 31437f25f2
commit d8997c8c1f

View File

@ -1224,7 +1224,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
// All slots hold nil so no scanning is needed.
// This may be racing with GC so do it atomically if there can be
// a race marking the bit.
if gcphase != _GCoff {
if writeBarrier.enabled {
gcmarknewobject(span, uintptr(x))
}