Skip to content

Commit

Permalink
correctly track element pointer in heap snapshot (#51592)
Browse files Browse the repository at this point in the history
Fixes #51576 on a simple
snapshot I collected on my machine.

(cherry picked from commit 5bdc1b3)
  • Loading branch information
d-netto authored and KristofferC committed Oct 9, 2023
1 parent 8c387e3 commit b3898c3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,8 @@ STATIC_INLINE void gc_mark_objarray(jl_ptls_t ptls, jl_value_t *obj_parent, jl_v
// the first young object before starting this chunk
// (this also would be valid for young objects, but probably less beneficial)
for (; obj_begin < obj_end; obj_begin += step) {
new_obj = *obj_begin;
jl_value_t **slot = obj_begin;
new_obj = *slot;
if (new_obj != NULL) {
verify_parent2("obj array", obj_parent, obj_begin, "elem(%d)",
gc_slot_to_arrayidx(obj_parent, obj_begin));
Expand All @@ -1984,7 +1985,7 @@ STATIC_INLINE void gc_mark_objarray(jl_ptls_t ptls, jl_value_t *obj_parent, jl_v
nptr |= 1;
if (!gc_marked(o->header))
break;
gc_heap_snapshot_record_array_edge(obj_parent, &new_obj);
gc_heap_snapshot_record_array_edge(obj_parent, slot);
}
}
}
Expand All @@ -2006,13 +2007,14 @@ STATIC_INLINE void gc_mark_objarray(jl_ptls_t ptls, jl_value_t *obj_parent, jl_v
}
}
for (; obj_begin < scan_end; obj_begin += step) {
jl_value_t **slot = obj_begin;
new_obj = *obj_begin;
if (new_obj != NULL) {
verify_parent2("obj array", obj_parent, obj_begin, "elem(%d)",
gc_slot_to_arrayidx(obj_parent, obj_begin));
gc_assert_parent_validity(obj_parent, new_obj);
gc_try_claim_and_push(mq, new_obj, &nptr);
gc_heap_snapshot_record_array_edge(obj_parent, &new_obj);
gc_heap_snapshot_record_array_edge(obj_parent, slot);
}
}
if (too_big) {
Expand Down Expand Up @@ -2043,7 +2045,8 @@ STATIC_INLINE void gc_mark_array8(jl_ptls_t ptls, jl_value_t *ary8_parent, jl_va
for (; ary8_begin < ary8_end; ary8_begin += elsize) {
int early_end = 0;
for (uint8_t *pindex = elem_begin; pindex < elem_end; pindex++) {
new_obj = ary8_begin[*pindex];
jl_value_t **slot = &ary8_begin[*pindex];
new_obj = *slot;
if (new_obj != NULL) {
verify_parent2("array", ary8_parent, &new_obj, "elem(%d)",
gc_slot_to_arrayidx(ary8_parent, ary8_begin));
Expand All @@ -2054,7 +2057,7 @@ STATIC_INLINE void gc_mark_array8(jl_ptls_t ptls, jl_value_t *ary8_parent, jl_va
early_end = 1;
break;
}
gc_heap_snapshot_record_array_edge(ary8_parent, &new_obj);
gc_heap_snapshot_record_array_edge(ary8_parent, slot);
}
}
if (early_end)
Expand All @@ -2080,13 +2083,14 @@ STATIC_INLINE void gc_mark_array8(jl_ptls_t ptls, jl_value_t *ary8_parent, jl_va
}
for (; ary8_begin < ary8_end; ary8_begin += elsize) {
for (uint8_t *pindex = elem_begin; pindex < elem_end; pindex++) {
new_obj = ary8_begin[*pindex];
jl_value_t **slot = &ary8_begin[*pindex];
new_obj = *slot;
if (new_obj != NULL) {
verify_parent2("array", ary8_parent, &new_obj, "elem(%d)",
gc_slot_to_arrayidx(ary8_parent, ary8_begin));
gc_assert_parent_validity(ary8_parent, new_obj);
gc_try_claim_and_push(mq, new_obj, &nptr);
gc_heap_snapshot_record_array_edge(ary8_parent, &new_obj);
gc_heap_snapshot_record_array_edge(ary8_parent, slot);
}
}
}
Expand Down Expand Up @@ -2118,7 +2122,8 @@ STATIC_INLINE void gc_mark_array16(jl_ptls_t ptls, jl_value_t *ary16_parent, jl_
for (; ary16_begin < ary16_end; ary16_begin += elsize) {
int early_end = 0;
for (uint16_t *pindex = elem_begin; pindex < elem_end; pindex++) {
new_obj = ary16_begin[*pindex];
jl_value_t **slot = &ary16_begin[*pindex];
new_obj = *slot;
if (new_obj != NULL) {
verify_parent2("array", ary16_parent, &new_obj, "elem(%d)",
gc_slot_to_arrayidx(ary16_parent, ary16_begin));
Expand All @@ -2129,7 +2134,7 @@ STATIC_INLINE void gc_mark_array16(jl_ptls_t ptls, jl_value_t *ary16_parent, jl_
early_end = 1;
break;
}
gc_heap_snapshot_record_array_edge(ary16_parent, &new_obj);
gc_heap_snapshot_record_array_edge(ary16_parent, slot);
}
}
if (early_end)
Expand All @@ -2155,13 +2160,14 @@ STATIC_INLINE void gc_mark_array16(jl_ptls_t ptls, jl_value_t *ary16_parent, jl_
}
for (; ary16_begin < scan_end; ary16_begin += elsize) {
for (uint16_t *pindex = elem_begin; pindex < elem_end; pindex++) {
new_obj = ary16_begin[*pindex];
jl_value_t **slot = &ary16_begin[*pindex];
new_obj = *slot;
if (new_obj != NULL) {
verify_parent2("array", ary16_parent, &new_obj, "elem(%d)",
gc_slot_to_arrayidx(ary16_parent, ary16_begin));
gc_assert_parent_validity(ary16_parent, new_obj);
gc_try_claim_and_push(mq, new_obj, &nptr);
gc_heap_snapshot_record_array_edge(ary16_parent, &new_obj);
gc_heap_snapshot_record_array_edge(ary16_parent, slot);
}
}
}
Expand Down

0 comments on commit b3898c3

Please sign in to comment.