Coverage Report

Created: 2017-04-15 07:07

/home/travis/build/MoarVM/MoarVM/src/gc/worklist.c
Line
Count
Source
1
#include "moar.h"
2
3
/* Allocates a new GC worklist. */
4
146
MVMGCWorklist * MVM_gc_worklist_create(MVMThreadContext *tc, MVMuint8 include_gen2) {
5
146
    MVMGCWorklist *worklist = MVM_malloc(sizeof(MVMGCWorklist));
6
146
    worklist->items = 0;
7
146
    worklist->alloc = MVM_GC_WORKLIST_START_SIZE;
8
146
    worklist->list  = MVM_malloc(worklist->alloc * sizeof(MVMCollectable **));
9
146
    worklist->include_gen2 = include_gen2;
10
146
    return worklist;
11
146
}
12
13
/* Adds an item to the worklist, expanding it if needed. */
14
145
void MVM_gc_worklist_add_slow(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMCollectable **item) {
15
145
    if (worklist->items == worklist->alloc) {
16
145
        worklist->alloc *= 2;
17
145
        worklist->list = MVM_realloc(worklist->list, worklist->alloc * sizeof(MVMCollectable **));
18
145
    }
19
145
    worklist->list[worklist->items++] = item;
20
145
}
21
22
/* Pre-sizes the worklist in expectation a certain number of items is about to be
23
 * added. */
24
146
void MVM_gc_worklist_presize_for(MVMThreadContext *tc, MVMGCWorklist *worklist, MVMint32 items) {
25
146
    if (worklist->items + items >= worklist->alloc) {
26
145
        worklist->alloc = worklist->items + items;
27
145
        worklist->list = MVM_realloc(worklist->list, worklist->alloc * sizeof(MVMCollectable **));
28
145
    }
29
146
}
30
31
/* Free a worklist. */
32
146
void MVM_gc_worklist_destroy(MVMThreadContext *tc, MVMGCWorklist *worklist) {
33
146
    MVM_free(worklist->list);
34
146
    MVM_free(worklist);
35
146
}