@@ -114,20 +114,25 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
114114 }
115115
116116 int ndimwords = jl_array_ndimwords (ndims );
117- int tsz = JL_ARRAY_ALIGN ( sizeof (jl_array_t ) + ndimwords * sizeof (size_t ), JL_CACHE_BYTE_ALIGNMENT );
117+ int tsz = sizeof (jl_array_t ) + ndimwords * sizeof (size_t );
118118 if (tot <= ARRAY_INLINE_NBYTES ) {
119+ // align data area
119120 if (isunboxed && elsz >= 4 )
120- tsz = JL_ARRAY_ALIGN (tsz , JL_SMALL_BYTE_ALIGNMENT ); // align data area
121+ tsz = JL_ARRAY_ALIGN (tsz , JL_SMALL_BYTE_ALIGNMENT );
122+ if (tsz + tot > GC_MAX_SZCLASS ) {
123+ // object won't be pool allocated, so take advantage of larger alignment
124+ tsz = JL_ARRAY_ALIGN (tsz , JL_CACHE_BYTE_ALIGNMENT );
125+ }
121126 size_t doffs = tsz ;
122127 tsz += tot ;
123- tsz = JL_ARRAY_ALIGN ( tsz , JL_SMALL_BYTE_ALIGNMENT ); // align whole object
128+ // jl_array_t is large enough that objects will always be aligned 16
124129 a = (jl_array_t * )jl_gc_alloc (ct -> ptls , tsz , atype );
130+ assert (((size_t )a & 15 ) == 0 );
125131 // No allocation or safepoint allowed after this
126132 a -> flags .how = 0 ;
127133 data = (char * )a + doffs ;
128134 }
129135 else {
130- tsz = JL_ARRAY_ALIGN (tsz , JL_CACHE_BYTE_ALIGNMENT ); // align whole object
131136 data = jl_gc_managed_malloc (tot );
132137 // Allocate the Array **after** allocating the data
133138 // to make sure the array is still young
@@ -223,7 +228,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,
223228 assert (jl_types_equal (jl_tparam0 (jl_typeof (data )), jl_tparam0 (atype )));
224229
225230 int ndimwords = jl_array_ndimwords (ndims );
226- int tsz = JL_ARRAY_ALIGN ( sizeof (jl_array_t ) + ndimwords * sizeof (size_t ) + sizeof (void * ), JL_SMALL_BYTE_ALIGNMENT );
231+ int tsz = sizeof (jl_array_t ) + ndimwords * sizeof (size_t ) + sizeof (void * );
227232 a = (jl_array_t * )jl_gc_alloc (ct -> ptls , tsz , atype );
228233 // No allocation or safepoint allowed after this
229234 a -> flags .pooled = tsz <= GC_MAX_SZCLASS ;
@@ -304,7 +309,7 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
304309 jl_array_t * a ;
305310
306311 int ndimwords = jl_array_ndimwords (1 );
307- int tsz = JL_ARRAY_ALIGN ( sizeof (jl_array_t ) + ndimwords * sizeof (size_t ) + sizeof (void * ), JL_SMALL_BYTE_ALIGNMENT );
312+ int tsz = sizeof (jl_array_t ) + ndimwords * sizeof (size_t ) + sizeof (void * );
308313 a = (jl_array_t * )jl_gc_alloc (ct -> ptls , tsz , jl_array_uint8_type );
309314 a -> flags .pooled = tsz <= GC_MAX_SZCLASS ;
310315 a -> flags .ndims = 1 ;
@@ -351,7 +356,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data,
351356 "unsafe_wrap: pointer %p is not properly aligned to %u bytes" , data , align );
352357
353358 int ndimwords = jl_array_ndimwords (1 );
354- int tsz = JL_ARRAY_ALIGN ( sizeof (jl_array_t ) + ndimwords * sizeof (size_t ), JL_CACHE_BYTE_ALIGNMENT );
359+ int tsz = sizeof (jl_array_t ) + ndimwords * sizeof (size_t );
355360 a = (jl_array_t * )jl_gc_alloc (ct -> ptls , tsz , atype );
356361 // No allocation or safepoint allowed after this
357362 a -> flags .pooled = tsz <= GC_MAX_SZCLASS ;
@@ -418,7 +423,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data,
418423 "unsafe_wrap: pointer %p is not properly aligned to %u bytes" , data , align );
419424
420425 int ndimwords = jl_array_ndimwords (ndims );
421- int tsz = JL_ARRAY_ALIGN ( sizeof (jl_array_t ) + ndimwords * sizeof (size_t ), JL_CACHE_BYTE_ALIGNMENT );
426+ int tsz = sizeof (jl_array_t ) + ndimwords * sizeof (size_t );
422427 a = (jl_array_t * )jl_gc_alloc (ct -> ptls , tsz , atype );
423428 // No allocation or safepoint allowed after this
424429 a -> flags .pooled = tsz <= GC_MAX_SZCLASS ;
0 commit comments