Skip to content

Commit 9bcca97

Browse files
niaowdeadprogram
authored andcommitted
internal/gclayout: use correct lengths
The GC bitmap length is measured in multiples of the pointer alignment. This is equal to the pointer size on all architectures except AVR. Replace the hardcoded lengths with lengths that are computed naturally.
1 parent a40586d commit 9bcca97

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/internal/gclayout/gclayout.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ const (
1313
// 64-bit int => bits = 6
1414
sizeBits = 4 + unsafe.Sizeof(uintptr(0))/4
1515

16+
ptrAlign = unsafe.Alignof(uintptr(0))
17+
1618
sizeShift = sizeBits + 1
1719

18-
NoPtrs = Layout(uintptr(0b0<<sizeShift) | uintptr(0b1<<1) | uintptr(1))
19-
Pointer = Layout(uintptr(0b1<<sizeShift) | uintptr(0b1<<1) | uintptr(1))
20-
String = Layout(uintptr(0b01<<sizeShift) | uintptr(0b10<<1) | uintptr(1))
21-
Slice = Layout(uintptr(0b001<<sizeShift) | uintptr(0b11<<1) | uintptr(1))
20+
NoPtrs = Layout((0 << sizeShift) | (1 << 1) | 1)
21+
Pointer = Layout((1 << sizeShift) | ((unsafe.Sizeof(unsafe.Pointer(nil)) / ptrAlign) << 1) | 1)
22+
String = Layout((1 << sizeShift) | ((unsafe.Sizeof("") / ptrAlign) << 1) | 1)
23+
Slice = Layout((1 << sizeShift) | ((unsafe.Sizeof([]byte{}) / ptrAlign) << 1) | 1)
2224
)
2325

2426
func (l Layout) AsPtr() unsafe.Pointer { return unsafe.Pointer(l) }

0 commit comments

Comments
 (0)