mirror of
https://github.com/golang/go
synced 2024-11-17 00:14:50 -07:00
cmd/compile/internal/reflectdata,reflect: merge MaxPtrmaskBytes const into internal/abi
For #59670
This commit is contained in:
parent
b3acaa8230
commit
6963f3c8fb
@ -1493,39 +1493,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.
|
||||
@ -1548,7 +1515,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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -2627,9 +2627,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.
|
||||
//
|
||||
@ -2698,7 +2695,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.
|
||||
|
Loading…
Reference in New Issue
Block a user