/home/travis/build/MoarVM/MoarVM/src/gc/gen2.h
Line | Count | Source |
1 | | /* Represents the objects for a particular size class. */ |
2 | | struct MVMGen2SizeClass { |
3 | | /* Each page holds a certain number of collectables. We know |
4 | | * nothing of the size statically, so we'll work in bytes. */ |
5 | | char **pages; |
6 | | |
7 | | /* Head of the free list. */ |
8 | | char **free_list; |
9 | | |
10 | | /* The current allocation position if we've nothing on the |
11 | | * free list. */ |
12 | | char *alloc_pos; |
13 | | |
14 | | /* The current page allocation limit (once we hit this, we need |
15 | | * to go to the next page) Also just used when no free list. */ |
16 | | char *alloc_limit; |
17 | | |
18 | | /* The current page number that we're allocating in. */ |
19 | | MVMuint32 cur_page; |
20 | | |
21 | | /* The number of pages allocated. */ |
22 | | MVMuint32 num_pages; |
23 | | }; |
24 | | |
25 | | /* An "instance" of the fixed size allocator. */ |
26 | | struct MVMGen2Allocator { |
27 | | /* Size classes for the fixed size allocator. Each one represents |
28 | | * a bunch of objects of the same size. The allocated sizes are |
29 | | * rounded and then one of these buckets is used, unless it is |
30 | | * past the limit. */ |
31 | | MVMGen2SizeClass *size_classes; |
32 | | |
33 | | /* Array of objects that were malloc'd instead, because they did |
34 | | * not fit in a size class due to being too large. */ |
35 | | MVMCollectable **overflows; |
36 | | |
37 | | /* The number of objects in the overflow array. */ |
38 | | MVMuint32 num_overflows; |
39 | | |
40 | | /* The amount of space allocated in the overflow array. */ |
41 | | MVMuint32 alloc_overflows; |
42 | | }; |
43 | | |
44 | | /* The number of bits we discard from the requested size when binning |
45 | | * the allocation request into a size class. For example, if this is |
46 | | * 3 bits then: |
47 | | * Request for 2 bytes ==> bin 0 (objects 0 - 8 bytes) |
48 | | * Request for 4 bytes ==> bin 0 (objects 0 - 8 bytes) |
49 | | * Request for 8 bytes ==> bin 0 (objects 0 - 8 bytes) |
50 | | * Request for 12 bytes ==> bin 1 (objects 9 - 16 bytes) |
51 | | * Request for 16 bytes ==> bin 1 (objects 9 - 16 bytes) |
52 | | */ |
53 | 15.4M | #define MVM_GEN2_BIN_BITS 3 |
54 | | |
55 | | /* Mask used to know if we hit a size class exactly or have to round up. */ |
56 | 5.14M | #define MVM_GEN2_BIN_MASK ((1 << MVM_GEN2_BIN_BITS) - 1) |
57 | | |
58 | | /* Number of bins in the FSA. Beyond this, we just degrade to malloc/free. */ |
59 | 5.14M | #define MVM_GEN2_BINS 40 |
60 | | |
61 | | /* Default overflow list size. */ |
62 | 317 | #define MVM_GEN2_OVERFLOWS 32 |
63 | | |
64 | | /* The number of items that go into each page. */ |
65 | 21.2k | #define MVM_GEN2_PAGE_ITEMS 256 |
66 | | |
67 | | /* Functions. */ |
68 | | MVMGen2Allocator * MVM_gc_gen2_create(MVMInstance *i); |
69 | | void * MVM_gc_gen2_allocate(MVMGen2Allocator *al, MVMuint32 size); |
70 | | void * MVM_gc_gen2_allocate_zeroed(MVMGen2Allocator *al, MVMuint32 size); |
71 | | void MVM_gc_gen2_destroy(MVMInstance *i, MVMGen2Allocator *allocator); |
72 | | void MVM_gc_gen2_transfer(MVMThreadContext *src, MVMThreadContext *dest); |
73 | | void MVM_gc_gen2_compact_overflows(MVMGen2Allocator *allocator); |