1 // Copyright 2009 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.
5 // Heap map, 32-bit version
6 // See malloc.h and mheap.c for overview.
11 #if __SIZEOF_POINTER__ == 4
13 // 3-level radix tree mapping page ids to Span*.
15 runtime_MHeapMap_Init(MHeapMap *m, void *(*allocator)(uintptr))
17 m->allocator = allocator;
21 runtime_MHeapMap_Get(MHeapMap *m, PageID k)
25 i2 = k & MHeapMap_Level2Mask;
26 k >>= MHeapMap_Level2Bits;
27 i1 = k & MHeapMap_Level1Mask;
28 k >>= MHeapMap_Level1Bits;
30 runtime_throw("MHeapMap_Get");
32 return m->p[i1]->s[i2];
36 runtime_MHeapMap_GetMaybe(MHeapMap *m, PageID k)
41 i2 = k & MHeapMap_Level2Mask;
42 k >>= MHeapMap_Level2Bits;
43 i1 = k & MHeapMap_Level1Mask;
44 k >>= MHeapMap_Level1Bits;
46 runtime_throw("MHeapMap_Get");
55 runtime_MHeapMap_Set(MHeapMap *m, PageID k, MSpan *s)
59 i2 = k & MHeapMap_Level2Mask;
60 k >>= MHeapMap_Level2Bits;
61 i1 = k & MHeapMap_Level1Mask;
62 k >>= MHeapMap_Level1Bits;
64 runtime_throw("MHeapMap_Set");
69 // Allocate the storage required for entries [k, k+1, ..., k+len-1]
70 // so that Get and Set calls need not check for nil pointers.
72 runtime_MHeapMap_Preallocate(MHeapMap *m, PageID k, uintptr len)
80 if((k >> MHeapMap_TotalBits) != 0)
82 i1 = (k >> MHeapMap_Level2Bits) & MHeapMap_Level1Mask;
84 // first-level pointer
86 p2 = m->allocator(sizeof *p2);
89 mstats.heapmap_sys += sizeof *p2;
93 // advance key past this leaf node
94 k = ((k >> MHeapMap_Level2Bits) + 1) << MHeapMap_Level2Bits;
99 #endif /* __SIZEOF_POINTER__ == 4 */