Skip to content

Heap Snapshot has messed up array edge indexes #51576

@NHDaly

Description

@NHDaly

If you look at a heap snapshot, all the edges coming from an array all report an index of [0]:
Screenshot 2023-10-03 at 4 46 44 PM

Looking at the .heapsnapshot file produced by the current C++ code, it looks like we are constructing edges with garbage values. Here is a snippet from one .heapsnapshot file I produced:

0,2,1
0,3,1
0,5,2
0,7,3
1,8,5
2,18446744073709551615,6
2,18446744073709551615,7
2,18446744073709551615,8
2,18446744073709551615,7
2,18446744073709551615,9
2,18446744073709551615,7
2,18446744073709551615,10
2,18446744073709551615,7
2,18446744073709551615,11
2,18446744073709551615,7

The first field is the edge type, and 2 is "element", meaning this is an array item.

The second field is supposed to be the array index, but all of them have the same value: 18446744073709551615, which is -1 in Int64:

julia> Unsigned(18446744073709551615)
0x0000000000000000ffffffffffffffff

julia> Unsigned(18446744073709551615) == typemax(UInt64)
true

This value is coming from gc_slot_to_arrayidx(from, to), here:

_gc_heap_snapshot_record_array_edge(from, *to, gc_slot_to_arrayidx(from, to));

So somehow the gc_slot_to_arrayidx value is wrong for all of the edges:

cat /Users/nathandaly/src/julia/37833_1019974912726708.heapsnapshot.edges | grep '^2,' | grep -v '18446744073709551615' | wc -l
       0

Is it valid to call gc_slot_to_arrayidx(from, to) on the parent/child objects? The callsites look like this, for example:

julia/src/gc.c

Lines 2069 to 2076 in e5c6340

verify_parent2("obj array", obj_parent, obj_begin, "elem(%d)",
gc_slot_to_arrayidx(obj_parent, obj_begin));
jl_taggedvalue_t *o = jl_astaggedvalue(new_obj);
if (!gc_old(o->header))
nptr |= 1;
if (!gc_marked(o->header))
break;
gc_heap_snapshot_record_array_edge(obj_parent, &new_obj);

Asking for support here from @gbaraldi, @apaz-cli, @d-netto. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions