Skip to content

Commit 9772a1d

Browse files
committed
Respect alignment in rb_mmtk_alloc_fast_path
1 parent e5f68d8 commit 9772a1d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

gc/mmtk/mmtk.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,19 +815,25 @@ rb_gc_impl_get_vm_context(void *objspace_ptr)
815815
// Object allocation
816816

817817
static VALUE
818-
rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size)
818+
rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size, size_t align)
819819
{
820820
MMTk_BumpPointer *bump_pointer = ractor_cache->bump_pointer;
821821
if (bump_pointer == NULL) return 0;
822822

823-
uintptr_t new_cursor = bump_pointer->cursor + size;
823+
uintptr_t cursor = bump_pointer->cursor;
824824

825-
if (new_cursor > bump_pointer->limit) {
825+
// Ensure cursor is aligned
826+
size_t mask = align - 1;
827+
cursor = (cursor + mask) & ~mask;
828+
829+
cursor += size;
830+
831+
if (cursor > bump_pointer->limit) {
826832
return 0;
827833
}
828834
else {
829-
VALUE obj = (VALUE)bump_pointer->cursor;
830-
bump_pointer->cursor = new_cursor;
835+
VALUE obj = cursor - size;
836+
bump_pointer->cursor = cursor;
831837
return obj;
832838
}
833839
}
@@ -912,7 +918,7 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
912918
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)]
913919
alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE;
914920

915-
VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
921+
VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size, MMTk_MIN_OBJ_ALIGN);
916922
if (!alloc_obj) {
917923
alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
918924
}

0 commit comments

Comments
 (0)