1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // A profMap is a map from (stack, tag) to mapEntry.
10 // It grows without bound, but that's assumed to be OK.
12 hash
map[uintptr]*profMapEntry
19 // A profMapEntry is a single entry in the profMap.
20 type profMapEntry
struct {
21 nextHash
*profMapEntry
// next in hash list
22 nextAll
*profMapEntry
// next in list of all entries
28 func (m
*profMap
) lookup(stk
[]uint64, tag unsafe
.Pointer
) *profMapEntry
{
29 // Compute hash of (stk, tag).
31 for _
, x
:= range stk
{
32 h
= h
<<8 |
(h
>> (8 * (unsafe
.Sizeof(h
) - 1)))
35 h
= h
<<8 |
(h
>> (8 * (unsafe
.Sizeof(h
) - 1)))
36 h
+= uintptr(tag
) * 41
38 // Find entry if present.
39 var last
*profMapEntry
41 for e
:= m
.hash
[h
]; e
!= nil; last
, e
= e
, e
.nextHash
{
42 if len(e
.stk
) != len(stk
) || e
.tag
!= tag
{
46 if e
.stk
[j
] != uintptr(stk
[j
]) {
52 last
.nextHash
= e
.nextHash
53 e
.nextHash
= m
.hash
[h
]
61 m
.free
= make([]profMapEntry
, 128)
65 e
.nextHash
= m
.hash
[h
]
68 if len(m
.freeStk
) < len(stk
) {
69 m
.freeStk
= make([]uintptr, 1024)
71 e
.stk
= m
.freeStk
[:len(stk
)]
72 m
.freeStk
= m
.freeStk
[len(stk
):]
75 e
.stk
[j
] = uintptr(stk
[j
])
78 m
.hash
= make(map[uintptr]*profMapEntry
)