Skip to content

Commit 0d8bbd9

Browse files
authored
Align up alloc size (#18)
1 parent 98a66ba commit 0d8bbd9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/julia.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,14 @@ STATIC_INLINE void mmtk_gc_wb(const void *parent, const void *ptr) JL_NOTSAFEPOI
24142414
{
24152415
mmtk_gc_wb_fast(parent, ptr);
24162416
}
2417+
2418+
#define MMTK_MIN_ALIGNMENT 4
2419+
// MMTk assumes allocation size is aligned to min alignment.
2420+
STATIC_INLINE size_t mmtk_align_alloc_sz(size_t sz) JL_NOTSAFEPOINT
2421+
{
2422+
return (sz + MMTK_MIN_ALIGNMENT - 1) & ~(MMTK_MIN_ALIGNMENT - 1);
2423+
}
2424+
24172425
#endif
24182426

24192427
#ifdef __cplusplus

src/mmtk-gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ JL_DLLEXPORT void jl_gc_wb2_slow(const void *parent, const void* ptr) JL_NOTSAFE
546546
void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offset)
547547
{
548548
jl_ptls_t ptls = jl_current_task->ptls;
549-
void* addr = mmtk_alloc(&ptls->mmtk_mutator, sz, align, offset, 1);
549+
size_t allocsz = mmtk_align_alloc_sz(sz);
550+
void* addr = mmtk_alloc(&ptls->mmtk_mutator, allocsz, align, offset, 1);
550551
return addr;
551552
}
552553

0 commit comments

Comments
 (0)