Skip to content

Commit 008c775

Browse files
committed
fix #10570, teach GC about variable DataType size
needs a test, and may not be optimal
1 parent 89103a8 commit 008c775

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/gc.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1629,19 +1629,19 @@ static int push_root(jl_value_t *v, int d, int bits)
16291629
// for stores to stack slots
16301630
refyoung = GC_MARKED_NOESC;
16311631
}
1632-
else if(vt == (jl_value_t*)jl_symbol_type) {
1632+
else if (vt == (jl_value_t*)jl_symbol_type) {
16331633
//gc_setmark_other(v, GC_MARKED); // symbols have their own allocator and are never freed
16341634
}
1635-
else if(
1635+
else if (
16361636
#ifdef GC_VERIFY
1637-
// this check should not be needed but it helps catching corruptions early
1638-
gc_typeof(vt) == (jl_value_t*)jl_datatype_type
1637+
// this check should not be needed but it helps catching corruptions early
1638+
gc_typeof(vt) == (jl_value_t*)jl_datatype_type
16391639
#else
1640-
1
1640+
1
16411641
#endif
1642-
) {
1642+
) {
16431643
jl_datatype_t *dt = (jl_datatype_t*)vt;
1644-
MARK(v, bits = gc_setmark(v, jl_datatype_size(dt), GC_MARKED_NOESC));
1644+
MARK(v, bits = gc_setmark(v, jl_struct_value_size(v), GC_MARKED_NOESC));
16451645
int nf = (int)jl_tuple_len(dt->names);
16461646
// TODO check if there is a perf improvement for objects with a lot of fields
16471647
// int fdsz = sizeof(void*)*nf;

src/julia.h

+11
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,17 @@ STATIC_INLINE jl_value_t *jl_cellset(void *a, size_t i, void *x)
569569
#define jl_field_size(st,i) (((jl_datatype_t*)st)->fields[i].size)
570570
#define jl_datatype_size(t) (((jl_datatype_t*)t)->size)
571571

572+
STATIC_INLINE size_t jl_struct_value_size(jl_value_t *v)
573+
{
574+
jl_datatype_t *dt = (jl_datatype_t*)jl_typeof(v);
575+
if (dt == jl_datatype_type) {
576+
return NWORDS(sizeof(jl_datatype_t) + jl_tuple_len(((jl_datatype_t*)v)->names)*sizeof(jl_fielddesc_t))*sizeof(void*);
577+
}
578+
else {
579+
return jl_datatype_size(dt);
580+
}
581+
}
582+
572583
// basic predicates -----------------------------------------------------------
573584
#define jl_is_null(v) (((jl_value_t*)(v)) == ((jl_value_t*)jl_null))
574585
#define jl_is_nothing(v) (((jl_value_t*)(v)) == ((jl_value_t*)jl_nothing))

0 commit comments

Comments
 (0)