From ff4e45fbc2ab7980087c0ae882a36803f6bc248f Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 24 Jan 2024 02:54:56 +0000 Subject: [PATCH] cmd/compile/internal/reflectdata,reflect: merge MaxPtrmaskBytes const into internal/abi 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 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- .../compile/internal/reflectdata/reflect.go | 35 +------------------ src/internal/abi/type.go | 31 ++++++++++++++++ src/reflect/type.go | 5 +-- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index fd64b2ebfe..185be4dd51 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -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 } diff --git a/src/internal/abi/type.go b/src/internal/abi/type.go index 0b9ad934d2..bf48fede2d 100644 --- a/src/internal/abi/type.go +++ b/src/internal/abi/type.go @@ -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 diff --git a/src/reflect/type.go b/src/reflect/type.go index 9a2e41f0b2..55d339fa39 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -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. -- 2.48.1