Skip to content

Commit 52616da

Browse files
committed
refactor allocation to take an alignment argument
1 parent ed51793 commit 52616da

21 files changed

+131
-155
lines changed

base/atomics.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using Core.Intrinsics: llvmcall
44

5-
import Base: setindex!, getindex, unsafe_convert
5+
import Base: setindex!, getindex, unsafe_convert, datatype_alignment
66
import Base.Sys: ARCH, WORD_SIZE
77

88
export
@@ -332,9 +332,6 @@ inttype(::Type{Float16}) = Int16
332332
inttype(::Type{Float32}) = Int32
333333
inttype(::Type{Float64}) = Int64
334334

335-
336-
alignment(::Type{T}) where {T} = ccall(:jl_alignment, Cint, (Csize_t,), sizeof(T))
337-
338335
# All atomic operations have acquire and/or release semantics, depending on
339336
# whether the load or store values. Most of the time, this is what one wants
340337
# anyway, and it's only moderately expensive on most hardware.
@@ -346,13 +343,13 @@ for typ in atomictypes
346343
@eval getindex(x::Atomic{$typ}) =
347344
llvmcall($"""
348345
%ptr = inttoptr i$WORD_SIZE %0 to $lt*
349-
%rv = load atomic $rt %ptr acquire, align $(alignment(typ))
346+
%rv = load atomic $rt %ptr acquire, align $(datatype_alignment(typ))
350347
ret $lt %rv
351348
""", $typ, Tuple{Ptr{$typ}}, unsafe_convert(Ptr{$typ}, x))
352349
@eval setindex!(x::Atomic{$typ}, v::$typ) =
353350
llvmcall($"""
354351
%ptr = inttoptr i$WORD_SIZE %0 to $lt*
355-
store atomic $lt %1, $lt* %ptr release, align $(alignment(typ))
352+
store atomic $lt %1, $lt* %ptr release, align $(datatype_alignment(typ))
356353
ret void
357354
""", Void, Tuple{Ptr{$typ}, $typ}, unsafe_convert(Ptr{$typ}, x), v)
358355

src/array.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
9191
size_t doffs = tsz;
9292
tsz += tot;
9393
tsz = JL_ARRAY_ALIGN(tsz, JL_SMALL_BYTE_ALIGNMENT); // align whole object
94-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
94+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, atype);
9595
// No allocation or safepoint allowed after this
9696
a->flags.how = 0;
9797
data = (char*)a + doffs;
@@ -103,7 +103,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
103103
data = jl_gc_managed_malloc(tot);
104104
// Allocate the Array **after** allocating the data
105105
// to make sure the array is still young
106-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
106+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
107107
// No allocation or safepoint allowed after this
108108
a->flags.how = 2;
109109
jl_gc_track_malloced_array(ptls, a);
@@ -183,7 +183,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,
183183

184184
int ndimwords = jl_array_ndimwords(ndims);
185185
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords * sizeof(size_t) + sizeof(void*), JL_SMALL_BYTE_ALIGNMENT);
186-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
186+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, atype);
187187
// No allocation or safepoint allowed after this
188188
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
189189
a->flags.ndims = ndims;
@@ -259,7 +259,7 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
259259

260260
int ndimwords = jl_array_ndimwords(1);
261261
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t) + sizeof(void*), JL_SMALL_BYTE_ALIGNMENT);
262-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, jl_array_uint8_type);
262+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_SMALL_BYTE_ALIGNMENT, jl_array_uint8_type);
263263
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
264264
a->flags.ndims = 1;
265265
a->offset = 0;
@@ -305,7 +305,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data,
305305

306306
int ndimwords = jl_array_ndimwords(1);
307307
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), JL_CACHE_BYTE_ALIGNMENT);
308-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
308+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
309309
// No allocation or safepoint allowed after this
310310
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
311311
a->data = data;
@@ -371,7 +371,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data,
371371

372372
int ndimwords = jl_array_ndimwords(ndims);
373373
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), JL_CACHE_BYTE_ALIGNMENT);
374-
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype);
374+
a = (jl_array_t*)jl_gc_alloc(ptls, tsz, JL_CACHE_BYTE_ALIGNMENT, atype);
375375
// No allocation or safepoint allowed after this
376376
a->flags.pooled = tsz <= GC_MAX_SZCLASS;
377377
a->data = data;
@@ -448,7 +448,7 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
448448

449449
JL_DLLEXPORT jl_value_t *jl_pchar_to_string(const char *str, size_t len)
450450
{
451-
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, jl_string_type);
451+
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, /*align*/ 0, jl_string_type);
452452
*(size_t*)s = len;
453453
memcpy((char*)s + sizeof(size_t), str, len);
454454
((char*)s + sizeof(size_t))[len] = 0;
@@ -457,7 +457,7 @@ JL_DLLEXPORT jl_value_t *jl_pchar_to_string(const char *str, size_t len)
457457

458458
JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len)
459459
{
460-
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, jl_string_type);
460+
jl_value_t *s = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t)+len+1, /*align*/ 0, jl_string_type);
461461
*(size_t*)s = len;
462462
((char*)s + sizeof(size_t))[len] = 0;
463463
return s;

src/builtins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
10011001
jl_ptls_t ptls = jl_get_ptls_states();
10021002
jl_array_t *ar = n==0 ? (jl_array_t*)jl_an_empty_vec_any : jl_alloc_vec_any(n);
10031003
JL_GC_PUSH1(&ar);
1004-
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t),
1004+
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t), /*align*/ 0,
10051005
jl_expr_type);
10061006
ex->head = head;
10071007
ex->args = ar;
@@ -1019,7 +1019,7 @@ JL_CALLABLE(jl_f__expr)
10191019
JL_GC_PUSH1(&ar);
10201020
for(size_t i=0; i < nargs-1; i++)
10211021
jl_array_ptr_set(ar, i, args[i+1]);
1022-
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t),
1022+
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ptls, sizeof(jl_expr_t), /*align*/ 0,
10231023
jl_expr_type);
10241024
ex->head = (jl_sym_t*)args[0];
10251025
ex->args = ar;

src/ccall.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,9 @@ static jl_cgval_t mark_or_box_ccall_result(jl_codectx_t &ctx, Value *result, boo
11421142
const DataLayout &DL = jl_ExecutionEngine->getDataLayout();
11431143
#endif
11441144
unsigned nb = DL.getTypeStoreSize(result->getType());
1145+
unsigned alignment = DL.getPrefTypeAlignment(result->getType());
11451146
MDNode *tbaa = jl_is_mutable(rt) ? tbaa_mutab : tbaa_immut;
1146-
Value *strct = emit_allocobj(ctx, nb, runtime_dt);
1147+
Value *strct = emit_allocobj(ctx, nb, alignment, runtime_dt);
11471148
init_bits_value(ctx, strct, result, tbaa);
11481149
return mark_julia_type(ctx, strct, true, rt);
11491150
}
@@ -1942,7 +1943,7 @@ jl_cgval_t function_sig_t::emit_a_ccall(
19421943
else {
19431944
// XXX: result needs to be zero'd and given a GC root here
19441945
assert(jl_datatype_size(rt) > 0 && "sret shouldn't be a singleton instance");
1945-
result = emit_allocobj(ctx, jl_datatype_size(rt),
1946+
result = emit_allocobj(ctx, jl_datatype_size(rt), jl_datatype_align(rt),
19461947
literal_pointer_val(ctx, (jl_value_t*)rt));
19471948
sretboxed = true;
19481949
}
@@ -2085,10 +2086,10 @@ jl_cgval_t function_sig_t::emit_a_ccall(
20852086
if (static_rt) {
20862087
Value *runtime_bt = literal_pointer_val(ctx, rt);
20872088
size_t rtsz = jl_datatype_size(rt);
2089+
size_t rtal = jl_datatype_align(rt);
20882090
assert(rtsz > 0);
2089-
Value *strct = emit_allocobj(ctx, rtsz, runtime_bt);
2091+
Value *strct = emit_allocobj(ctx, rtsz, rtal, runtime_bt);
20902092
MDNode *tbaa = jl_is_mutable(rt) ? tbaa_mutab : tbaa_immut;
2091-
int boxalign = jl_datatype_align(rt);
20922093
// copy the data from the return value to the new struct
20932094
#if JL_LLVM_VERSION >= 40000
20942095
const DataLayout &DL = jl_data_layout;
@@ -2100,12 +2101,12 @@ jl_cgval_t function_sig_t::emit_a_ccall(
21002101
// ARM and AArch64 can use a LLVM type larger than the julia type.
21012102
// When this happens, cast through memory.
21022103
auto slot = emit_static_alloca(ctx, resultTy);
2103-
slot->setAlignment(boxalign);
2104-
ctx.builder.CreateAlignedStore(result, slot, boxalign);
2105-
emit_memcpy(ctx, strct, slot, rtsz, boxalign, tbaa);
2104+
slot->setAlignment(rtal);
2105+
ctx.builder.CreateAlignedStore(result, slot, rtal);
2106+
emit_memcpy(ctx, strct, slot, rtsz, rtal, tbaa);
21062107
}
21072108
else {
2108-
init_bits_value(ctx, strct, result, tbaa, boxalign);
2109+
init_bits_value(ctx, strct, result, tbaa, rtal);
21092110
}
21102111
return mark_julia_type(ctx, strct, true, rt);
21112112
}

src/cgutils.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ static Value *emit_array_nd_index(
18241824

18251825
// --- boxing ---
18261826

1827-
static Value *emit_allocobj(jl_codectx_t &ctx, size_t static_size, Value *jt);
1827+
static Value *emit_allocobj(jl_codectx_t &ctx, size_t static_size, size_t alignment, Value *jt);
18281828

18291829
static void init_bits_value(jl_codectx_t &ctx, Value *newv, Value *v, MDNode *tbaa,
18301830
unsigned alignment = sizeof(void*)) // min alignment in julia's gc is pointer-aligned
@@ -2067,7 +2067,7 @@ static Value *box_union(jl_codectx_t &ctx, const jl_cgval_t &vinfo, const SmallB
20672067
jl_cgval_t vinfo_r = jl_cgval_t(vinfo, (jl_value_t*)jt, NULL);
20682068
box = _boxed_special(ctx, vinfo_r, t);
20692069
if (!box) {
2070-
box = emit_allocobj(ctx, jl_datatype_size(jt), literal_pointer_val(ctx, (jl_value_t*)jt));
2070+
box = emit_allocobj(ctx, jl_datatype_size(jt), jl_datatype_align(jt), literal_pointer_val(ctx, (jl_value_t*)jt));
20712071
init_bits_cgval(ctx, box, vinfo_r, jl_is_mutable(jt) ? tbaa_mutab : tbaa_immut);
20722072
}
20732073
}
@@ -2125,7 +2125,7 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo)
21252125
assert(!type_is_ghost(t)); // ghost values should have been handled by vinfo.constant above!
21262126
box = _boxed_special(ctx, vinfo, t);
21272127
if (!box) {
2128-
box = emit_allocobj(ctx, jl_datatype_size(jt), literal_pointer_val(ctx, (jl_value_t*)jt));
2128+
box = emit_allocobj(ctx, jl_datatype_size(jt), jl_datatype_align(jt), literal_pointer_val(ctx, (jl_value_t*)jt));
21292129
init_bits_cgval(ctx, box, vinfo, jl_is_mutable(jt) ? tbaa_mutab : tbaa_immut);
21302130
}
21312131
else {
@@ -2226,11 +2226,12 @@ static void emit_cpointercheck(jl_codectx_t &ctx, const jl_cgval_t &x, const std
22262226
}
22272227

22282228
// allocation for known size object
2229-
static Value *emit_allocobj(jl_codectx_t &ctx, size_t static_size, Value *jt)
2229+
static Value *emit_allocobj(jl_codectx_t &ctx, size_t static_size, size_t alignment, Value *jt)
22302230
{
22312231
Value *ptls_ptr = emit_bitcast(ctx, ctx.ptlsStates, T_pint8);
22322232
auto call = ctx.builder.CreateCall(prepare_call(jl_alloc_obj_func),
22332233
{ptls_ptr, ConstantInt::get(T_size, static_size),
2234+
ConstantInt::get(T_size, alignment),
22342235
maybe_decay_untracked(jt)});
22352236
call->setAttributes(jl_alloc_obj_func->getAttributes());
22362237
return call;
@@ -2409,7 +2410,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
24092410
else
24102411
return mark_julia_slot(strct, ty, NULL, tbaa_stack);
24112412
}
2412-
Value *strct = emit_allocobj(ctx, jl_datatype_size(sty),
2413+
Value *strct = emit_allocobj(ctx, jl_datatype_size(sty), jl_datatype_align(sty),
24132414
literal_pointer_val(ctx, (jl_value_t*)ty));
24142415
jl_cgval_t strctinfo = mark_julia_type(ctx, strct, true, ty);
24152416
for (size_t i = 0; i < nf; i++) {

src/codegen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,7 @@ static void emit_cfunc_invalidate(
40564056
}
40574057
case jl_returninfo_t::SRet: {
40584058
unsigned sret_nbytes = jl_datatype_size(astrt);
4059-
emit_memcpy(ctx, &*gf_thunk->arg_begin(), gf_ret, sret_nbytes, jl_alignment(sret_nbytes));
4059+
emit_memcpy(ctx, &*gf_thunk->arg_begin(), gf_ret, sret_nbytes, jl_datatype_align(astrt));
40604060
ctx.builder.CreateRetVoid();
40614061
break;
40624062
}
@@ -4240,7 +4240,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t
42404240
(void)julia_type_to_llvm(jargty, &isboxed);
42414241
if (isboxed) {
42424242
// passed an unboxed T, but want something boxed
4243-
Value *mem = emit_allocobj(ctx, jl_datatype_size(jargty),
4243+
Value *mem = emit_allocobj(ctx, jl_datatype_size(jargty), jl_datatype_align(jargty),
42444244
literal_pointer_val(ctx, (jl_value_t*)jargty));
42454245
tbaa_decorate(jl_is_mutable(jargty) ? tbaa_mutab : tbaa_immut,
42464246
ctx.builder.CreateAlignedStore(val,
@@ -6493,6 +6493,7 @@ static void init_julia_llvm_env(Module *m)
64936493
std::vector<Type*> gc_alloc_args(0);
64946494
gc_alloc_args.push_back(T_pint8);
64956495
gc_alloc_args.push_back(T_size);
6496+
gc_alloc_args.push_back(T_size);
64966497
gc_alloc_args.push_back(T_prjlvalue);
64976498
jl_alloc_obj_func = Function::Create(FunctionType::get(T_prjlvalue, gc_alloc_args, false),
64986499
Function::ExternalLinkage,

src/datatype.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
3636
{
3737
jl_ptls_t ptls = jl_get_ptls_states();
3838
jl_methtable_t *mt =
39-
(jl_methtable_t*)jl_gc_alloc(ptls, sizeof(jl_methtable_t),
39+
(jl_methtable_t*)jl_gc_alloc(ptls, sizeof(jl_methtable_t), 0,
4040
jl_methtable_type);
4141
mt->name = jl_demangle_typename(name);
4242
mt->module = module;
@@ -53,7 +53,7 @@ JL_DLLEXPORT jl_typename_t *jl_new_typename_in(jl_sym_t *name, jl_module_t *modu
5353
{
5454
jl_ptls_t ptls = jl_get_ptls_states();
5555
jl_typename_t *tn =
56-
(jl_typename_t*)jl_gc_alloc(ptls, sizeof(jl_typename_t),
56+
(jl_typename_t*)jl_gc_alloc(ptls, sizeof(jl_typename_t), 0,
5757
jl_typename_type);
5858
tn->name = name;
5959
tn->module = module;
@@ -76,7 +76,7 @@ jl_datatype_t *jl_new_abstracttype(jl_value_t *name, jl_module_t *module, jl_dat
7676
jl_datatype_t *jl_new_uninitialized_datatype(void)
7777
{
7878
jl_ptls_t ptls = jl_get_ptls_states();
79-
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ptls, sizeof(jl_datatype_t), jl_datatype_type);
79+
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ptls, sizeof(jl_datatype_t), 0, jl_datatype_type);
8080
t->depth = 0;
8181
t->hasfreetypevars = 0;
8282
t->isleaftype = 1;
@@ -225,7 +225,7 @@ STATIC_INLINE int jl_is_datatype_make_singleton(jl_datatype_t *d)
225225
STATIC_INLINE void jl_allocate_singleton_instance(jl_datatype_t *st)
226226
{
227227
if (jl_is_datatype_make_singleton(st)) {
228-
st->instance = jl_gc_alloc(jl_get_ptls_states(), 0, st);
228+
st->instance = jl_gc_alloc(jl_get_ptls_states(), 0, 0, st);
229229
jl_gc_wb(st, st->instance);
230230
}
231231
}
@@ -504,7 +504,7 @@ JL_DLLEXPORT jl_value_t *jl_new_bits(jl_value_t *dt, void *data)
504504
if (bt == jl_int32_type) return jl_box_int32(*(int32_t*)data);
505505
if (bt == jl_float64_type) return jl_box_float64(*(double*)data);
506506

507-
jl_value_t *v = jl_gc_alloc(ptls, nb, bt);
507+
jl_value_t *v = jl_gc_alloc(ptls, nb, jl_datatype_align(bt), bt);
508508
switch (nb) {
509509
case 1: *(int8_t*) jl_data_ptr(v) = *(int8_t*)data; break;
510510
case 2: *(int16_t*) jl_data_ptr(v) = *(int16_t*)data; break;
@@ -520,7 +520,7 @@ JL_DLLEXPORT jl_value_t *jl_new_bits(jl_value_t *dt, void *data)
520520
JL_DLLEXPORT jl_value_t *jl_typemax_uint(jl_value_t *bt)
521521
{
522522
uint64_t data = 0xffffffffffffffffULL;
523-
jl_value_t *v = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t), bt);
523+
jl_value_t *v = jl_gc_alloc(jl_get_ptls_states(), sizeof(size_t), 0, bt);
524524
memcpy(jl_data_ptr(v), &data, sizeof(size_t));
525525
return v;
526526
}
@@ -545,7 +545,8 @@ void jl_assign_bits(void *dest, jl_value_t *bits)
545545
jl_ptls_t ptls = jl_get_ptls_states(); \
546546
assert(jl_isbits(t)); \
547547
assert(jl_datatype_size(t) == sizeof(x)); \
548-
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), t); \
548+
size_t align = jl_datatype_align(t); \
549+
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), align, t);\
549550
*(int##nb##_t*)jl_data_ptr(v) = x; \
550551
return v; \
551552
} \
@@ -590,7 +591,7 @@ UNBOX_FUNC(voidpointer, void*)
590591
JL_DLLEXPORT jl_value_t *pfx##_##typ(c_type x) \
591592
{ \
592593
jl_ptls_t ptls = jl_get_ptls_states(); \
593-
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
594+
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
594595
jl_##typ##_type); \
595596
*(c_type*)jl_data_ptr(v) = x; \
596597
return v; \
@@ -613,7 +614,7 @@ BOX_FUNC(float64, double, jl_box, 2)
613614
c_type idx = x+NBOX_C/2; \
614615
if ((u##c_type)idx < (u##c_type)NBOX_C) \
615616
return boxed_##typ##_cache[idx]; \
616-
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
617+
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
617618
jl_##typ##_type); \
618619
*(c_type*)jl_data_ptr(v) = x; \
619620
return v; \
@@ -625,7 +626,7 @@ BOX_FUNC(float64, double, jl_box, 2)
625626
jl_ptls_t ptls = jl_get_ptls_states(); \
626627
if (x < NBOX_C) \
627628
return boxed_##typ##_cache[x]; \
628-
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), \
629+
jl_value_t *v = jl_gc_alloc(ptls, nw * sizeof(void*), 0,\
629630
jl_##typ##_type); \
630631
*(c_type*)jl_data_ptr(v) = x; \
631632
return v; \
@@ -706,7 +707,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
706707
va_list args;
707708
size_t nf = jl_datatype_nfields(type);
708709
va_start(args, type);
709-
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
710+
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), jl_datatype_align(type), type);
710711
for (size_t i = 0; i < nf; i++) {
711712
jl_set_nth_field(jv, i, va_arg(args, jl_value_t*));
712713
}
@@ -720,7 +721,7 @@ JL_DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args,
720721
jl_ptls_t ptls = jl_get_ptls_states();
721722
if (type->instance != NULL) return type->instance;
722723
size_t nf = jl_datatype_nfields(type);
723-
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
724+
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), jl_datatype_align(type), type);
724725
for (size_t i = 0; i < na; i++) {
725726
jl_value_t *ft = jl_field_type(type, i);
726727
if (!jl_isa(args[i], ft))
@@ -739,8 +740,9 @@ JL_DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
739740
{
740741
jl_ptls_t ptls = jl_get_ptls_states();
741742
if (type->instance != NULL) return type->instance;
742-
size_t size = jl_datatype_size(type);
743-
jl_value_t *jv = jl_gc_alloc(ptls, size, type);
743+
size_t size = jl_datatype_size(type);
744+
size_t align = jl_datatype_align(type);
745+
jl_value_t *jv = jl_gc_alloc(ptls, size, align, type);
744746
if (size > 0)
745747
memset(jl_data_ptr(jv), 0, size);
746748
return jv;

0 commit comments

Comments
 (0)