Skip to content

Commit

Permalink
Make jl_datatype_size reflect non-padded field size
Browse files Browse the repository at this point in the history
Padding is then added when creating the struct layout, but otherwise
the memory layout should be unchanged. This is an alternative to
the proposal in #46260. LLVM size and julia size should now be
aligned.
  • Loading branch information
Keno committed Aug 11, 2022
1 parent 854519c commit 3c003c0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,14 @@ void jl_compute_field_offsets(jl_datatype_t *st)
zeroinit = ((jl_datatype_t*)fld)->zeroinit;
npointers += fld_npointers;
}
desc[i].size = fsz;
fsz = LLT_ALIGN(fsz, al);
}
else {
fsz = sizeof(void*);
if (fsz > MAX_ALIGN)
fsz = MAX_ALIGN;
desc[i].size = fsz;
al = fsz;
desc[i].isptr = 1;
zeroinit = 1;
Expand All @@ -503,7 +506,6 @@ void jl_compute_field_offsets(jl_datatype_t *st)
}
homogeneous &= firstty == fld;
desc[i].offset = sz;
desc[i].size = fsz;
if (__unlikely(max_offset - sz < fsz))
throw_ovf(should_malloc, desc, st, sz);
sz += fsz;
Expand All @@ -525,9 +527,7 @@ void jl_compute_field_offsets(jl_datatype_t *st)
if (al > alignm)
alignm = al;
}
st->size = LLT_ALIGN(sz, alignm);
if (st->size > sz)
haspadding = 1;
st->size = sz;
if (should_malloc && npointers)
pointers = (uint32_t*)malloc_s(npointers * sizeof(uint32_t));
else
Expand Down Expand Up @@ -1470,6 +1470,7 @@ static inline void memassign_safe(int hasptr, jl_value_t *parent, char *dst, con
memmove_refs((void**)dst, (void**)src, nptr);
jl_gc_multi_wb(parent, src);
src = (jl_value_t*)((char*)src + nptr * sizeof(void*));
dst += nptr * sizeof(void*);
nb -= nptr * sizeof(void*);
}
else {
Expand Down

0 comments on commit 3c003c0

Please sign in to comment.