From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AC6FD1F454 for ; Sat, 18 Jul 2015 07:42:26 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] remove mimmalloc/mimfree for vm and main thread Date: Sat, 18 Jul 2015 07:42:26 +0000 Message-Id: <1437205346-19622-1-git-send-email-e@80x24.org> List-Id: MVM probably will not happen. Even if MVM proceeds, any process (at least on *nix) will always have at least one VM and one thread. Instead of hitting the heap so early on and having a specialized malloc, use the text area of a process to simplify code and potentially allow sighandler to work without wasting syscalls during shutdown. --- gc.c | 29 ----------------------------- internal.h | 2 -- vm.c | 15 +++++---------- 3 files changed, 5 insertions(+), 41 deletions(-) diff --git a/gc.c b/gc.c index 2bb5f7a..97228c9 100644 --- a/gc.c +++ b/gc.c @@ -7723,35 +7723,6 @@ ruby_xfree(void *x) ruby_sized_xfree(x, 0); } -/* Mimic ruby_xmalloc, but need not rb_objspace. - * should return pointer suitable for ruby_xfree - */ -void * -ruby_mimmalloc(size_t size) -{ - void *mem; -#if CALC_EXACT_MALLOC_SIZE - size += sizeof(size_t); -#endif - mem = malloc(size); -#if CALC_EXACT_MALLOC_SIZE - /* set 0 for consistency of allocated_size/allocations */ - ((size_t *)mem)[0] = 0; - mem = (size_t *)mem + 1; -#endif - return mem; -} - -void -ruby_mimfree(void *ptr) -{ - size_t *mem = (size_t *)ptr; -#if CALC_EXACT_MALLOC_SIZE - mem = mem - 1; -#endif - free(mem); -} - #if MALLOC_ALLOCATED_SIZE /* * call-seq: diff --git a/internal.h b/internal.h index c91d8ca..185a09f 100644 --- a/internal.h +++ b/internal.h @@ -802,8 +802,6 @@ NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path) extern VALUE *ruby_initial_gc_stress_ptr; extern int ruby_disable_gc; void Init_heap(void); -void *ruby_mimmalloc(size_t size); -void ruby_mimfree(void *ptr); void rb_objspace_set_event_hook(const rb_event_flag_t event); #if USE_RGENGC void rb_gc_writebarrier_remember(VALUE obj); diff --git a/vm.c b/vm.c index bbd5320..986f547 100644 --- a/vm.c +++ b/vm.c @@ -1878,11 +1878,11 @@ ruby_vm_destruct(rb_vm_t *vm) #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE struct rb_objspace *objspace = vm->objspace; #endif - vm->main_thread = 0; if (th) { rb_fiber_reset_root_local_storage(th->self); thread_free(th); } + vm->main_thread = 0; rb_vm_living_threads_init(vm); ruby_vm_run_at_exit_hooks(vm); rb_vm_gvl_destroy(vm); @@ -1891,8 +1891,6 @@ ruby_vm_destruct(rb_vm_t *vm) rb_objspace_free(objspace); } #endif - /* after freeing objspace, you *can't* use ruby_xfree() */ - ruby_mimfree(vm); ruby_current_vm = 0; } RUBY_FREE_LEAVE("vm"); @@ -2810,14 +2808,11 @@ struct rb_objspace *rb_objspace_alloc(void); void Init_BareVM(void) { + static rb_vm_t ruby_main_vm; + static rb_thread_t ruby_main_thread; /* VM bootstrap: phase 1 */ - rb_vm_t * vm = ruby_mimmalloc(sizeof(*vm)); - rb_thread_t * th = ruby_mimmalloc(sizeof(*th)); - if (!vm || !th) { - fprintf(stderr, "[FATAL] failed to allocate memory\n"); - exit(EXIT_FAILURE); - } - MEMZERO(th, rb_thread_t, 1); + rb_vm_t *vm = &ruby_main_vm; + rb_thread_t *th = &ruby_main_thread; rb_thread_set_current_raw(th); vm_init2(vm); -- EW