]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: have mergeInlineMarkBits also clear the inline mark bits
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 14 Jul 2025 19:23:12 +0000 (19:23 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 15 Jul 2025 19:24:28 +0000 (12:24 -0700)
This is conceptually simpler, as the sweeper doesn't have to worry about
clearing them separately. It also doesn't have a use for them.

This will also be useful to avoiding unnecessary zeroing in
initInlineMarkBits at allocation time. Currently, because it's used in
both span allocation and at sweep time, we cannot blindly trust
needzero.

This change also renames mergeInlineMarkBits to moveInlineMarkBits to
make this change in semantics clearer from the name.

For #73581.

Change-Id: Ib154738a945633b7ff5b2ae27235baa310400139
Reviewed-on: https://go-review.googlesource.com/c/go/+/687936
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/mgcmark_greenteagc.go
src/runtime/mgcmark_nogreenteagc.go
src/runtime/mgcsweep.go

index 3a368438d4b57745ff12f487a8612742808f3584..018f7df6ffefc3a0b2fe4985a5a5cfd8716a1a4e 100644 (file)
@@ -183,10 +183,10 @@ func (s *mspan) initInlineMarkBits() {
        s.inlineMarkBits().init(s.spanclass)
 }
 
-// mergeInlineMarks merges the span's inline mark bits into dst.
+// moveInlineMarks merges the span's inline mark bits into dst and clears them.
 //
 // gcUsesSpanInlineMarkBits(s.elemsize) must be true.
-func (s *mspan) mergeInlineMarks(dst *gcBits) {
+func (s *mspan) moveInlineMarks(dst *gcBits) {
        if doubleCheckGreenTea && !gcUsesSpanInlineMarkBits(s.elemsize) {
                throw("expected span with inline mark bits")
        }
@@ -203,6 +203,9 @@ func (s *mspan) mergeInlineMarks(dst *gcBits) {
        if doubleCheckGreenTea && !s.spanclass.noscan() && imb.marks != imb.scans {
                throw("marks don't match scans for span with pointer")
        }
+
+       // Reset the inline mark bits.
+       imb.init(s.spanclass)
 }
 
 // inlineMarkBits returns the inline mark bits for the span.
index c0ca5c21ea83f63057fb5c76738c97345c518540..6e4f0c4f7255b2b13d5ca243a87ad6cbbb922379 100644 (file)
@@ -24,7 +24,7 @@ func tryDeferToSpanScan(p uintptr, gcw *gcWork) bool {
 func (s *mspan) initInlineMarkBits() {
 }
 
-func (s *mspan) mergeInlineMarks(to *gcBits) {
+func (s *mspan) moveInlineMarks(to *gcBits) {
        throw("unimplemented")
 }
 
index a3bf2989dfbb2327a4fb04a9885d6a7633a17fd3..1605c21966ce1541b35bb2114659f0e905f1444e 100644 (file)
@@ -650,9 +650,9 @@ func (sl *sweepLocked) sweep(preserve bool) bool {
                }
        }
 
-       // Copy over the inline mark bits if necessary.
+       // Copy over and clear the inline mark bits if necessary.
        if gcUsesSpanInlineMarkBits(s.elemsize) {
-               s.mergeInlineMarks(s.gcmarkBits)
+               s.moveInlineMarks(s.gcmarkBits)
        }
 
        // Check for zombie objects.
@@ -704,11 +704,6 @@ func (sl *sweepLocked) sweep(preserve bool) bool {
        // Initialize alloc bits cache.
        s.refillAllocCache(0)
 
-       // Reset the object queue, if we have one.
-       if gcUsesSpanInlineMarkBits(s.elemsize) {
-               s.initInlineMarkBits()
-       }
-
        // The span must be in our exclusive ownership until we update sweepgen,
        // check for potential races.
        if state := s.state.get(); state != mSpanInUse || s.sweepgen != sweepgen-1 {