[前][次][番号順一覧][スレッド一覧]

ruby-changes:35371

From: normal <ko1@a...>
Date: Tue, 9 Sep 2014 04:38:36 +0900 (JST)
Subject: [ruby-changes:35371] normal:r47453 (trunk): vm_core.h (rb_env_t): use flexible array

normal	2014-09-09 04:38:22 +0900 (Tue, 09 Sep 2014)

  New Revision: 47453

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47453

  Log:
    vm_core.h (rb_env_t): use flexible array
    
    * vm_core.h (rb_env_t): use flexible array
      This reduces allocations and speeds up the lambda calculus
      fizzbuzz (bm_app_lc_fizzbuzz.rb) benchmark [ruby-core:64858]
    * proc.c (get_local_variable_ptr): deconst to adjust for flex array
    * vm.c (env_mark, env_free, env_memsize): remove check for env->env
    * vm.c (env_alloc): single allocation for flex array
    * vm.c (vm_make_env_each): adjust env_alloc call

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/vm.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47452)
+++ ChangeLog	(revision 47453)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep  9 04:36:24 2014  Eric Wong  <e@8...>
+
+	* vm_core.h (rb_env_t): use flexible array
+	  This reduces allocations and speeds up the lambda calculus
+	  fizzbuzz (bm_app_lc_fizzbuzz.rb) benchmark [ruby-core:64858]
+	* proc.c (get_local_variable_ptr): deconst to adjust for flex array
+	* vm.c (env_mark, env_free, env_memsize): remove check for env->env
+	* vm.c (env_alloc): single allocation for flex array
+	* vm.c (vm_make_env_each): adjust env_alloc call
+
 Mon Sep  8 16:08:22 2014  Koichi Sasada  <ko1@a...>
 
 	* benchmark/bm_app_lc_fizzbuzz.rb: should skip output on benchmark.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 47452)
+++ vm_core.h	(revision 47453)
@@ -753,11 +753,11 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L753
   GetCoreDataFromValue((obj), rb_env_t, (ptr))
 
 typedef struct {
-    VALUE *env;
     int env_size;
     int local_size;
     VALUE prev_envval;		/* for GC mark */
     rb_block_t block;
+    VALUE env[1];               /* flexible array */
 } rb_env_t;
 
 extern const rb_data_type_t ruby_binding_data_type;
Index: proc.c
===================================================================
--- proc.c	(revision 47452)
+++ proc.c	(revision 47453)
@@ -401,7 +401,7 @@ bind_eval(int argc, VALUE *argv, VALUE b https://github.com/ruby/ruby/blob/trunk/proc.c#L401
 static VALUE *
 get_local_variable_ptr(VALUE envval, ID lid)
 {
-    const rb_env_t *env;
+    rb_env_t *env;
 
     do {
 	const rb_iseq_t *iseq;
Index: vm.c
===================================================================
--- vm.c	(revision 47452)
+++ vm.c	(revision 47453)
@@ -354,11 +354,9 @@ env_mark(void * const ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L354
     if (ptr) {
 	const rb_env_t * const env = ptr;
 
-	if (env->env) {
-	    /* TODO: should mark more restricted range */
-	    RUBY_GC_INFO("env->env\n");
-	    rb_gc_mark_locations(env->env, env->env + env->env_size);
-	}
+	/* TODO: should mark more restricted range */
+	RUBY_GC_INFO("env->env\n");
+	rb_gc_mark_locations(env->env, env->env + env->env_size);
 
 	RUBY_GC_INFO("env->prev_envval\n");
 	RUBY_MARK_UNLESS_NULL(env->prev_envval);
@@ -382,8 +380,6 @@ env_free(void * const ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L380
 {
     RUBY_FREE_ENTER("env");
     if (ptr) {
-	rb_env_t *const env = ptr;
-	RUBY_FREE_UNLESS_NULL(env->env);
 	ruby_xfree(ptr);
     }
     RUBY_FREE_LEAVE("env");
@@ -395,9 +391,8 @@ env_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L391
     if (ptr) {
 	const rb_env_t * const env = ptr;
 	size_t size = sizeof(rb_env_t);
-	if (env->env) {
-	    size += env->env_size * sizeof(VALUE);
-	}
+
+	size += (env->env_size - 1) * sizeof(VALUE);
 	return size;
     }
     return 0;
@@ -410,15 +405,15 @@ static const rb_data_type_t env_data_typ https://github.com/ruby/ruby/blob/trunk/vm.c#L405
 };
 
 static VALUE
-env_alloc(void)
+env_alloc(int local_size)
 {
-    VALUE obj;
     rb_env_t *env;
-    obj = TypedData_Make_Struct(rb_cEnv, rb_env_t, &env_data_type, env);
-    env->env = 0;
-    env->prev_envval = 0;
-    env->block.iseq = 0;
-    return obj;
+
+    env = xcalloc(1, sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
+    env->env_size = local_size + 1 + 1;
+    env->local_size = local_size;
+
+    return TypedData_Wrap_Struct(rb_cEnv, &env_data_type, env);
 }
 
 static VALUE check_env_value(VALUE envval);
@@ -485,10 +480,6 @@ vm_make_env_each(const rb_thread_t *cons https://github.com/ruby/ruby/blob/trunk/vm.c#L480
 	}
     }
 
-    /* allocate env */
-    envval = env_alloc();
-    GetEnvPtr(envval, env);
-
     if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
 	local_size = 2;
     }
@@ -496,9 +487,10 @@ vm_make_env_each(const rb_thread_t *cons https://github.com/ruby/ruby/blob/trunk/vm.c#L487
 	local_size = cfp->iseq->local_size;
     }
 
-    env->env_size = local_size + 1 + 1;
-    env->local_size = local_size;
-    env->env = ALLOC_N(VALUE, env->env_size);
+    /* allocate env */
+    envval = env_alloc(local_size);
+    GetEnvPtr(envval, env);
+
     env->prev_envval = penvval;
 
     for (i = 0; i <= local_size; i++) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]