ruby-changes:45935
From: normal <ko1@a...>
Date: Sat, 18 Mar 2017 05:00:05 +0900 (JST)
Subject: [ruby-changes:45935] normal:r58006 (trunk): remove branches in dmark and dfree GC callbacks
normal 2017-03-18 04:59:56 +0900 (Sat, 18 Mar 2017) New Revision: 58006 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58006 Log: remove branches in dmark and dfree GC callbacks dmark and dfree callbacks are never called in gc.c for NULL DATA_PTR values, not even for zombie objects. * compile.c (ibf_loader_mark): remove branch for pointer validity * compile.c (ibf_loader_free): ditto * cont.c (cont_free): ditto * cont.c (fiber_free): ditto * dir.c (dir_free): ditto * ext/stringio/stringio.c (strio_mark): ditto * proc.c (binding_free): ditto * thread_sync.c (mutex_free): ditto * vm.c (thread_free): ditto Modified files: trunk/compile.c trunk/cont.c trunk/dir.c trunk/ext/stringio/stringio.c trunk/proc.c trunk/thread_sync.c trunk/vm.c Index: dir.c =================================================================== --- dir.c (revision 58005) +++ dir.c (revision 58006) @@ -436,9 +436,8 @@ static void https://github.com/ruby/ruby/blob/trunk/dir.c#L436 dir_free(void *ptr) { struct dir_data *dir = ptr; - if (dir) { - if (dir->dir) closedir(dir->dir); - } + + if (dir->dir) closedir(dir->dir); xfree(dir); } Index: vm.c =================================================================== --- vm.c (revision 58005) +++ vm.c (revision 58006) @@ -2346,41 +2346,38 @@ rb_thread_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2346 static void thread_free(void *ptr) { - rb_thread_t *th; + rb_thread_t *th = ptr; RUBY_FREE_ENTER("thread"); - if (ptr) { - th = ptr; - - if (!th->root_fiber) { - RUBY_FREE_UNLESS_NULL(th->stack); - } + if (!th->root_fiber) { + RUBY_FREE_UNLESS_NULL(th->stack); + } - if (th->locking_mutex != Qfalse) { - rb_bug("thread_free: locking_mutex must be NULL (%p:%p)", (void *)th, (void *)th->locking_mutex); - } - if (th->keeping_mutexes != NULL) { - rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes); - } + if (th->locking_mutex != Qfalse) { + rb_bug("thread_free: locking_mutex must be NULL (%p:%p)", (void *)th, (void *)th->locking_mutex); + } + if (th->keeping_mutexes != NULL) { + rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes); + } - if (th->local_storage) { - st_free_table(th->local_storage); - } + if (th->local_storage) { + st_free_table(th->local_storage); + } - if (th->vm && th->vm->main_thread == th) { - RUBY_GC_INFO("main thread\n"); - } - else { + if (th->vm && th->vm->main_thread == th) { + RUBY_GC_INFO("main thread\n"); + } + else { #ifdef USE_SIGALTSTACK - if (th->altstack) { - free(th->altstack); - } -#endif - ruby_xfree(ptr); + if (th->altstack) { + free(th->altstack); } - if (ruby_current_thread == th) - ruby_current_thread = NULL; +#endif + ruby_xfree(ptr); } + if (ruby_current_thread == th) + ruby_current_thread = NULL; + RUBY_FREE_LEAVE("thread"); } Index: ext/stringio/stringio.c =================================================================== --- ext/stringio/stringio.c (revision 58005) +++ ext/stringio/stringio.c (revision 58006) @@ -52,9 +52,8 @@ static void https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L52 strio_mark(void *p) { struct StringIO *ptr = p; - if (ptr) { - rb_gc_mark(ptr->string); - } + + rb_gc_mark(ptr->string); } static void Index: thread_sync.c =================================================================== --- thread_sync.c (revision 58005) +++ thread_sync.c (revision 58006) @@ -54,16 +54,14 @@ static const char* rb_mutex_unlock_th(rb https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L54 static void mutex_free(void *ptr) { - if (ptr) { - rb_mutex_t *mutex = ptr; - if (mutex->th) { - /* rb_warn("free locked mutex"); */ - const char *err = rb_mutex_unlock_th(mutex, mutex->th); - if (err) rb_bug("%s", err); - } - native_mutex_destroy(&mutex->lock); - native_cond_destroy(&mutex->cond); + rb_mutex_t *mutex = ptr; + if (mutex->th) { + /* rb_warn("free locked mutex"); */ + const char *err = rb_mutex_unlock_th(mutex, mutex->th); + if (err) rb_bug("%s", err); } + native_mutex_destroy(&mutex->lock); + native_cond_destroy(&mutex->cond); ruby_xfree(ptr); } Index: proc.c =================================================================== --- proc.c (revision 58005) +++ proc.c (revision 58006) @@ -265,12 +265,10 @@ rb_proc_lambda_p(VALUE procval) https://github.com/ruby/ruby/blob/trunk/proc.c#L265 static void binding_free(void *ptr) { - rb_binding_t *bind; RUBY_FREE_ENTER("binding"); - if (ptr) { - bind = ptr; - ruby_xfree(bind); - } + + ruby_xfree(ptr); + RUBY_FREE_LEAVE("binding"); } Index: compile.c =================================================================== --- compile.c (revision 58005) +++ compile.c (revision 58006) @@ -8631,22 +8631,18 @@ ibf_load_setup(struct ibf_load *load, VA https://github.com/ruby/ruby/blob/trunk/compile.c#L8631 static void ibf_loader_mark(void *ptr) { - if (ptr) { - struct ibf_load *load = (struct ibf_load *)ptr; - rb_gc_mark(load->str); - rb_gc_mark(load->iseq_list); - rb_gc_mark(load->obj_list); - } + struct ibf_load *load = (struct ibf_load *)ptr; + rb_gc_mark(load->str); + rb_gc_mark(load->iseq_list); + rb_gc_mark(load->obj_list); } static void ibf_loader_free(void *ptr) { - if (ptr) { - struct ibf_load *load = (struct ibf_load *)ptr; - ruby_xfree(load->id_list); - ruby_xfree(load); - } + struct ibf_load *load = (struct ibf_load *)ptr; + ruby_xfree(load->id_list); + ruby_xfree(load); } static size_t Index: cont.c =================================================================== --- cont.c (revision 58005) +++ cont.c (revision 58006) @@ -218,55 +218,54 @@ cont_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L218 static void cont_free(void *ptr) { + rb_context_t *cont = ptr; + RUBY_FREE_ENTER("cont"); - if (ptr) { - rb_context_t *cont = ptr; - RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack); + RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack); #if FIBER_USE_NATIVE - if (cont->type == CONTINUATION_CONTEXT) { - /* cont */ - ruby_xfree(cont->ensure_array); - RUBY_FREE_UNLESS_NULL(cont->machine.stack); - } - else { - /* fiber */ - rb_fiber_t *fib = (rb_fiber_t*)cont; - const rb_thread_t *const th = GET_THREAD(); + if (cont->type == CONTINUATION_CONTEXT) { + /* cont */ + ruby_xfree(cont->ensure_array); + RUBY_FREE_UNLESS_NULL(cont->machine.stack); + } + else { + /* fiber */ + rb_fiber_t *fib = (rb_fiber_t*)cont; + const rb_thread_t *const th = GET_THREAD(); #ifdef _WIN32 - if (th && th->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) { - /* don't delete root fiber handle */ - if (fib->fib_handle) { - DeleteFiber(fib->fib_handle); - } + if (th && th->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) { + /* don't delete root fiber handle */ + if (fib->fib_handle) { + DeleteFiber(fib->fib_handle); } + } #else /* not WIN32 */ - if (th && th->fiber != fib) { - if (fib->ss_sp) { - if (cont->type == ROOT_FIBER_CONTEXT) { - rb_bug("Illegal root fiber parameter"); - } - munmap((void*)fib->ss_sp, fib->ss_size); + if (th && th->fiber != fib) { + if (fib->ss_sp) { + if (cont->type == ROOT_FIBER_CONTEXT) { + rb_bug("Illegal root fiber parameter"); } + munmap((void*)fib->ss_sp, fib->ss_size); } - else { - /* It may reached here when finalize */ - /* TODO examine whether it is a bug */ - /* rb_bug("cont_free: release self"); */ - } -#endif } + else { + /* It may reached here when finalize */ + /* TODO examine whether it is a bug */ + /* rb_bug("cont_free: release self"); */ + } +#endif + } #else /* not FIBER_USE_NATIVE */ - ruby_xfree(cont->ensure_array); - RUBY_FREE_UNLESS_NULL(cont->machine.stack); + ruby_xfree(cont->ensure_array); + RUBY_FREE_UNLESS_NULL(cont->machine.stack); #endif #ifdef __ia64 - RUBY_FREE_UNLESS_NULL(cont->machine.register_stack); + RUBY_FREE_UNLESS_NULL(cont->machine.register_stack); #endif - RUBY_FREE_UNLESS_NULL(cont->vm_stack); + RUBY_FREE_UNLESS_NULL(cont->vm_stack); - /* free rb_cont_t or rb_fiber_t */ - ruby_xfree(ptr); - } + /* free rb_cont_t or rb_fiber_t */ + ruby_xfree(ptr); RUBY_FREE_LEAVE("cont"); } @@ -317,16 +316,14 @@ fiber_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L316 static void fiber_free(void *ptr) { + rb_fiber_t *fib = ptr; RUBY_FREE_ENTER("fiber"); - if (ptr) { - rb_fiber_t *fib = ptr; - if (fib->cont.type != ROOT_FIBER_CONTEXT && - fib->cont.saved_thread.local_storage) { - st_free_table(fib->cont.saved_thread.local_storage); - } - - cont_free(&fib->cont); + if (fib->cont.type != ROOT_FIBER_CONTEXT && + fib->cont.saved_thread.local_storage) { + st_free_table(fib->cont.saved_thread.local_storage); } + + cont_free(&fib->cont); RUBY_FREE_LEAVE("fiber"); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/