2017-03-02 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / runtime / mcache.go
blobb65dd37421dec78ca2ce6dcf65095eb262081d1f
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 package runtime
7 // This is a temporary mcache.go for gccgo.
8 // At some point it will be replaced by the one in the gc runtime package.
10 import "unsafe"
12 type mcachelist struct {
13 list *mlink
14 nlist uint32
17 // Per-thread (in Go, per-P) cache for small objects.
18 // No locking needed because it is per-thread (per-P).
20 // mcaches are allocated from non-GC'd memory, so any heap pointers
21 // must be specially handled.
23 //go:notinheap
24 type mcache struct {
25 // The following members are accessed on every malloc,
26 // so they are grouped here for better caching.
27 next_sample int32 // trigger heap sample after allocating this many bytes
28 local_cachealloc uintptr // bytes allocated (or freed) from cache since last lock of heap
30 // Allocator cache for tiny objects w/o pointers.
31 // See "Tiny allocator" comment in malloc.go.
33 // tiny points to the beginning of the current tiny block, or
34 // nil if there is no current tiny block.
36 // tiny is a heap pointer. Since mcache is in non-GC'd memory,
37 // we handle it by clearing it in releaseAll during mark
38 // termination.
39 tiny unsafe.Pointer
40 tinysize uintptr
42 // The rest is not accessed on every malloc.
43 alloc [_NumSizeClasses]*mspan // spans to allocate from
44 free [_NumSizeClasses]mcachelist // lists of explicitly freed objects
46 // Local allocator stats, flushed during GC.
47 local_nlookup uintptr // number of pointer lookups
48 local_largefree uintptr // bytes freed for large objects (>maxsmallsize)
49 local_nlargefree uintptr // number of frees for large objects (>maxsmallsize)
50 local_nsmallfree [_NumSizeClasses]uintptr // number of frees for small objects (<=maxsmallsize)
53 type mtypes struct {
54 compression byte
55 data uintptr
58 type special struct {
59 next *special
60 offset uint16
61 kind byte
64 type mspan struct {
65 next *mspan // next span in list, or nil if none
66 prev *mspan // previous span's next field, or list head's first field if none
67 start uintptr
68 npages uintptr // number of pages in span
69 freelist *mlink
71 // sweep generation:
72 // if sweepgen == h->sweepgen - 2, the span needs sweeping
73 // if sweepgen == h->sweepgen - 1, the span is currently being swept
74 // if sweepgen == h->sweepgen, the span is swept and ready to use
75 // h->sweepgen is incremented by 2 after every GC
77 sweepgen uint32
78 ref uint16
79 sizeclass uint8 // size class
80 incache bool // being used by an mcache
81 state uint8 // mspaninuse etc
82 needzero uint8 // needs to be zeroed before allocation
83 elemsize uintptr // computed from sizeclass or from npages
84 unusedsince int64 // first time spotted by gc in mspanfree state
85 npreleased uintptr // number of pages released to the os
86 limit uintptr // end of data in span
87 types mtypes
88 speciallock mutex // guards specials list
89 specials *special // linked list of special records sorted by offset.
90 freebuf *mlink
93 type mlink struct {
94 next *mlink