Skip to content

Commit ed286e4

Browse files
committed
Introduce JL_HEAP_ALIGNMENT
1 parent 5115a38 commit ed286e4

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

src/cgutils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, jl_unionall_t *ua, bool *isbox
525525
unsigned llvm_alignment = DL.getABITypeAlignment((Type*)jst->struct_decl);
526526
unsigned julia_alignment = jl_datatype_align(jst);
527527
// Check that the alignment adheres to the heap alignment.
528-
assert(julia_alignment <= JL_SMALL_BYTE_ALIGNMENT);
528+
assert(julia_alignment <= JL_HEAP_ALIGNMENT);
529529
// TODO: Fix alignment calculation in LLVM, as well as in the GC and the struct declaration
530-
if (llvm_alignment <= JL_SMALL_BYTE_ALIGNMENT)
530+
if (llvm_alignment <= JL_HEAP_ALIGNMENT)
531531
assert(julia_alignment == llvm_alignment);
532532
}
533533
#endif
@@ -1169,9 +1169,9 @@ static Value *emit_bounds_check(const jl_cgval_t &ainfo, jl_value_t *ty, Value *
11691169
// It is currently unused, but might be used in the future for a more precise answer.
11701170
static unsigned julia_alignment(Value* /*ptr*/, jl_value_t *jltype, unsigned alignment)
11711171
{
1172-
if (!alignment && jl_datatype_align(jltype) > MAX_ALIGN) {
1172+
if (!alignment && jl_datatype_align(jltype) > JL_HEAP_ALIGNMENT) {
11731173
// Type's natural alignment exceeds strictest alignment promised in heap, so return the heap alignment.
1174-
return MAX_ALIGN;
1174+
return JL_HEAP_ALIGNMENT;
11751175
}
11761176
return alignment;
11771177
}

src/datatype.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ void jl_compute_field_offsets(jl_datatype_t *st)
290290
al = fsz;
291291
desc[i].isptr = 1;
292292
}
293+
assert(al <= JL_HEAP_ALIGNMENT && (JL_HEAP_ALIGNMENT % al) == 0);
293294
if (al != 0) {
294295
size_t alsz = LLT_ALIGN(sz, al);
295296
if (sz & (al - 1))
@@ -310,9 +311,9 @@ void jl_compute_field_offsets(jl_datatype_t *st)
310311
// Some tuples become LLVM vectors with stronger alignment than what was calculated above.
311312
unsigned al = jl_special_vector_alignment(nfields, lastty);
312313
assert(al % alignm == 0);
313-
// JL_SMALL_BYTE_ALIGNMENT is the smallest alignment we can guarantee on the heap.
314-
if (al > JL_SMALL_BYTE_ALIGNMENT)
315-
alignm = JL_SMALL_BYTE_ALIGNMENT;
314+
// JL_HEAP_ALIGNMENT is the biggest alignment we can guarantee on the heap.
315+
if (al > JL_HEAP_ALIGNMENT)
316+
alignm = JL_HEAP_ALIGNMENT;
316317
else if (al)
317318
alignm = al;
318319
}

src/gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t sz)
706706
{
707707
maybe_collect(ptls);
708708
size_t offs = offsetof(bigval_t, header);
709+
static_assert(sizeof(bigval_t) % JL_HEAP_ALIGNMENT == 0, "");
709710
size_t allocsz = LLT_ALIGN(sz + offs, JL_CACHE_BYTE_ALIGNMENT);
710711
if (allocsz < sz) // overflow in adding offs, size was "negative"
711712
jl_throw(jl_memory_exception);

src/gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern "C" {
3232

3333
#define GC_PAGE_LG2 14 // log2(size of a page)
3434
#define GC_PAGE_SZ (1 << GC_PAGE_LG2) // 16k
35-
#define GC_PAGE_OFFSET (JL_SMALL_BYTE_ALIGNMENT - (sizeof(jl_taggedvalue_t) % JL_SMALL_BYTE_ALIGNMENT))
35+
#define GC_PAGE_OFFSET (JL_HEAP_ALIGNMENT - (sizeof(jl_taggedvalue_t) % JL_HEAP_ALIGNMENT))
3636

3737
#define jl_malloc_tag ((void*)0xdeadaa01)
3838
#define jl_singleton_tag ((void*)0xdeadaa02)

src/intrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static Value *emit_unbox(Type *to, const jl_cgval_t &x, jl_value_t *jt, Value *d
331331

332332
int alignment;
333333
if (x.isboxed) {
334-
// julia's gc gives 16-byte aligned addresses
334+
// julia's gc gives 16-byte aligned addresses
335335
alignment = 16;
336336
}
337337
else if (jt) {

src/julia_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ STATIC_INLINE int JL_CONST_FUNC jl_gc_szclass(size_t sz)
223223
#endif
224224
#define JL_SMALL_BYTE_ALIGNMENT 16
225225
#define JL_CACHE_BYTE_ALIGNMENT 64
226+
// JL_HEAP_ALIGNMENT is the maximum alignment that the GC can provide
227+
#define JL_HEAP_ALIGNMENT JL_SMALL_BYTE_ALIGNMENT
226228
#define GC_MAX_SZCLASS (2032-sizeof(void*))
227229

228230
STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)

0 commit comments

Comments
 (0)