Skip to content

Commit f315ca6

Browse files
peterzhu2118matzbot
authored andcommitted
[ruby/mmtk] Respect alignment in rb_mmtk_alloc_fast_path
ruby/mmtk@9772a1d30a
1 parent a4c655e commit f315ca6

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
@@ -813,19 +813,25 @@ rb_gc_impl_get_vm_context(void *objspace_ptr)
813813
// Object allocation
814814

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

821-
uintptr_t new_cursor = bump_pointer->cursor + size;
821+
uintptr_t cursor = bump_pointer->cursor;
822822

823-
if (new_cursor > bump_pointer->limit) {
823+
// Ensure cursor is aligned
824+
size_t mask = align - 1;
825+
cursor = (cursor + mask) & ~mask;
826+
827+
cursor += size;
828+
829+
if (cursor > bump_pointer->limit) {
824830
return 0;
825831
}
826832
else {
827-
VALUE obj = (VALUE)bump_pointer->cursor;
828-
bump_pointer->cursor = new_cursor;
833+
VALUE obj = cursor - size;
834+
bump_pointer->cursor = cursor;
829835
return obj;
830836
}
831837
}
@@ -910,7 +916,7 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
910916
// Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)]
911917
alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE;
912918

913-
VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
919+
VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size, MMTk_MIN_OBJ_ALIGN);
914920
if (!alloc_obj) {
915921
alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
916922
}

0 commit comments

Comments
 (0)