Skip to content

Commit

Permalink
pass alignment from the outside jl_gc_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed May 25, 2017
1 parent 541e8de commit 19ee5f9
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 82 deletions.
16 changes: 8 additions & 8 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
size_t doffs = tsz;
tsz += tot;
tsz = JL_ARRAY_ALIGN(tsz, JL_SMALL_BYTE_ALIGNMENT); // align whole object
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, atype);
// No allocation or safepoint allowed after this
a->flags.how = 0;
data = (char*)a + doffs;
Expand All @@ -105,7 +105,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
data = jl_gc_managed_malloc(tot);
// Allocate the Array **after** allocating the data
// to make sure the array is still young
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
// No allocation or safepoint allowed after this
a->flags.how = 2;
jl_gc_track_malloced_array(ptls, a);
Expand Down Expand Up @@ -181,7 +181,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,

int ndimwords = jl_array_ndimwords(ndims);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t) + sizeof(void*), JL_SMALL_BYTE_ALIGNMENT);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, atype);
// No allocation or safepoint allowed after this
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
a->flags.ndims = ndims;
Expand Down Expand Up @@ -251,7 +251,7 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)

int ndimwords = jl_array_ndimwords(1);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t) + sizeof(void*), JL_SMALL_BYTE_ALIGNMENT);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, jl_array_uint8_type);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, jl_array_uint8_type);
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
a->flags.ndims = 1;
a->offset = 0;
Expand Down Expand Up @@ -294,7 +294,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data,

int ndimwords = jl_array_ndimwords(1);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), JL_CACHE_BYTE_ALIGNMENT);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
// No allocation or safepoint allowed after this
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
a->data = data;
Expand Down Expand Up @@ -357,7 +357,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data,

int ndimwords = jl_array_ndimwords(ndims);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), JL_CACHE_BYTE_ALIGNMENT);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
// No allocation or safepoint allowed after this
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
a->data = data;
Expand Down Expand Up @@ -434,7 +434,7 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)

JL_DLLEXPORT jl_value_t *jl_pchar_to_string(const char *str, size_t len)
{
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, jl_string_type);
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, /*align*/ 0, jl_string_type);
*(size_t*)s = len;
memcpy((char*)s + sizeof(size_t), str, len);
((char*)s + sizeof(size_t))[len] = 0;
Expand All @@ -443,7 +443,7 @@ JL_DLLEXPORT jl_value_t *jl_pchar_to_string(const char *str, size_t len)

JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len)
{
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, jl_string_type);
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, /*align*/ 0, jl_string_type);
*(size_t*)s = len;
((char*)s + sizeof(size_t))[len] = 0;
return s;
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
jl_ptls_t ptls = jl_get_ptls_states();
jl_array_t *ar = n==0 ? (jl_array_t*)jl_an_empty_vec_any : jl_alloc_vec_any(n);
JL_GC_PUSH1(&ar);
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t),
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t), /*align*/ 0,
jl_expr_type);
ex->head = head;
ex->args = ar;
Expand All @@ -877,7 +877,7 @@ JL_CALLABLE(jl_f__expr)
JL_GC_PUSH1(&ar);
for(size_t i=0; i < nargs-1; i++)
jl_array_ptr_set(ar, i, args[i+1]);
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t),
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t), /*align*/ 0,
jl_expr_type);
ex->head = (jl_sym_t*)args[0];
ex->args = ar;
Expand Down
26 changes: 14 additions & 12 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_methtable_t *mt =
(jl_methtable_t*)jl_gc_alloc(ptls, sizeof(jl_methtable_t),
(jl_methtable_t*)jl_gc_alloc(ptls, sizeof(jl_methtable_t), 0,
jl_methtable_type);
mt->name = jl_demangle_typename(name);
mt->module = module;
Expand All @@ -53,7 +53,7 @@ JL_DLLEXPORT jl_typename_t *jl_new_typename_in(jl_sym_t *name, jl_module_t *modu
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_typename_t *tn =
(jl_typename_t*)jl_gc_alloc(ptls, sizeof(jl_typename_t),
(jl_typename_t*)jl_gc_alloc(ptls, sizeof(jl_typename_t), 0,
jl_typename_type);
tn->name = name;
tn->module = module;
Expand Down Expand Up @@ -82,7 +82,7 @@ jl_datatype_t *jl_new_abstracttype(jl_value_t *name, jl_datatype_t *super, jl_sv
jl_datatype_t *jl_new_uninitialized_datatype(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ptls, sizeof(jl_datatype_t), jl_datatype_type);
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ptls, sizeof(jl_datatype_t), 0, jl_datatype_type);
t->depth = 0;
t->hasfreetypevars = 0;
t->isleaftype = 1;
Expand Down Expand Up @@ -451,7 +451,7 @@ static jl_value_t *jl_new_bits_internal(jl_value_t *dt, void *data, size_t *len)
if (bt == jl_int32_type) return jl_box_int32(*(int32_t*)data);
if (bt == jl_float64_type) return jl_box_float64(*(double*)data);

jl_value_t *v = jl_gc_alloc(ptls, nb, bt);
jl_value_t *v = jl_gc_alloc(ptls, nb, jl_datatype_align(bt), bt);
switch (nb) {
case 1: *(int8_t*) jl_data_ptr(v) = *(int8_t*)data; break;
case 2: *(int16_t*) jl_data_ptr(v) = *(int16_t*)data; break;
Expand Down Expand Up @@ -489,7 +489,8 @@ void jl_assign_bits(void *dest, jl_value_t *bits)
jl_ptls_t ptls = jl_get_ptls_states(); \
assert(jl_isbits(t)); \
assert(jl_datatype_size(t) == sizeof(x)); \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), t); \
size_t align = jl_datatype_align(t); \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), align, t);\
*(int##nb##_t*)jl_data_ptr(v) = x; \
return v; \
} \
Expand Down Expand Up @@ -534,7 +535,7 @@ UNBOX_FUNC(voidpointer, void*)
JL_DLLEXPORT jl_value_t *pfx##_##typ(c_type x) \
{ \
jl_ptls_t ptls = jl_get_ptls_states(); \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand All @@ -557,7 +558,7 @@ BOX_FUNC(float64, double, jl_box, 2)
c_type idx = x+NBOX_C/2; \
if ((u##c_type)idx < (u##c_type)NBOX_C) \
return boxed_##typ##_cache[idx]; \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand All @@ -569,7 +570,7 @@ BOX_FUNC(float64, double, jl_box, 2)
jl_ptls_t ptls = jl_get_ptls_states(); \
if (x < NBOX_C) \
return boxed_##typ##_cache[x]; \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand Down Expand Up @@ -650,7 +651,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
va_list args;
size_t nf = jl_datatype_nfields(type);
va_start(args, type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), jl_datatype_align(type), type);
for(size_t i=0; i < nf; i++) {
jl_set_nth_field(jv, i, va_arg(args, jl_value_t*));
}
Expand All @@ -664,7 +665,7 @@ JL_DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args,
jl_ptls_t ptls = jl_get_ptls_states();
if (type->instance != NULL) return type->instance;
size_t nf = jl_datatype_nfields(type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), jl_datatype_align(type), type);
for(size_t i=0; i < na; i++) {
jl_set_nth_field(jv, i, args[i]);
}
Expand All @@ -680,8 +681,9 @@ JL_DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (type->instance != NULL) return type->instance;
size_t size = jl_datatype_size(type);
jl_value_t *jv = jl_gc_alloc(ptls, size, type);
size_t size = jl_datatype_size(type);
size_t align = jl_datatype_align(type);
jl_value_t *jv = jl_gc_alloc(ptls, size, align, type);
if (size > 0)
memset(jl_data_ptr(jv), 0, size);
return jv;
Expand Down
16 changes: 9 additions & 7 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ static jl_value_t *jl_deserialize_value_method(jl_serializer_state *s, jl_value_
{
int usetable = (s->mode != MODE_AST);
jl_method_t *m =
(jl_method_t*)jl_gc_alloc(s->ptls, sizeof(jl_method_t),
(jl_method_t*)jl_gc_alloc(s->ptls, sizeof(jl_method_t), /*align*/ 0,
jl_method_type);
memset(m, 0, sizeof(jl_method_type));
uintptr_t pos = backref_list.len;
Expand Down Expand Up @@ -1766,7 +1766,7 @@ static jl_value_t *jl_deserialize_value_method_instance(jl_serializer_state *s,
{
int usetable = (s->mode != MODE_AST);
jl_method_instance_t *li =
(jl_method_instance_t*)jl_gc_alloc(s->ptls, sizeof(jl_method_instance_t),
(jl_method_instance_t*)jl_gc_alloc(s->ptls, sizeof(jl_method_instance_t), /*align*/ 0,
jl_method_instance_type);
memset(li, 0, sizeof(jl_method_instance_t));
uintptr_t pos = backref_list.len;
Expand Down Expand Up @@ -1928,7 +1928,7 @@ static jl_value_t *jl_deserialize_value_singleton(jl_serializer_state *s, jl_val
jl_datatype_t *dt = (jl_datatype_t*)jl_deserialize_value(s, NULL);
return dt->instance;
}
jl_value_t *v = (jl_value_t*)jl_gc_alloc(s->ptls, 0, NULL);
jl_value_t *v = (jl_value_t*)jl_gc_alloc(s->ptls, 0, 0, NULL);
uintptr_t pos = backref_list.len;
arraylist_push(&backref_list, (void*)v);
if (s->mode == MODE_MODULE) {
Expand Down Expand Up @@ -1984,7 +1984,9 @@ static jl_value_t *jl_deserialize_typemap_entry(jl_serializer_state *s)
jl_value_t *te = jl_nothing;
jl_value_t **pn = &te;
while (n > 0) {
jl_value_t *v = jl_gc_alloc(s->ptls, jl_datatype_size(jl_typemap_entry_type), jl_typemap_entry_type);
jl_value_t *v = jl_gc_alloc(s->ptls, jl_datatype_size(jl_typemap_entry_type),
jl_datatype_align(jl_typemap_entry_type),
jl_typemap_entry_type);
if (n == N && s->mode != MODE_AST)
arraylist_push(&backref_list, v);
jl_deserialize_struct(s, v, 1);
Expand All @@ -2000,7 +2002,7 @@ static jl_value_t *jl_deserialize_value_any(jl_serializer_state *s, jl_value_t *
{
int usetable = (s->mode != MODE_AST);
int32_t sz = (vtag == (jl_value_t*)SmallDataType_tag ? read_uint8(s->s) : read_int32(s->s));
jl_value_t *v = jl_gc_alloc(s->ptls, sz, NULL);
jl_value_t *v = jl_gc_alloc(s->ptls, sz, 0, NULL);
jl_set_typeof(v, (void*)(intptr_t)0x50);
uintptr_t pos = backref_list.len;
if (usetable)
Expand Down Expand Up @@ -2081,7 +2083,7 @@ static jl_value_t *jl_deserialize_value_(jl_serializer_state *s, jl_value_t *vta
return jl_deserialize_value_expr(s, vtag);
}
else if (vtag == (jl_value_t*)jl_tvar_type) {
jl_tvar_t *tv = (jl_tvar_t*)jl_gc_alloc(s->ptls, sizeof(jl_tvar_t), jl_tvar_type);
jl_tvar_t *tv = (jl_tvar_t*)jl_gc_alloc(s->ptls, sizeof(jl_tvar_t), 0, jl_tvar_type);
if (usetable)
arraylist_push(&backref_list, tv);
tv->name = (jl_sym_t*)jl_deserialize_value(s, NULL);
Expand Down Expand Up @@ -2786,7 +2788,7 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ast(jl_method_t *m, jl_array_t *data)
};

jl_code_info_t *code =
(jl_code_info_t*)jl_gc_alloc(ptls, sizeof(jl_code_info_t),
(jl_code_info_t*)jl_gc_alloc(ptls, sizeof(jl_code_info_t), 0,
jl_code_info_type);
uint8_t flags = read_uint8(s.s);
code->inferred = !!(flags & (1 << 3));
Expand Down
16 changes: 8 additions & 8 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ static inline int maybe_collect(jl_ptls_t ptls)
JL_DLLEXPORT jl_weakref_t *jl_gc_new_weakref_th(jl_ptls_t ptls,
jl_value_t *value)
{
jl_weakref_t *wr = (jl_weakref_t*)jl_gc_alloc(ptls, sizeof(void*),
jl_weakref_t *wr = (jl_weakref_t*)jl_gc_alloc(ptls, sizeof(void*), 0,
jl_weakref_type);
wr->value = value; // NOTE: wb not needed here
arraylist_push(&ptls->heap.weak_refs, wr);
Expand Down Expand Up @@ -2571,9 +2571,9 @@ void gc_mark_queue_all_roots(jl_ptls_t ptls, gc_mark_sp_t *sp)

// allocator entry points

JL_DLLEXPORT jl_value_t *(jl_gc_alloc)(jl_ptls_t ptls, size_t sz, void *ty)
JL_DLLEXPORT jl_value_t *(jl_gc_alloc)(jl_ptls_t ptls, size_t sz, size_t alignment, void *ty)
{
return jl_gc_alloc_(ptls, sz, ty);
return jl_gc_alloc_(ptls, sz, alignment, ty);
}

// Per-thread initialization
Expand Down Expand Up @@ -2909,31 +2909,31 @@ JL_DLLEXPORT jl_weakref_t *jl_gc_new_weakref(jl_value_t *value)
JL_DLLEXPORT jl_value_t *jl_gc_allocobj(size_t sz)
{
jl_ptls_t ptls = jl_get_ptls_states();
return jl_gc_alloc(ptls, sz, NULL);
return jl_gc_alloc(ptls, sz, /*align*/ 0, NULL);
}

JL_DLLEXPORT jl_value_t *jl_gc_alloc_0w(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return jl_gc_alloc(ptls, 0, NULL);
return jl_gc_alloc(ptls, 0, 0, NULL);
}

JL_DLLEXPORT jl_value_t *jl_gc_alloc_1w(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return jl_gc_alloc(ptls, sizeof(void*), NULL);
return jl_gc_alloc(ptls, sizeof(void*), 0, NULL);
}

JL_DLLEXPORT jl_value_t *jl_gc_alloc_2w(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return jl_gc_alloc(ptls, sizeof(void*) * 2, NULL);
return jl_gc_alloc(ptls, sizeof(void*) * 2, 0, NULL);
}

JL_DLLEXPORT jl_value_t *jl_gc_alloc_3w(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return jl_gc_alloc(ptls, sizeof(void*) * 3, NULL);
return jl_gc_alloc(ptls, sizeof(void*) * 3, 0, NULL);
}

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
}
jl_compute_field_offsets(dt);
if (para == (jl_value_t*)jl_emptysvec && jl_is_datatype_make_singleton(dt)) {
dt->instance = jl_gc_alloc(ptls, 0, dt);
dt->instance = jl_gc_alloc(ptls, 0, 0, dt);
jl_gc_wb(dt, dt->instance);
}

Expand Down
8 changes: 4 additions & 4 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ JL_DLLEXPORT jl_tvar_t *jl_new_typevar(jl_sym_t *name, jl_value_t *lb, jl_value_
if ((ub != (jl_value_t*)jl_any_type && !jl_is_type(ub) && !jl_is_typevar(ub)) || jl_is_vararg_type(ub))
jl_type_error_rt("TypeVar", "upper bound", (jl_value_t*)jl_type_type, ub);
jl_ptls_t ptls = jl_get_ptls_states();
jl_tvar_t *tv = (jl_tvar_t*)jl_gc_alloc(ptls, sizeof(jl_tvar_t), jl_tvar_type);
jl_tvar_t *tv = (jl_tvar_t*)jl_gc_alloc(ptls, sizeof(jl_tvar_t), /*align*/ 0, jl_tvar_type);
tv->name = name;
tv->lb = lb;
tv->ub = ub;
Expand Down Expand Up @@ -1154,7 +1154,7 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
ndt->layout = dt->layout;
ndt->types = jl_emptysvec;
if (jl_is_datatype_make_singleton(ndt)) {
ndt->instance = jl_gc_alloc(ptls, 0, ndt);
ndt->instance = jl_gc_alloc(ptls, 0, 0, ndt);
jl_gc_wb(ndt, ndt->instance);
}
}
Expand All @@ -1175,7 +1175,7 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
if (cacheable) {
jl_compute_field_offsets(ndt);
if (jl_is_datatype_make_singleton(ndt)) {
ndt->instance = jl_gc_alloc(ptls, 0, ndt);
ndt->instance = jl_gc_alloc(ptls, 0, 0, ndt);
jl_gc_wb(ndt, ndt->instance);
}
}
Expand Down Expand Up @@ -1503,7 +1503,7 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
if (ndt->uid) { // cacheable
jl_compute_field_offsets(ndt);
if (jl_is_datatype_make_singleton(ndt)) {
ndt->instance = jl_gc_alloc(ptls, 0, ndt);
ndt->instance = jl_gc_alloc(ptls, 0, 0, ndt);
jl_gc_wb(ndt, ndt->instance);
}
}
Expand Down
Loading

0 comments on commit 19ee5f9

Please sign in to comment.