@@ -17,55 +17,41 @@ const (
17
17
//
18
18
// See heapAddrBits for a table of address space sizes on
19
19
// various architectures. 48 bits is enough for all
20
- // architectures except s390x.
20
+ // arch/os combos except s390x, aix, and riscv64 .
21
21
//
22
- // On AMD64, virtual addresses are 48-bit (or 57-bit) numbers sign extended to 64.
23
- // We shift the address left 16 to eliminate the sign extended part and make
24
- // room in the bottom for the count.
22
+ // On AMD64, virtual addresses are 48-bit (or 57-bit) sign-extended.
23
+ // Other archs are 48-bit zero-extended.
25
24
//
26
25
// On s390x, virtual addresses are 64-bit. There's not much we
27
26
// can do about this, so we just hope that the kernel doesn't
28
27
// get to really high addresses and panic if it does.
29
- addrBits = 48
30
-
31
- // In addition to the 16 bits taken from the top, we can take 9 from the
32
- // bottom, because we require pointers to be well-aligned (see tagptr.go:tagAlignBits).
33
- // That gives us a total of 25 bits for the tag.
34
- tagBits = 64 - addrBits + tagAlignBits
28
+ defaultAddrBits = 48
35
29
36
30
// On AIX, 64-bit addresses are split into 36-bit segment number and 28-bit
37
31
// offset in segment. Segment numbers in the range 0x0A0000000-0x0AFFFFFFF(LSA)
38
32
// are available for mmap.
39
33
// We assume all tagged addresses are from memory allocated with mmap.
40
34
// We use one bit to distinguish between the two ranges.
41
35
aixAddrBits = 57
42
- aixTagBits = 64 - aixAddrBits + tagAlignBits
43
36
44
37
// riscv64 SV57 mode gives 56 bits of userspace VA.
45
38
// tagged pointer code supports it,
46
39
// but broader support for SV57 mode is incomplete,
47
40
// and there may be other issues (see #54104).
48
41
riscv64AddrBits = 56
49
- riscv64TagBits = 64 - riscv64AddrBits + tagAlignBits
50
- )
51
42
52
- // The number of bits stored in the numeric tag of a taggedPointer
53
- const taggedPointerBits = (goos .IsAix * aixTagBits ) + (goarch .IsRiscv64 * riscv64TagBits ) + ((1 - goos .IsAix ) * (1 - goarch .IsRiscv64 ) * tagBits )
43
+ addrBits = goos .IsAix * aixAddrBits + goarch .IsRiscv64 * riscv64AddrBits + (1 - goos .IsAix )* (1 - goarch .IsRiscv64 )* defaultAddrBits
44
+
45
+ // In addition to the 16 bits (or other, depending on arch/os) taken from the top,
46
+ // we can take 9 from the bottom, because we require pointers to be well-aligned
47
+ // (see tagptr.go:tagAlignBits). That gives us a total of 25 bits for the tag.
48
+ tagBits = 64 - addrBits + tagAlignBits
49
+ )
54
50
55
51
// taggedPointerPack created a taggedPointer from a pointer and a tag.
56
52
// Tag bits that don't fit in the result are discarded.
57
53
func taggedPointerPack (ptr unsafe.Pointer , tag uintptr ) taggedPointer {
58
- var t taggedPointer
59
- if GOOS == "aix" {
60
- if GOARCH != "ppc64" {
61
- throw ("check this code for aix on non-ppc64" )
62
- }
63
- t = taggedPointer (uint64 (uintptr (ptr ))<< (64 - aixAddrBits ) | uint64 (tag & (1 << aixTagBits - 1 )))
64
- } else if GOARCH == "riscv64" {
65
- t = taggedPointer (uint64 (uintptr (ptr ))<< (64 - riscv64AddrBits ) | uint64 (tag & (1 << riscv64TagBits - 1 )))
66
- } else {
67
- t = taggedPointer (uint64 (uintptr (ptr ))<< (64 - addrBits ) | uint64 (tag & (1 << tagBits - 1 )))
68
- }
54
+ t := taggedPointer (uint64 (uintptr (ptr ))<< (tagBits - tagAlignBits ) | uint64 (tag & (1 << tagBits - 1 )))
69
55
if t .pointer () != ptr || t .tag () != tag {
70
56
print ("runtime: taggedPointerPack invalid packing: ptr=" , ptr , " tag=" , hex (tag ), " packed=" , hex (t ), " -> ptr=" , t .pointer (), " tag=" , hex (t .tag ()), "\n " )
71
57
throw ("taggedPointerPack" )
@@ -80,16 +66,10 @@ func (tp taggedPointer) pointer() unsafe.Pointer {
80
66
// val before unpacking.
81
67
return unsafe .Pointer (uintptr (int64 (tp ) >> tagBits << tagAlignBits ))
82
68
}
83
- if GOOS == "aix" {
84
- return unsafe .Pointer (uintptr ((tp >> aixTagBits << tagAlignBits ) | 0xa << 56 ))
85
- }
86
- if GOARCH == "riscv64" {
87
- return unsafe .Pointer (uintptr (tp >> riscv64TagBits << tagAlignBits ))
88
- }
89
69
return unsafe .Pointer (uintptr (tp >> tagBits << tagAlignBits ))
90
70
}
91
71
92
72
// Tag returns the tag from a taggedPointer.
93
73
func (tp taggedPointer ) tag () uintptr {
94
- return uintptr (tp & (1 << taggedPointerBits - 1 ))
74
+ return uintptr (tp & (1 << tagBits - 1 ))
95
75
}
0 commit comments