]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use wb flag instead of gcphase for allocate-black check
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 3 Oct 2024 18:18:11 +0000 (18:18 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 21 Oct 2024 15:46:44 +0000 (15:46 +0000)
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>
src/runtime/malloc.go

index 4fda8a3c233710151064dab0c71a49e3457d066c..d376a4a26a52360165024e7be0395ce3c089c1e9 100644 (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))
        }