]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: minor mfinal.go code cleanup
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 18 Feb 2025 22:32:00 +0000 (22:32 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 19 Feb 2025 22:25:03 +0000 (14:25 -0800)
This change moves finBlockSize into mfinal.go and renames finblock to
finBlock.

Change-Id: I20a0bc3907e7b028a2caa5d2fe8cf3f76332c871
Reviewed-on: https://go-review.googlesource.com/c/go/+/650695
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/runtime/mfinal.go
src/runtime/mgc.go

index 4962a63a4146cec6442b217ce1273c0f2439f85a..05d26e6cd6619c608c9f189ae620a96d594981da 100644 (file)
@@ -14,19 +14,21 @@ import (
        "unsafe"
 )
 
-// finblock is an array of finalizers to be executed. finblocks are
-// arranged in a linked list for the finalizer queue.
+const finBlockSize = 4 * 1024
+
+// finBlock is an block of finalizers/cleanups to be executed. finBlocks
+// are arranged in a linked list for the finalizer queue.
 //
-// finblock is allocated from non-GC'd memory, so any heap pointers
+// finBlock is allocated from non-GC'd memory, so any heap pointers
 // must be specially handled. GC currently assumes that the finalizer
 // queue does not grow during marking (but it can shrink).
-type finblock struct {
+type finBlock struct {
        _       sys.NotInHeap
-       alllink *finblock
-       next    *finblock
+       alllink *finBlock
+       next    *finBlock
        cnt     uint32
        _       int32
-       fin     [(_FinBlockSize - 2*goarch.PtrSize - 2*4) / unsafe.Sizeof(finalizer{})]finalizer
+       fin     [(finBlockSize - 2*goarch.PtrSize - 2*4) / unsafe.Sizeof(finalizer{})]finalizer
 }
 
 var fingStatus atomic.Uint32
@@ -40,16 +42,15 @@ const (
        fingWake
 )
 
-// This runs durring the GC sweep phase. Heap memory can't be allocated while sweep is running.
 var (
        finlock    mutex     // protects the following variables
        fing       *g        // goroutine that runs finalizers
-       finq       *finblock // list of finalizers that are to be executed
-       finc       *finblock // cache of free blocks
-       finptrmask [_FinBlockSize / goarch.PtrSize / 8]byte
+       finq       *finBlock // list of finalizers that are to be executed
+       finc       *finBlock // cache of free blocks
+       finptrmask [finBlockSize / goarch.PtrSize / 8]byte
 )
 
-var allfin *finblock // list of all blocks
+var allfin *finBlock // list of all blocks
 
 // NOTE: Layout known to queuefinalizer.
 type finalizer struct {
@@ -108,7 +109,7 @@ func queuefinalizer(p unsafe.Pointer, fn *funcval, nret uintptr, fint *_type, ot
        lock(&finlock)
        if finq == nil || finq.cnt == uint32(len(finq.fin)) {
                if finc == nil {
-                       finc = (*finblock)(persistentalloc(_FinBlockSize, 0, &memstats.gcMiscSys))
+                       finc = (*finBlock)(persistentalloc(finBlockSize, 0, &memstats.gcMiscSys))
                        finc.alllink = allfin
                        allfin = finc
                        if finptrmask[0] == 0 {
index d10f3c09cf1da085ff11cac3099e940c439606cf..25345abca9fd00e18b5d5aea2c1785bc0b6b5e57 100644 (file)
@@ -135,8 +135,7 @@ import (
 )
 
 const (
-       _DebugGC      = 0
-       _FinBlockSize = 4 * 1024
+       _DebugGC = 0
 
        // concurrentSweep is a debug flag. Disabling this flag
        // ensures all spans are swept while the world is stopped.