* [PATCH] remove mimmalloc/mimfree for vm and main thread
@ 2015-07-18 7:42 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-07-18 7:42 UTC (permalink / raw)
To: spew
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-07-18 7:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-18 7:42 [PATCH] remove mimmalloc/mimfree for vm and main thread Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).