Merge rb_objspace_alloc and Init_heap.

Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
This commit is contained in:
Matt Valentine-House 2024-04-03 20:46:30 +01:00
Родитель 3ac6a03b2e
Коммит ef19234b10
4 изменённых файлов: 32 добавлений и 42 удалений

1
eval.c
Просмотреть файл

@ -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();

68
gc.c
Просмотреть файл

@ -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);
@ -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. */
@ -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 *);

Просмотреть файл

@ -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);

2
vm.c
Просмотреть файл

@ -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);