...
Source file
src/runtime/trace2region.go
Documentation: runtime
1
2
3
4
5
6
7
8
9 package runtime
10
11 import (
12 "internal/goarch"
13 "runtime/internal/sys"
14 "unsafe"
15 )
16
17
18
19 type traceRegionAlloc struct {
20 head *traceRegionAllocBlock
21 off uintptr
22 }
23
24
25
26
27
28
29 type traceRegionAllocBlock struct {
30 _ sys.NotInHeap
31 next *traceRegionAllocBlock
32 data [64<<10 - goarch.PtrSize]byte
33 }
34
35
36 func (a *traceRegionAlloc) alloc(n uintptr) *notInHeap {
37 n = alignUp(n, goarch.PtrSize)
38 if a.head == nil || a.off+n > uintptr(len(a.head.data)) {
39 if n > uintptr(len(a.head.data)) {
40 throw("traceRegion: alloc too large")
41 }
42 block := (*traceRegionAllocBlock)(sysAlloc(unsafe.Sizeof(traceRegionAllocBlock{}), &memstats.other_sys))
43 if block == nil {
44 throw("traceRegion: out of memory")
45 }
46 block.next = a.head
47 a.head = block
48 a.off = 0
49 }
50 p := &a.head.data[a.off]
51 a.off += n
52 return (*notInHeap)(unsafe.Pointer(p))
53 }
54
55
56 func (a *traceRegionAlloc) drop() {
57 for a.head != nil {
58 block := a.head
59 a.head = block.next
60 sysFree(unsafe.Pointer(block), unsafe.Sizeof(traceRegionAllocBlock{}), &memstats.other_sys)
61 }
62 }
63
View as plain text