]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/reflectdata,reflect: merge MaxPtrmaskBytes const into internal/abi
authorqiulaidongfeng <2645477756@qq.com>
Wed, 24 Jan 2024 02:54:56 +0000 (02:54 +0000)
committerCherry Mui <cherryyz@google.com>
Tue, 20 Feb 2024 16:10:05 +0000 (16:10 +0000)
For #59670

Change-Id: I5c0a463f54208db215683f11e6454d0178edda3c
GitHub-Last-Rev: 6963f3c8fb9cf34cdc8dda7ee92a58c71ca65520
GitHub-Pull-Request: golang/go#64904
Reviewed-on: https://go-review.googlesource.com/c/go/+/553275
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/reflectdata/reflect.go
src/internal/abi/type.go
src/reflect/type.go

index fd64b2ebfe3679ba126bca99bb2189246db24e9d..185be4dd514e8e936f6c7647c0c7a8afd7a49595 100644 (file)
@@ -1498,39 +1498,6 @@ func (a typesByString) Less(i, j int) bool {
 }
 func (a typesByString) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
 
-// maxPtrmaskBytes is the maximum length of a GC ptrmask bitmap,
-// which holds 1-bit entries describing where pointers are in a given type.
-// Above this length, the GC information is recorded as a GC program,
-// which can express repetition compactly. In either form, the
-// information is used by the runtime to initialize the heap bitmap,
-// and for large types (like 128 or more words), they are roughly the
-// same speed. GC programs are never much larger and often more
-// compact. (If large arrays are involved, they can be arbitrarily
-// more compact.)
-//
-// The cutoff must be large enough that any allocation large enough to
-// use a GC program is large enough that it does not share heap bitmap
-// bytes with any other objects, allowing the GC program execution to
-// assume an aligned start and not use atomic operations. In the current
-// runtime, this means all malloc size classes larger than the cutoff must
-// be multiples of four words. On 32-bit systems that's 16 bytes, and
-// all size classes >= 16 bytes are 16-byte aligned, so no real constraint.
-// On 64-bit systems, that's 32 bytes, and 32-byte alignment is guaranteed
-// for size classes >= 256 bytes. On a 64-bit system, 256 bytes allocated
-// is 32 pointers, the bits for which fit in 4 bytes. So maxPtrmaskBytes
-// must be >= 4.
-//
-// We used to use 16 because the GC programs do have some constant overhead
-// to get started, and processing 128 pointers seems to be enough to
-// amortize that overhead well.
-//
-// To make sure that the runtime's chansend can call typeBitsBulkBarrier,
-// we raised the limit to 2048, so that even 32-bit systems are guaranteed to
-// use bitmaps for objects up to 64 kB in size.
-//
-// Also known to reflect/type.go.
-const maxPtrmaskBytes = 2048
-
 // GCSym returns a data symbol containing GC information for type t, along
 // with a boolean reporting whether the UseGCProg bit should be set in the
 // type kind, and the ptrdata field to record in the reflect type information.
@@ -1553,7 +1520,7 @@ func GCSym(t *types.Type) (lsym *obj.LSym, useGCProg bool, ptrdata int64) {
 // When write is true, it writes the symbol data.
 func dgcsym(t *types.Type, write bool) (lsym *obj.LSym, useGCProg bool, ptrdata int64) {
        ptrdata = types.PtrDataSize(t)
-       if ptrdata/int64(types.PtrSize) <= maxPtrmaskBytes*8 {
+       if ptrdata/int64(types.PtrSize) <= abi.MaxPtrmaskBytes*8 {
                lsym = dgcptrmask(t, write)
                return
        }
index 0b9ad934d281a5f2748cc6664ddd82010e875f5a..bf48fede2d55efcd8913afd023233a21d39f587e 100644 (file)
@@ -749,3 +749,34 @@ const (
        TraceArgsOffsetTooLarge = 0xfb
        TraceArgsSpecial        = 0xf0 // above this are operators, below this are ordinary offsets
 )
+
+// MaxPtrmaskBytes is the maximum length of a GC ptrmask bitmap,
+// which holds 1-bit entries describing where pointers are in a given type.
+// Above this length, the GC information is recorded as a GC program,
+// which can express repetition compactly. In either form, the
+// information is used by the runtime to initialize the heap bitmap,
+// and for large types (like 128 or more words), they are roughly the
+// same speed. GC programs are never much larger and often more
+// compact. (If large arrays are involved, they can be arbitrarily
+// more compact.)
+//
+// The cutoff must be large enough that any allocation large enough to
+// use a GC program is large enough that it does not share heap bitmap
+// bytes with any other objects, allowing the GC program execution to
+// assume an aligned start and not use atomic operations. In the current
+// runtime, this means all malloc size classes larger than the cutoff must
+// be multiples of four words. On 32-bit systems that's 16 bytes, and
+// all size classes >= 16 bytes are 16-byte aligned, so no real constraint.
+// On 64-bit systems, that's 32 bytes, and 32-byte alignment is guaranteed
+// for size classes >= 256 bytes. On a 64-bit system, 256 bytes allocated
+// is 32 pointers, the bits for which fit in 4 bytes. So MaxPtrmaskBytes
+// must be >= 4.
+//
+// We used to use 16 because the GC programs do have some constant overhead
+// to get started, and processing 128 pointers seems to be enough to
+// amortize that overhead well.
+//
+// To make sure that the runtime's chansend can call typeBitsBulkBarrier,
+// we raised the limit to 2048, so that even 32-bit systems are guaranteed to
+// use bitmaps for objects up to 64 kB in size.
+const MaxPtrmaskBytes = 2048
index 9a2e41f0b24e1ea4501c38e99fd106d1aa2c682c..55d339fa39d9b10fda0b2acccf65cf6b0d69477b 100644 (file)
@@ -2621,9 +2621,6 @@ func typeptrdata(t *abi.Type) uintptr {
        }
 }
 
-// See cmd/compile/internal/reflectdata/reflect.go for derivation of constant.
-const maxPtrmaskBytes = 2048
-
 // ArrayOf returns the array type with the given length and element type.
 // For example, if t represents int, ArrayOf(5, t) represents [5]int.
 //
@@ -2692,7 +2689,7 @@ func ArrayOf(length int, elem Type) Type {
                array.GCData = typ.GCData
                array.PtrBytes = typ.PtrBytes
 
-       case typ.Kind_&kindGCProg == 0 && array.Size_ <= maxPtrmaskBytes*8*goarch.PtrSize:
+       case typ.Kind_&kindGCProg == 0 && array.Size_ <= abi.MaxPtrmaskBytes*8*goarch.PtrSize:
                // Element is small with pointer mask; array is still small.
                // Create direct pointer mask by turning each 1 bit in elem
                // into length 1 bits in larger mask.