summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2026-01-31 11:02:17 +0100
committerJean Boussier <jean.boussier@gmail.com>2026-01-31 17:54:33 +0100
commit9cc71cb9093caa7ee471def8aa8f0de596e366cf (patch)
tree500dac8f1cc2d635405134f40a590c2c87444ee4 /vm.c
parent0b4b30af9e09be12960ad1e9aff89b195b7c3734 (diff)
Use static memory instead of mimalloc for the VM, main ractor, main thread.
Also allocate fibers with ruby_xmalloc.
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/vm.c b/vm.c
index 05d2025a12..264bdfa1f2 100644
--- a/vm.c
+++ b/vm.c
@@ -3392,8 +3392,6 @@ ruby_vm_destruct(rb_vm_t *vm)
st_free_table(vm->static_ext_inits);
- rb_vm_postponed_job_free();
-
rb_id_table_free(vm->constant_cache);
set_free_table(vm->unused_block_warning_table);
@@ -3433,14 +3431,11 @@ ruby_vm_destruct(rb_vm_t *vm)
rb_objspace_free_objects(objspace);
rb_free_generic_fields_tbl_();
rb_free_default_rand_key();
-
- ruby_mimfree(th);
}
rb_objspace_free(objspace);
}
rb_native_mutex_destroy(&vm->workqueue_lock);
/* after freeing objspace, you *can't* use ruby_xfree() */
- ruby_mimfree(vm);
ruby_current_vm_ptr = NULL;
if (rb_free_at_exit) {
@@ -3785,7 +3780,7 @@ thread_mark(void *ptr)
rb_gc_mark(th->top_wrapper);
if (th->root_fiber) rb_fiber_mark_self(th->root_fiber);
- RUBY_ASSERT(th->ec == rb_fiberptr_get_ec(th->ec->fiber_ptr));
+ RUBY_ASSERT(th->ec == NULL || th->ec == rb_fiberptr_get_ec(th->ec->fiber_ptr));
rb_gc_mark(th->last_status);
rb_gc_mark(th->locking_mutex);
rb_gc_mark(th->name);
@@ -3822,10 +3817,7 @@ thread_free(void *ptr)
else {
// ruby_xfree(th->nt);
// TODO: MN system collect nt, but without MN system it should be freed here.
- if (th->main_thread) {
- ruby_mimfree(th);
- }
- else {
+ if (!th->main_thread) {
ruby_xfree(th);
}
}
@@ -4576,12 +4568,15 @@ rb_vm_set_progname(VALUE filename)
extern const struct st_hash_type rb_fstring_hash_type;
+static rb_vm_t _vm;
+static rb_thread_t _main_thread = { .main_thread = 1 };
+
void
Init_BareVM(void)
{
/* VM bootstrap: phase 1 */
- rb_vm_t *vm = ruby_mimcalloc(1, sizeof(*vm));
- rb_thread_t *th = ruby_mimcalloc(1, sizeof(*th));
+ rb_vm_t *vm = &_vm;
+ rb_thread_t *th = &_main_thread;
if (!vm || !th) {
fputs("[FATAL] failed to allocate memory\n", stderr);
exit(EXIT_FAILURE);
@@ -4590,7 +4585,6 @@ Init_BareVM(void)
// setup the VM
vm_init2(vm);
- rb_vm_postponed_job_queue_init(vm);
ruby_current_vm_ptr = vm;
rb_objspace_alloc();
vm->negative_cme_table = rb_id_table_create(16);
@@ -4600,7 +4594,6 @@ Init_BareVM(void)
vm->global_hooks.type = hook_list_type_global;
// setup main thread
- th->main_thread = 1;
th->nt = ZALLOC(struct rb_native_thread);
th->vm = vm;
th->ractor = vm->ractor.main_ractor = rb_ractor_main_alloc();