Merge rb_objspace_alloc and Init_heap.
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
This commit is contained in:
parent
3ac6a03b2e
commit
ef19234b10
1
eval.c
1
eval.c
@ -78,7 +78,6 @@ ruby_setup(void)
|
|||||||
prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
|
prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
Init_BareVM();
|
Init_BareVM();
|
||||||
Init_heap();
|
|
||||||
rb_vm_encoded_insn_data_table_init();
|
rb_vm_encoded_insn_data_table_init();
|
||||||
Init_vm_objects();
|
Init_vm_objects();
|
||||||
|
|
||||||
|
68
gc.c
68
gc.c
@ -1884,40 +1884,6 @@ rb_gc_initial_stress_set(VALUE flag)
|
|||||||
initial_stress = 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 free_stack_chunks(mark_stack_t *);
|
||||||
static void mark_stack_free_cache(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);
|
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,
|
object_id_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
rb_objspace_t *
|
||||||
Init_heap(void)
|
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)
|
#if defined(INIT_HEAP_PAGE_ALLOC_USE_MMAP)
|
||||||
/* Need to determine if we can use mmap at runtime. */
|
/* Need to determine if we can use mmap at runtime. */
|
||||||
@ -3556,6 +3549,7 @@ Init_heap(void)
|
|||||||
|
|
||||||
objspace->profile.invoke_time = getrusage_time();
|
objspace->profile.invoke_time = getrusage_time();
|
||||||
finalizer_table = st_init_numtable();
|
finalizer_table = st_init_numtable();
|
||||||
|
return objspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int each_obj_callback(void *, void *, size_t, void *);
|
typedef int each_obj_callback(void *, void *, size_t, void *);
|
||||||
|
@ -19,9 +19,6 @@ void Init_ext(void);
|
|||||||
/* file.c */
|
/* file.c */
|
||||||
void Init_File(void);
|
void Init_File(void);
|
||||||
|
|
||||||
/* gc.c */
|
|
||||||
void Init_heap(void);
|
|
||||||
|
|
||||||
/* localeinit.c */
|
/* localeinit.c */
|
||||||
int Init_enc_set_filesystem_encoding(void);
|
int Init_enc_set_filesystem_encoding(void);
|
||||||
|
|
||||||
|
2
vm.c
2
vm.c
@ -4244,7 +4244,7 @@ Init_BareVM(void)
|
|||||||
|
|
||||||
rb_vm_postponed_job_queue_init(vm);
|
rb_vm_postponed_job_queue_init(vm);
|
||||||
ruby_current_vm_ptr = vm;
|
ruby_current_vm_ptr = vm;
|
||||||
vm->objspace = rb_objspace_alloc();
|
rb_objspace_alloc();
|
||||||
vm->negative_cme_table = rb_id_table_create(16);
|
vm->negative_cme_table = rb_id_table_create(16);
|
||||||
vm->overloaded_cme_table = st_init_numtable();
|
vm->overloaded_cme_table = st_init_numtable();
|
||||||
vm->constant_cache = rb_id_table_create(0);
|
vm->constant_cache = rb_id_table_create(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user