Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,21 @@ void rb_gc_impl_set_params(void *objspace_ptr) { }

static VALUE gc_verify_internal_consistency(VALUE self) { return Qnil; }

#define MMTK_HEAP_COUNT 5
#define MMTK_MAX_OBJ_SIZE 640

static size_t heap_sizes[MMTK_HEAP_COUNT + 1] = {
40, 80, 160, 320, MMTK_MAX_OBJ_SIZE, 0
};

void
rb_gc_impl_init(void)
{
VALUE gc_constants = rb_hash_new();
rb_hash_aset(gc_constants, ID2SYM(rb_intern("BASE_SLOT_SIZE")), SIZET2NUM(sizeof(VALUE) * 5));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RBASIC_SIZE")), SIZET2NUM(sizeof(struct RBasic)));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_OVERHEAD")), INT2NUM(0));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVARGC_MAX_ALLOCATE_SIZE")), LONG2FIX(640));
rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVARGC_MAX_ALLOCATE_SIZE")), LONG2FIX(MMTK_MAX_OBJ_SIZE));
// Pretend we have 5 size pools
rb_hash_aset(gc_constants, ID2SYM(rb_intern("SIZE_POOL_COUNT")), LONG2FIX(5));
OBJ_FREEZE(gc_constants);
Expand All @@ -485,10 +492,6 @@ rb_gc_impl_init(void)
rb_define_singleton_method(rb_mGC, "verify_compaction_references", rb_f_notimplement, -1);
}

static size_t heap_sizes[6] = {
40, 80, 160, 320, 640, 0
};

size_t *
rb_gc_impl_heap_sizes(void *objspace_ptr)
{
Expand Down Expand Up @@ -609,8 +612,8 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
struct objspace *objspace = objspace_ptr;
struct MMTk_ractor_cache *ractor_cache = cache_ptr;

if (alloc_size > 640) rb_bug("too big");
for (int i = 0; i < 5; i++) {
if (alloc_size > MMTK_MAX_OBJ_SIZE) rb_bug("too big");
for (int i = 0; i < MMTK_HEAP_COUNT; i++) {
if (alloc_size == heap_sizes[i]) break;
if (alloc_size < heap_sizes[i]) {
alloc_size = heap_sizes[i];
Expand Down Expand Up @@ -658,7 +661,7 @@ rb_gc_impl_heap_id_for_size(void *objspace_ptr, size_t size)
bool
rb_gc_impl_size_allocatable_p(size_t size)
{
return size <= 640;
return size <= MMTK_MAX_OBJ_SIZE;
}

// Malloc
Expand Down