ruby-changes:39164
From: ko1 <ko1@a...>
Date: Wed, 15 Jul 2015 02:36:56 +0900 (JST)
Subject: [ruby-changes:39164] ko1:r51245 (trunk): * vm_core.h, vm.c: remvoe rb_env_t::prev_envval because we can know it
ko1 2015-07-15 02:36:36 +0900 (Wed, 15 Jul 2015) New Revision: 51245 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51245 Log: * vm_core.h, vm.c: remvoe rb_env_t::prev_envval because we can know it via env->ep. rb_vm_env_prev_envval(env) returns prev_envval via env->ep. * vm_core.h (rb_vm_env_local_variables): change parameter type from VALUE (T_DATA/env) to `const rb_env_t *' to make same as rb_vm_env_prev_envval(). * proc.c: catch up these changes. * vm_dump.c: ditto. * vm.c: rename macros. * ENV_IN_HEAP_P() to VM_EP_IN_HEAP_P() because it uses ep. * ENV_VAL() to VM_ENV_EP_ENVVAL() because it is too short. Modified files: trunk/ChangeLog trunk/proc.c trunk/vm.c trunk/vm_core.h trunk/vm_dump.c Index: ChangeLog =================================================================== --- ChangeLog (revision 51244) +++ ChangeLog (revision 51245) @@ -1,3 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 15 02:27:22 2015 Koichi Sasada <ko1@a...> + + * vm_core.h, vm.c: remvoe rb_env_t::prev_envval because we can know it + via env->ep. + + rb_vm_env_prev_envval(env) returns prev_envval via env->ep. + + * vm_core.h (rb_vm_env_local_variables): change parameter type + from VALUE (T_DATA/env) to `const rb_env_t *' to make same as + rb_vm_env_prev_envval(). + + * proc.c: catch up these changes. + + * vm_dump.c: ditto. + + * vm.c: rename macros. + + * ENV_IN_HEAP_P() to VM_EP_IN_HEAP_P() because it uses ep. + * ENV_VAL() to VM_ENV_EP_ENVVAL() because it is too short. + Wed Jul 15 01:09:09 2015 Koichi Sasada <ko1@a...> * vm.c: refactoring Proc/Env related code. Index: vm_core.h =================================================================== --- vm_core.h (revision 51244) +++ vm_core.h (revision 51245) @@ -796,7 +796,6 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L796 typedef struct { int env_size; - VALUE prev_envval; /* for GC mark */ rb_block_t block; VALUE env[1]; /* flexible array */ } rb_env_t; @@ -958,7 +957,8 @@ VALUE rb_vm_invoke_proc(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm_core.h#L957 VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const rb_block_t *block, VALUE klass, int8_t is_lambda); VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass); VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp); -VALUE rb_vm_env_local_variables(VALUE envval); +VALUE rb_vm_env_local_variables(const rb_env_t *env); +VALUE rb_vm_env_prev_envval(const rb_env_t *env); VALUE *rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars); void rb_vm_inc_const_missing_count(void); void rb_vm_gvl_destroy(rb_vm_t *vm); Index: proc.c =================================================================== --- proc.c (revision 51244) +++ proc.c (revision 51245) @@ -379,7 +379,7 @@ get_local_variable_ptr(VALUE envval, ID https://github.com/ruby/ruby/blob/trunk/proc.c#L379 else { return NULL; } - } while ((envval = env->prev_envval) != 0); + } while ((envval = rb_vm_env_prev_envval(env)) != Qfalse); return NULL; } @@ -432,9 +432,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L432 bind_local_variables(VALUE bindval) { const rb_binding_t *bind; + const rb_env_t *env; GetBindingPtr(bindval, bind); - return rb_vm_env_local_variables(bind->env); + GetEnvPtr(bind->env, env); + + return rb_vm_env_local_variables(env); } /* Index: vm.c =================================================================== --- vm.c (revision 51244) +++ vm.c (revision 51245) @@ -407,10 +407,6 @@ ruby_vm_run_at_exit_hooks(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm.c#L407 }; */ -#define ENV_IN_HEAP_P(th, env) \ - (!((th)->stack <= (env) && (env) < ((th)->stack + (th)->stack_size))) -#define ENV_VAL(env) ((env)[1]) - static void env_mark(void * const ptr) { @@ -420,8 +416,7 @@ env_mark(void * const ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L416 RUBY_GC_INFO("env->env\n"); rb_gc_mark_values((long)env->env_size, env->env); - RUBY_GC_INFO("env->prev_envval\n"); - RUBY_MARK_UNLESS_NULL(env->prev_envval); + RUBY_MARK_UNLESS_NULL(rb_vm_env_prev_envval(env)); RUBY_MARK_UNLESS_NULL(env->block.self); RUBY_MARK_UNLESS_NULL(env->block.proc); @@ -452,6 +447,9 @@ static const rb_data_type_t env_data_typ https://github.com/ruby/ruby/blob/trunk/vm.c#L447 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; +#define VM_EP_IN_HEAP_P(th, ep) (!((th)->stack <= (ep) && (ep) < ((th)->stack + (th)->stack_size))) +#define VM_ENV_EP_ENVVAL(ep) ((ep)[1]) + static VALUE check_env_value(VALUE envval); static int @@ -462,9 +460,9 @@ check_env(rb_env_t * const env) https://github.com/ruby/ruby/blob/trunk/vm.c#L460 fprintf(stderr, "envval: %10p ", (void *)env->block.ep[1]); dp(env->block.ep[1]); fprintf(stderr, "ep: %10p\n", (void *)env->block.ep); - if (env->prev_envval) { + if (rb_vm_env_prev_envval(env)) { fprintf(stderr, ">>\n"); - check_env_value(env->prev_envval); + check_env_value(rb_vm_env_prev_envval(env)); fprintf(stderr, "<<\n"); } return 1; @@ -499,23 +497,20 @@ vm_make_proc_from_block(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm.c#L497 static VALUE vm_make_env_each(rb_thread_t *const th, rb_control_frame_t *const cfp) { - VALUE envval, penvval = 0, blockprocval = 0; + VALUE envval, blockprocval = 0; VALUE * const ep = cfp->ep; rb_env_t *env; VALUE *new_ep; int i, local_size, env_size; - if (ENV_IN_HEAP_P(th, ep)) { - return ENV_VAL(ep); + if (VM_EP_IN_HEAP_P(th, ep)) { + return VM_ENV_EP_ENVVAL(ep); } if (!VM_EP_LEP_P(ep)) { VALUE *prev_ep = VM_EP_PREV_EP(ep); - if (ENV_IN_HEAP_P(th, prev_ep)) { - penvval = ENV_VAL(prev_ep); - } - else { + if (!VM_EP_IN_HEAP_P(th, prev_ep)) { rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); while (prev_cfp->ep != prev_ep) { @@ -523,7 +518,7 @@ vm_make_env_each(rb_thread_t *const th, https://github.com/ruby/ruby/blob/trunk/vm.c#L518 if (VM_CHECK_MODE > 0 && prev_cfp->ep == 0) rb_bug("invalid ep"); } - penvval = vm_make_env_each(th, prev_cfp); + vm_make_env_each(th, prev_cfp); *ep = VM_ENVVAL_PREV_EP_PTR(prev_cfp->ep); } } @@ -571,9 +566,8 @@ vm_make_env_each(rb_thread_t *const th, https://github.com/ruby/ruby/blob/trunk/vm.c#L566 * must happen after TypedData_Wrap_Struct to ensure penvval is markable * in case object allocation triggers GC and clobbers penvval. */ - env->prev_envval = penvval; - *ep = envval; /* GC mark */ + new_ep = &env->env[i - 1]; new_ep[1] = envval; if (blockprocval) new_ep[2] = blockprocval; @@ -614,6 +608,19 @@ rb_vm_stack_to_heap(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L608 } } +VALUE +rb_vm_env_prev_envval(const rb_env_t *env) +{ + const VALUE *ep = env->block.ep; + + if (VM_EP_LEP_P(ep)) { + return Qfalse; + } + else { + return VM_ENV_EP_ENVVAL(VM_EP_PREV_EP(ep)); + } +} + static int collect_local_variables_in_iseq(const rb_iseq_t *iseq, const struct local_var_list *vars) { @@ -628,19 +635,19 @@ collect_local_variables_in_iseq(const rb https://github.com/ruby/ruby/blob/trunk/vm.c#L635 static void collect_local_variables_in_env(const rb_env_t *env, const struct local_var_list *vars) { + VALUE prev_envval; - while (collect_local_variables_in_iseq(env->block.iseq, vars), - env->prev_envval) { - GetEnvPtr(env->prev_envval, env); + while (collect_local_variables_in_iseq(env->block.iseq, vars), (prev_envval = rb_vm_env_prev_envval(env)) != Qfalse) { + GetEnvPtr(prev_envval, env); } } static int vm_collect_local_variables_in_heap(rb_thread_t *th, const VALUE *ep, const struct local_var_list *vars) { - if (ENV_IN_HEAP_P(th, ep)) { + if (VM_EP_IN_HEAP_P(th, ep)) { rb_env_t *env; - GetEnvPtr(ENV_VAL(ep), env); + GetEnvPtr(VM_ENV_EP_ENVVAL(ep), env); collect_local_variables_in_env(env, vars); return 1; } @@ -650,12 +657,9 @@ vm_collect_local_variables_in_heap(rb_th https://github.com/ruby/ruby/blob/trunk/vm.c#L657 } VALUE -rb_vm_env_local_variables(VALUE envval) +rb_vm_env_local_variables(const rb_env_t *env) { struct local_var_list vars; - const rb_env_t *env; - - GetEnvPtr(envval, env); local_var_list_init(&vars); collect_local_variables_in_env(env, &vars); return local_var_list_finish(&vars); Index: vm_dump.c =================================================================== --- vm_dump.c (revision 51244) +++ vm_dump.c (revision 51245) @@ -185,6 +185,8 @@ rb_vmdebug_env_dump_raw(rb_env_t *env, V https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L185 fprintf(stderr, "-- env --------------------\n"); while (env) { + VALUE prev_envval; + fprintf(stderr, "--\n"); for (i = 0; i < env->env_size; i++) { fprintf(stderr, "%04d: %08"PRIxVALUE" (%p)", i, env->env[i], (void *)&env->env[i]); @@ -192,11 +194,11 @@ rb_vmdebug_env_dump_raw(rb_env_t *env, V https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L194 fprintf(stderr, "\n"); } - if (env->prev_envval != 0) { - GetEnvPtr(env->prev_envval, env); + if ((prev_envval = rb_vm_env_prev_envval(env)) != Qfalse) { + GetEnvPtr(prev_envval, env); } else { - env = 0; + env = NULL; } } fprintf(stderr, "---------------------------\n"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/