Skip to content

Commit

Permalink
Merge rb_objspace_alloc and Init_heap.
Browse files Browse the repository at this point in the history
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
  • Loading branch information
eightbitraptor and peterzhu2118 committed Apr 4, 2024
1 parent 3ac6a03 commit ef19234
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 42 deletions.
1 change: 0 additions & 1 deletion eval.c
Expand Up @@ -78,7 +78,6 @@ ruby_setup(void)
prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
#endif
Init_BareVM();
Init_heap();
rb_vm_encoded_insn_data_table_init();
Init_vm_objects();

Expand Down
68 changes: 31 additions & 37 deletions gc.c
Expand Up @@ -1884,40 +1884,6 @@ rb_gc_initial_stress_set(VALUE flag)
initial_stress = flag;
}

rb_objspace_t *
rb_objspace_alloc(void)
{
rb_objspace_t *objspace = calloc1(sizeof(rb_objspace_t));

objspace->flags.gc_stressful = RTEST(initial_stress);
objspace->gc_stress_mode = initial_stress;

objspace->flags.measure_gc = 1;
malloc_limit = gc_params.malloc_limit_min;
objspace->finalize_deferred_pjob = rb_postponed_job_preregister(0, gc_finalize_deferred, objspace);
if (objspace->finalize_deferred_pjob == POSTPONED_JOB_HANDLE_INVALID) {
rb_bug("Could not preregister postponed job for GC");
}

for (int i = 0; i < SIZE_POOL_COUNT; i++) {
rb_size_pool_t *size_pool = &size_pools[i];

size_pool->slot_size = (1 << i) * BASE_SLOT_SIZE;

ccan_list_head_init(&SIZE_POOL_EDEN_HEAP(size_pool)->pages);
ccan_list_head_init(&SIZE_POOL_TOMB_HEAP(size_pool)->pages);
}

rb_darray_make(&objspace->weak_references, 0);

// TODO: debug why on Windows Ruby crashes on boot when GC is on.
#ifdef _WIN32
dont_gc_on();
#endif

return objspace;
}

static void free_stack_chunks(mark_stack_t *);
static void mark_stack_free_cache(mark_stack_t *);
static void heap_page_free(rb_objspace_t *objspace, struct heap_page *page);
Expand Down Expand Up @@ -3523,10 +3489,37 @@ static const struct st_hash_type object_id_hash_type = {
object_id_hash,
};

void
Init_heap(void)
rb_objspace_t *
rb_objspace_alloc(void)
{
rb_objspace_t *objspace = &rb_objspace;
rb_objspace_t *objspace = calloc1(sizeof(rb_objspace_t));
ruby_current_vm_ptr->objspace = objspace;

objspace->flags.gc_stressful = RTEST(initial_stress);
objspace->gc_stress_mode = initial_stress;

objspace->flags.measure_gc = 1;
malloc_limit = gc_params.malloc_limit_min;
objspace->finalize_deferred_pjob = rb_postponed_job_preregister(0, gc_finalize_deferred, objspace);
if (objspace->finalize_deferred_pjob == POSTPONED_JOB_HANDLE_INVALID) {
rb_bug("Could not preregister postponed job for GC");
}

for (int i = 0; i < SIZE_POOL_COUNT; i++) {
rb_size_pool_t *size_pool = &size_pools[i];

size_pool->slot_size = (1 << i) * BASE_SLOT_SIZE;

ccan_list_head_init(&SIZE_POOL_EDEN_HEAP(size_pool)->pages);
ccan_list_head_init(&SIZE_POOL_TOMB_HEAP(size_pool)->pages);
}

rb_darray_make(&objspace->weak_references, 0);

// TODO: debug why on Windows Ruby crashes on boot when GC is on.
#ifdef _WIN32
dont_gc_on();
#endif

#if defined(INIT_HEAP_PAGE_ALLOC_USE_MMAP)
/* Need to determine if we can use mmap at runtime. */
Expand Down Expand Up @@ -3556,6 +3549,7 @@ Init_heap(void)

objspace->profile.invoke_time = getrusage_time();
finalizer_table = st_init_numtable();
return objspace;
}

typedef int each_obj_callback(void *, void *, size_t, void *);
Expand Down
3 changes: 0 additions & 3 deletions internal/inits.h
Expand Up @@ -19,9 +19,6 @@ void Init_ext(void);
/* file.c */
void Init_File(void);

/* gc.c */
void Init_heap(void);

/* localeinit.c */
int Init_enc_set_filesystem_encoding(void);

Expand Down
2 changes: 1 addition & 1 deletion vm.c
Expand Up @@ -4244,7 +4244,7 @@ Init_BareVM(void)

rb_vm_postponed_job_queue_init(vm);
ruby_current_vm_ptr = vm;
vm->objspace = rb_objspace_alloc();
rb_objspace_alloc();
vm->negative_cme_table = rb_id_table_create(16);
vm->overloaded_cme_table = st_init_numtable();
vm->constant_cache = rb_id_table_create(0);
Expand Down

0 comments on commit ef19234

Please sign in to comment.