Skip to content

Commit

Permalink
Sketch in heap profiler data structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 16, 2016
1 parent 99bf383 commit 60db2be
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ OBJECTS = src/core/callsite@obj@ \
src/profiler/instrument@obj@ \
src/profiler/log@obj@ \
src/profiler/profile@obj@ \
src/profiler/heapsnapshot@obj@ \
src/instrument/crossthreadwrite@obj@ \
src/moar@obj@ \
@platform@ \
Expand Down Expand Up @@ -336,6 +337,7 @@ HEADERS = src/moar.h \
src/profiler/instrument.h \
src/profiler/log.h \
src/profiler/profile.h \
src/profiler/heapsnapshot.h \
src/platform/mmap.h \
src/platform/time.h \
src/platform/threads.h \
Expand Down
1 change: 1 addition & 0 deletions src/moar.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ MVM_PUBLIC const MVMint32 MVM_jit_support(void);
#include "profiler/instrument.h"
#include "profiler/log.h"
#include "profiler/profile.h"
#include "profiler/heapsnapshot.h"
#include "instrument/crossthreadwrite.h"

MVMObject *MVM_backend_config(MVMThreadContext *tc);
Expand Down
1 change: 1 addition & 0 deletions src/profiler/heapsnapshot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "moar.h"
106 changes: 106 additions & 0 deletions src/profiler/heapsnapshot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* A collection of heap snapshots, with common type and static frame names.
* Note that we take care to never refer to heap objects themselves in here,
* including for types and frames, since to do so would extend their lifetime
* for the whole program, which would render the results pretty bogus. */
struct MVMHeapSnapshotCollection {
/* List of taken snapshots. */
MVMHeapSnapshot *snapshots;
MVMuint32 num_snapshots;
MVMuint32 alloc_snapshots;

/* Known types/REPRs. Just a list for now, but we might like to look at a
* hash or trie if this ends up making taking a snapshot wicked slow. */
MVMHeapSnapshotType *types;

/* Known static frames. Same applies to searching this as to the above. */
MVMHeapSnapshotStaticFrame *static_frames;

/* Strings, referenced by index from various places. */
char **strings;
};

/* An individual heap snapshot. */
struct MVMHeapSnapshot {
/* Array of data about collectables on the heap. */
MVMHeapSnapshotCollectable *collectables;
MVMuint64 num_collectables;
MVMuint64 alloc_collectables;

/* References. */
MVMHeapSnapshotReference *references;
MVMuint64 num_references;
MVMuint64 alloc_references;
};

/* An object/type object/STable type in the snapshot. */
struct MVMHeapSnapshotType {
/* Name of the representation. Do not free; this is a reference to the
* REPR's name string itself. */
char *repr_name;

/* The type's debug name. We assume these are sufficiently unique we don't
* reference them in the string heap. */
char *type_name;
};

/* A static frame in the snapshot. */
struct MVMHeapSnapshotStaticFrame {
/* The static frame name; index into the snapshot collection string heap. */
MVMuint32 name;

/* The line number where it's declared. */
MVMuint32 line_number;

/* And the filename; also an index into snapshot collection string heap. */
MVMuint32 file;
};

/* Kinds of collectable. */
#define MVM_SNAPSHOT_COL_KIND_OBJECT 1
#define MVM_SNAPSHOT_COL_KIND_TYPE_OBJECT 2
#define MVM_SNAPSHOT_COL_KIND_STABLE 3
#define MVM_SNAPSHOT_COL_KIND_FRAME 4

/* Data about an individual collectable in the heap snapshot. Ordered to avoid
* holes. */
struct MVMHeapSnapshotCollectable {
/* What kind of collectable is it? */
MVMuint16 kind;

/* Self-size (from the collectable header). */
MVMuint16 collectable_size;

/* Index into the snapshot collection type name or frame info array,
* depending on kind. */
MVMuint32 type_or_frame_index;

/* The number of other collectables this one references. */
MVMuint32 num_refs;

/* Index into the references info list. */
MVMuint64 refs_start;

/* Unmanaged size (memory held but not under the GC's contorl). */
MVMuint64 unmanaged_size;
};

/* Reference identifier kinds. */
#define MVM_SNAPSHOT_REF_KIND_UNKNOWN 0
#define MVM_SNAPSHOT_REF_KIND_INDEX 1
#define MVM_SNAPSHOT_REF_KIND_STRING 2

/* Number of bits needed for ref kind. */
#define MVM_SNAPSHOT_REF_KIND_BITS 2

/* A reference from one collectable to another. */
struct MVMHeapSnapshotReference {
/* The lower MVM_SNAPSHOT_REF_KIND_BITS bits indicate the type of reference.
* After shifting those away, we either have a numeric index (e.g. for
* array indexes) or an index into the string heap (for lexicals in frames
* and attributes in objects). If kind is MVM_SNAPSHOT_REF_KIND_UNKNOWN the
* rest of the bits will be zero; we know nothing of the relationship. */
MVMuint64 kind;

/* The index of the collectable referenced. */
MVMuint64 collectable_index;
};
6 changes: 6 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,9 @@ typedef struct MVMProfileGC MVMProfileGC;
typedef struct MVMProfileCallNode MVMProfileCallNode;
typedef struct MVMProfileAllocationCount MVMProfileAllocationCount;
typedef struct MVMProfileContinuationData MVMProfileContinuationData;
typedef struct MVMHeapSnapshotCollection MVMHeapSnapshotCollection;
typedef struct MVMHeapSnapshot MVMHeapSnapshot;
typedef struct MVMHeapSnapshotType MVMHeapSnapshotType;
typedef struct MVMHeapSnapshotStaticFrame MVMHeapSnapshotStaticFrame;
typedef struct MVMHeapSnapshotCollectable MVMHeapSnapshotCollectable;
typedef struct MVMHeapSnapshotReference MVMHeapSnapshotReference;

0 comments on commit 60db2be

Please sign in to comment.