Skip to content

Instantly share code, notes, and snippets.

@niner
Created April 17, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niner/176100dec8a726a9cb48870c4ca0b88a to your computer and use it in GitHub Desktop.
Save niner/176100dec8a726a9cb48870c4ca0b88a to your computer and use it in GitHub Desktop.
diff --git a/src/gc/gen2.c b/src/gc/gen2.c
index 98a31ae22..b619679b1 100644
--- a/src/gc/gen2.c
+++ b/src/gc/gen2.c
@@ -12,6 +12,7 @@ MVMGen2Allocator * MVM_gc_gen2_create(MVMInstance *i) {
al->alloc_overflows = MVM_GEN2_OVERFLOWS;
al->num_overflows = 0;
al->overflows = MVM_malloc(al->alloc_overflows * sizeof(MVMCollectable *));
+ al->generating_heap_snapshot = 0;
return al;
}
@@ -59,6 +60,8 @@ static void add_page(MVMGen2Allocator *al, MVMuint32 bin) {
* it up in any way. */
void * MVM_gc_gen2_allocate(MVMGen2Allocator *al, MVMuint32 size) {
void *result;
+ if (al->generating_heap_snapshot)
+ fprintf(stderr, "Allocating in gen2 while generating heap snapshot\n");
/* Determine the bin. If we hit a bin exactly then it's off-by-one,
* since the bins list is base-0. Otherwise we've some extra bits,
diff --git a/src/gc/gen2.h b/src/gc/gen2.h
index 01daadbab..831e666a6 100644
--- a/src/gc/gen2.h
+++ b/src/gc/gen2.h
@@ -39,6 +39,8 @@ struct MVMGen2Allocator {
/* The amount of space allocated in the overflow array. */
MVMuint32 alloc_overflows;
+
+ int generating_heap_snapshot;
};
/* The number of bits we discard from the requested size when binning
diff --git a/src/profiler/heapsnapshot.c b/src/profiler/heapsnapshot.c
index e1ef0053e..d9ff643f2 100644
--- a/src/profiler/heapsnapshot.c
+++ b/src/profiler/heapsnapshot.c
@@ -371,9 +371,11 @@ static void set_static_frame_index(MVMThreadContext *tc, MVMHeapSnapshotState *s
MVMCompUnit *cu = sf->body.cu;
MVMBytecodeAnnotation *ann = MVM_bytecode_resolve_annotation(tc, &(sf->body), 0);
MVMuint64 line = ann ? ann->line_number : 1;
+ tc->gen2->generating_heap_snapshot = 0;
MVMString *file_name = ann && ann->filename_string_heap_index < cu->body.num_strings
? MVM_cu_string(tc, cu, ann->filename_string_heap_index)
: cu->body.filename;
+ tc->gen2->generating_heap_snapshot = 1;
/* We're running as part of gc_finalize. By now, live objects have been marked
but not yet collected. If the file name was just deserialized from the string
@@ -1870,6 +1872,7 @@ void finish_collection_to_filehandle(MVMThreadContext *tc, MVMHeapSnapshotCollec
/* Takes a snapshot of the heap, outputting it to the filehandle */
void MVM_profile_heap_take_snapshot(MVMThreadContext *tc) {
if (MVM_profile_heap_profiling(tc)) {
+ tc->gen2->generating_heap_snapshot = 1;
MVMHeapSnapshotCollection *col = tc->instance->heap_snapshots;
MVMint64 do_heapsnapshot = 1;
if (MVM_confprog_has_entrypoint(tc, MVM_PROGRAM_ENTRYPOINT_HEAPSNAPSHOT)) {
@@ -1902,6 +1905,7 @@ void MVM_profile_heap_take_snapshot(MVMThreadContext *tc) {
}
col->snapshot_idx++;
+ tc->gen2->generating_heap_snapshot = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment