Coverage Report

Created: 2018-06-21 18:56

/home/travis/build/MoarVM/MoarVM/src/6model/reprs/MVMThread.c
Line
Count
Source (jump to first uncovered line)
1
#include "moar.h"
2
3
/* This representation's function pointer table. */
4
static const MVMREPROps MVMThread_this_repr;
5
6
/* Creates a new type object of this representation, and associates it with
7
 * the given HOW. */
8
288
static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
9
288
    MVMSTable *st  = MVM_gc_allocate_stable(tc, &MVMThread_this_repr, HOW);
10
288
11
288
    MVMROOT(tc, st, {
12
288
        MVMObject *obj = MVM_gc_allocate_type_object(tc, st);
13
288
        MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj);
14
288
        st->size = sizeof(MVMThread);
15
288
    });
16
288
17
288
    return st->WHAT;
18
288
}
19
20
/* Copies the body of one object to another. */
21
0
static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) {
22
0
    MVM_exception_throw_adhoc(tc, "Cannot copy object with representation MVMThread");
23
0
}
24
25
/* Adds held objects to the GC worklist. */
26
66
static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) {
27
66
    MVMThreadBody *body = (MVMThreadBody *)data;
28
66
    MVM_gc_worklist_add(tc, worklist, &body->invokee);
29
66
    MVM_gc_worklist_add(tc, worklist, &body->next);
30
66
31
66
    /* Unstarted threads are not yet in the running threads list, so their TC
32
66
     * needs marking here. The rest of the time, it's marked due to being in
33
66
     * the running threads list. */
34
66
    if (MVM_load(&(body->stage)) == MVM_thread_stage_unstarted)
35
9
        MVM_gc_root_add_tc_roots_to_worklist(body->tc, worklist, NULL);
36
66
}
37
38
/* Called by the VM in order to free memory associated with this object. */
39
0
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
40
0
    /* The ThreadContext has already been destroyed by the GC. */
41
0
    MVMThread *thread = (MVMThread *)obj;
42
0
    thread->body.invokee = NULL;
43
0
}
44
45
static const MVMStorageSpec storage_spec = {
46
    MVM_STORAGE_SPEC_REFERENCE, /* inlineable */
47
    0,                          /* bits */
48
    0,                          /* align */
49
    MVM_STORAGE_SPEC_BP_NONE,   /* boxed_primitive */
50
    0,                          /* can_box */
51
    0,                          /* is_unsigned */
52
};
53
54
55
/* Gets the storage specification for this representation. */
56
0
static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) {
57
0
    return &storage_spec;
58
0
}
59
60
/* Compose the representation. */
61
0
static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) {
62
0
    /* Nothing to do for this REPR. */
63
0
}
64
65
/* Initializes the representation. */
66
144
const MVMREPROps * MVMThread_initialize(MVMThreadContext *tc) {
67
144
    return &MVMThread_this_repr;
68
144
}
69
70
static const MVMREPROps MVMThread_this_repr = {
71
    type_object_for,
72
    MVM_gc_allocate_object,
73
    NULL, /* initialize */
74
    copy_to,
75
    MVM_REPR_DEFAULT_ATTR_FUNCS,
76
    MVM_REPR_DEFAULT_BOX_FUNCS,
77
    MVM_REPR_DEFAULT_POS_FUNCS,
78
    MVM_REPR_DEFAULT_ASS_FUNCS,
79
    MVM_REPR_DEFAULT_ELEMS,
80
    get_storage_spec,
81
    NULL, /* change_type */
82
    NULL, /* serialize */
83
    NULL, /* deserialize */
84
    NULL, /* serialize_repr_data */
85
    NULL, /* deserialize_repr_data */
86
    NULL, /* deserialize_stable_size */
87
    gc_mark,
88
    gc_free,
89
    NULL, /* gc_cleanup */
90
    NULL, /* gc_mark_repr_data */
91
    NULL, /* gc_free_repr_data */
92
    compose,
93
    NULL, /* spesh */
94
    "VMThread", /* name */
95
    MVM_REPR_ID_MVMThread,
96
    NULL, /* unmanaged_size */
97
    NULL, /* describe_refs */
98
};