/home/travis/build/MoarVM/MoarVM/src/6model/reprs/MVMSpeshLog.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 SpeshLog_this_repr; |
5 | | |
6 | | /* Creates a new type object of this representation, and associates it with |
7 | | * the given HOW. */ |
8 | 144 | static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) { |
9 | 144 | MVMSTable *st = MVM_gc_allocate_stable(tc, &SpeshLog_this_repr, HOW); |
10 | 144 | |
11 | 144 | MVMROOT(tc, st, { |
12 | 144 | MVMObject *obj = MVM_gc_allocate_type_object(tc, st); |
13 | 144 | MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj); |
14 | 144 | st->size = sizeof(MVMSpeshLog); |
15 | 144 | }); |
16 | 144 | |
17 | 144 | return st->WHAT; |
18 | 144 | } |
19 | | |
20 | | /* Initializes the log. */ |
21 | 1.86k | static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) { |
22 | 1.86k | MVMSpeshLogBody *log = (MVMSpeshLogBody *)data; |
23 | 1.86k | log->entries = MVM_malloc(sizeof(MVMSpeshLogEntry) * MVM_SPESH_LOG_DEFAULT_ENTRIES); |
24 | 1.86k | log->limit = MVM_SPESH_LOG_DEFAULT_ENTRIES; |
25 | 1.86k | } |
26 | | |
27 | | /* Copies the body of one object to another. */ |
28 | 0 | static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) { |
29 | 0 | MVM_exception_throw_adhoc(tc, "Cannot copy object with representation SpeshLog"); |
30 | 0 | } |
31 | | |
32 | | /* Called by the VM to mark any GCable items. */ |
33 | 430 | static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) { |
34 | 430 | MVMSpeshLogBody *log = (MVMSpeshLogBody *)data; |
35 | 430 | MVMuint32 i; |
36 | 430 | MVM_gc_worklist_add(tc, worklist, &(log->thread)); |
37 | 4.56M | for (i = 0; i < log->used; i++) { |
38 | 4.56M | switch (log->entries[i].kind) { |
39 | 574k | case MVM_SPESH_LOG_ENTRY: |
40 | 574k | MVM_gc_worklist_add(tc, worklist, &(log->entries[i].entry.sf)); |
41 | 574k | break; |
42 | 931k | case MVM_SPESH_LOG_PARAMETER: |
43 | 931k | case MVM_SPESH_LOG_PARAMETER_DECONT: |
44 | 931k | MVM_gc_worklist_add(tc, worklist, &(log->entries[i].param.type)); |
45 | 931k | break; |
46 | 1.86M | case MVM_SPESH_LOG_TYPE: |
47 | 1.86M | case MVM_SPESH_LOG_RETURN: |
48 | 1.86M | MVM_gc_worklist_add(tc, worklist, &(log->entries[i].type.type)); |
49 | 1.86M | break; |
50 | 18.4k | case MVM_SPESH_LOG_STATIC: |
51 | 18.4k | MVM_gc_worklist_add(tc, worklist, &(log->entries[i].value.value)); |
52 | 18.4k | break; |
53 | 1.04M | case MVM_SPESH_LOG_INVOKE: |
54 | 1.04M | MVM_gc_worklist_add(tc, worklist, &(log->entries[i].invoke.sf)); |
55 | 1.04M | break; |
56 | 4.56M | } |
57 | 4.56M | } |
58 | 430 | } |
59 | | |
60 | | /* Called by the VM in order to free memory associated with this object. */ |
61 | 684 | static void gc_free(MVMThreadContext *tc, MVMObject *obj) { |
62 | 684 | MVMSpeshLog *log = (MVMSpeshLog *)obj; |
63 | 684 | MVM_free(log->body.entries); |
64 | 684 | if (log->body.block_condvar) { |
65 | 0 | uv_cond_destroy(log->body.block_condvar); |
66 | 0 | MVM_free(log->body.block_condvar); |
67 | 0 | } |
68 | 684 | if (log->body.block_mutex) { |
69 | 0 | uv_mutex_destroy(log->body.block_mutex); |
70 | 0 | MVM_free(log->body.block_mutex); |
71 | 0 | } |
72 | 684 | } |
73 | | |
74 | | static const MVMStorageSpec storage_spec = { |
75 | | MVM_STORAGE_SPEC_REFERENCE, /* inlineable */ |
76 | | 0, /* bits */ |
77 | | 0, /* align */ |
78 | | MVM_STORAGE_SPEC_BP_NONE, /* boxed_primitive */ |
79 | | 0, /* can_box */ |
80 | | 0, /* is_unsigned */ |
81 | | }; |
82 | | |
83 | | |
84 | | /* Gets the storage specification for this representation. */ |
85 | 0 | static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) { |
86 | 0 | return &storage_spec; |
87 | 0 | } |
88 | | |
89 | | /* Compose the representation. */ |
90 | 0 | static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { |
91 | 0 | /* Nothing to do for this REPR. */ |
92 | 0 | } |
93 | | |
94 | | /* Set the size of the STable. */ |
95 | 0 | static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) { |
96 | 0 | st->size = sizeof(MVMSpeshLog); |
97 | 0 | } |
98 | | |
99 | 60 | static MVMuint64 unmanaged_size(MVMThreadContext *tc, MVMSTable *st, void *data) { |
100 | 60 | MVMSpeshLogBody *log = (MVMSpeshLogBody *)data; |
101 | 60 | return log->limit * sizeof(MVMSpeshLogEntry); |
102 | 60 | } |
103 | | |
104 | | /* Initializes the representation. */ |
105 | 144 | const MVMREPROps * MVMSpeshLog_initialize(MVMThreadContext *tc) { |
106 | 144 | return &SpeshLog_this_repr; |
107 | 144 | } |
108 | | |
109 | | static const MVMREPROps SpeshLog_this_repr = { |
110 | | type_object_for, |
111 | | MVM_gc_allocate_object, |
112 | | initialize, |
113 | | copy_to, |
114 | | MVM_REPR_DEFAULT_ATTR_FUNCS, |
115 | | MVM_REPR_DEFAULT_BOX_FUNCS, |
116 | | MVM_REPR_DEFAULT_POS_FUNCS, |
117 | | MVM_REPR_DEFAULT_ASS_FUNCS, |
118 | | MVM_REPR_DEFAULT_ELEMS, |
119 | | get_storage_spec, |
120 | | NULL, /* change_type */ |
121 | | NULL, /* serialize */ |
122 | | NULL, /* deserialize */ |
123 | | NULL, /* serialize_repr_data */ |
124 | | NULL, /* deserialize_repr_data */ |
125 | | deserialize_stable_size, |
126 | | gc_mark, |
127 | | gc_free, |
128 | | NULL, /* gc_cleanup */ |
129 | | NULL, /* gc_mark_repr_data */ |
130 | | NULL, /* gc_free_repr_data */ |
131 | | compose, |
132 | | NULL, /* spesh */ |
133 | | "MVMSpeshLog", /* name */ |
134 | | MVM_REPR_ID_MVMSpeshLog, |
135 | | unmanaged_size, |
136 | | NULL, /* describe_refs */ |
137 | | }; |