Coverage Report

Created: 2018-06-21 18:56

/home/travis/build/MoarVM/MoarVM/src/profiler/heapsnapshot.h
Line
Count
Source (jump to first uncovered line)
1
struct MVMHeapDumpIndexSnapshotEntry {
2
    MVMuint64 collectables_size;
3
    MVMuint64 full_refs_size;
4
    MVMuint64 refs_middlepoint;
5
    MVMuint64 incremental_data;
6
};
7
8
struct MVMHeapDumpIndex {
9
    MVMuint64 stringheap_size;
10
    MVMuint64 types_size;
11
    MVMuint64 staticframes_size;
12
13
    MVMuint64 snapshot_size_entries;
14
    MVMHeapDumpIndexSnapshotEntry *snapshot_sizes;
15
16
    MVMuint64 snapshot_sizes_alloced;
17
};
18
19
/* A collection of heap snapshots, with common type and static frame names.
20
 * Note that we take care to never refer to heap objects themselves in here,
21
 * including for types and frames, since to do so would extend their lifetime
22
 * for the whole program, which would render the results pretty bogus. */
23
struct MVMHeapSnapshotCollection {
24
    /* Snapshot we are currently taking and its index */
25
    MVMHeapSnapshot *snapshot;
26
    MVMuint64 snapshot_idx;
27
28
    /* Known types/REPRs. Just a list for now, but we might like to look at a
29
     * hash or trie if this ends up making taking a snapshot wicked slow. */
30
    MVMHeapSnapshotType *types;
31
    MVMuint64 num_types;
32
    MVMuint64 alloc_types;
33
34
    /* Known static frames. Same applies to searching this as to the above. */
35
    MVMHeapSnapshotStaticFrame *static_frames;
36
    MVMuint64 num_static_frames;
37
    MVMuint64 alloc_static_frames;
38
39
    /* Strings, referenced by index from various places. Also a "should we
40
     * free it" flag for each one. */
41
    char **strings;
42
    MVMuint64 num_strings;
43
    MVMuint64 alloc_strings;
44
    char *strings_free;
45
    MVMuint64 num_strings_free;
46
    MVMuint64 alloc_strings_free;
47
48
    MVMuint64 types_written;
49
    MVMuint64 static_frames_written;
50
    MVMuint64 strings_written;
51
52
    MVMHeapDumpIndex *index;
53
54
    /* The file handle we are outputting to */
55
    FILE *fh;
56
};
57
58
/* An individual heap snapshot. */
59
struct MVMHeapSnapshot {
60
    /* Array of data about collectables on the heap. */
61
    MVMHeapSnapshotCollectable *collectables;
62
    MVMuint64 num_collectables;
63
    MVMuint64 alloc_collectables;
64
65
    /* References.  */
66
    MVMHeapSnapshotReference *references;
67
    MVMuint64 num_references;
68
    MVMuint64 alloc_references;
69
};
70
71
/* An object/type object/STable type in the snapshot. */
72
struct MVMHeapSnapshotType {
73
    /* String heap index of the REPR name. */
74
    MVMuint64 repr_name;
75
76
    /* String heap index of the type's debug name. */
77
    MVMuint64 type_name;
78
};
79
80
/* A static frame in the snapshot. */
81
struct MVMHeapSnapshotStaticFrame {
82
    /* The static frame name; index into the snapshot collection string heap. */
83
    MVMuint64 name;
84
85
    /* The static frame compilation unit ID, for added uniqueness checking.
86
     * Also an index into the string heap. */
87
    MVMuint64 cuid;
88
89
    /* The line number where it's declared. */
90
    MVMuint64 line;
91
92
    /* And the filename; also an index into snapshot collection string heap. */
93
    MVMuint64 file;
94
};
95
96
/* Kinds of collectable, plus a few "virtual" kinds to cover the various places
97
 * we find roots. MVM_SNAPSHOT_COL_KIND_ROOT is the ultimate root of the heap
98
 * snapshot and everything hangs off it. */
99
0
#define MVM_SNAPSHOT_COL_KIND_OBJECT            1
100
0
#define MVM_SNAPSHOT_COL_KIND_TYPE_OBJECT       2
101
0
#define MVM_SNAPSHOT_COL_KIND_STABLE            3
102
0
#define MVM_SNAPSHOT_COL_KIND_FRAME             4
103
0
#define MVM_SNAPSHOT_COL_KIND_PERM_ROOTS        5
104
0
#define MVM_SNAPSHOT_COL_KIND_INSTANCE_ROOTS    6
105
0
#define MVM_SNAPSHOT_COL_KIND_CSTACK_ROOTS      7
106
0
#define MVM_SNAPSHOT_COL_KIND_THREAD_ROOTS      8
107
0
#define MVM_SNAPSHOT_COL_KIND_ROOT              9
108
0
#define MVM_SNAPSHOT_COL_KIND_INTERGEN_ROOTS    10
109
0
#define MVM_SNAPSHOT_COL_KIND_CALLSTACK_ROOTS   11
110
111
/* Data about an individual collectable in the heap snapshot. Ordered to avoid
112
 * holes. */
113
struct MVMHeapSnapshotCollectable {
114
    /* What kind of collectable is it? */
115
    MVMuint16 kind;
116
117
    /* Self-size (from the collectable header). */
118
    MVMuint16 collectable_size;
119
120
    /* Index into the snapshot collection type name or frame info array,
121
     * depending on kind. */
122
    MVMuint32 type_or_frame_index;
123
124
    /* The number of other collectables this one references. */
125
    MVMuint32 num_refs;
126
127
    /* Index into the references info list. */
128
    MVMuint64 refs_start;
129
130
    /* Unmanaged size (memory held but not under the GC's contorl). */
131
    MVMuint64 unmanaged_size;
132
};
133
134
/* Reference identifier kinds. */
135
0
#define MVM_SNAPSHOT_REF_KIND_UNKNOWN   0
136
0
#define MVM_SNAPSHOT_REF_KIND_INDEX     1
137
0
#define MVM_SNAPSHOT_REF_KIND_STRING    2
138
139
/* Number of bits needed for ref kind. */
140
0
#define MVM_SNAPSHOT_REF_KIND_BITS      2
141
142
/* A reference from one collectable to another. */
143
struct MVMHeapSnapshotReference {
144
    /* The lower MVM_SNAPSHOT_REF_KIND_BITS bits indicate the type of reference.
145
     * After shifting those away, we either have a numeric index (e.g. for
146
     * array indexes) or an index into the string heap (for lexicals in frames
147
     * and attributes in objects). If kind is MVM_SNAPSHOT_REF_KIND_UNKNOWN the
148
     * rest of the bits will be zero; we know nothing of the relationship. */
149
    MVMuint64 description;
150
151
    /* The index of the collectable referenced. */
152
    MVMuint64 collectable_index;
153
};
154
155
/* Current state object whlie taking a heap snapshot. */
156
struct MVMHeapSnapshotState {
157
    /* The heap snapshot collection and current working snapshot. */
158
    MVMHeapSnapshotCollection *col;
159
    MVMHeapSnapshot *hs;
160
161
    /* Our current collectable worklist. */
162
    MVMHeapSnapshotWorkItem *workitems;
163
    MVMuint64 num_workitems;
164
    MVMuint64 alloc_workitems;
165
166
    /* The collectable we're currently adding references for. */
167
    MVMuint64 ref_from;
168
169
    /* The seen hash of collectables (including frames). */
170
    MVMHeapSnapshotSeen *seen;
171
172
    /* We sometimes use GC mark functions to find references. Keep a worklist
173
     * around for those times (much cheaper than allocating it whenever we
174
     * need it). */
175
    MVMGCWorklist *gcwl;
176
};
177
178
/* Work item used while taking a heap snapshot. */
179
struct MVMHeapSnapshotWorkItem {
180
    /* The kind of collectable. */
181
    MVMuint16 kind;
182
183
    /* Index in the collectables (assigned upon adding to the worklist). */
184
    MVMuint64 col_idx;
185
186
    /* Target collectable, if any. */
187
    void *target;
188
};
189
190
/* Heap seen hash entry used while taking a heap snapshot. */
191
struct MVMHeapSnapshotSeen {
192
    /* The seen address. */
193
    void *address;
194
195
    /* The collectables index it has. */
196
    MVMuint64 idx;
197
198
    /* Hash handle. */
199
    UT_hash_handle hash_handle;
200
};
201
202
MVMint32 MVM_profile_heap_profiling(MVMThreadContext *tc);
203
void MVM_profile_heap_start(MVMThreadContext *tc, MVMObject *config);
204
void MVM_profile_heap_take_snapshot(MVMThreadContext *tc);
205
MVMObject * MVM_profile_heap_end(MVMThreadContext *tc);
206
207
/* API for things that want to contribute more detailed data to the heap
208
 * profile. */
209
MVM_PUBLIC void MVM_profile_heap_add_collectable_rel_const_cstr(MVMThreadContext *tc,
210
    MVMHeapSnapshotState *ss, MVMCollectable *collectable, char *desc);
211
MVM_PUBLIC void MVM_profile_heap_add_collectable_rel_vm_str(MVMThreadContext *tc,
212
    MVMHeapSnapshotState *ss, MVMCollectable *collectable, MVMString *desc);
213
MVM_PUBLIC void MVM_profile_heap_add_collectable_rel_idx(MVMThreadContext *tc,
214
    MVMHeapSnapshotState *ss, MVMCollectable *collectable, MVMuint64 idx);