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

ruby-changes:40786

From: ko1 <ko1@a...>
Date: Wed, 2 Dec 2015 22:58:20 +0900 (JST)
Subject: [ruby-changes:40786] ko1:r52865 (trunk): * vm_core.h, iseq.h: remove rb_iseq_t::variable_body.

ko1	2015-12-02 22:58:07 +0900 (Wed, 02 Dec 2015)

  New Revision: 52865

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

  Log:
    * vm_core.h, iseq.h: remove rb_iseq_t::variable_body.
      Fields in rb_iseq_t::variable_body are contained by
      rb_iseq_t::body::mark_ary (hidden Array object).
    
      Index 0 to 2 of mark_ary are reserved by these objects.
    
    * iseq.c: catch up this fix.
    
    * compile.c (rb_iseq_original_iseq): trivial rewrite.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/iseq.h
    trunk/test/ruby/test_process.rb
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52864)
+++ ChangeLog	(revision 52865)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 02 22:57:46 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_core.h, iseq.h: remove rb_iseq_t::variable_body.
+	  Fields in rb_iseq_t::variable_body are contained by
+	  rb_iseq_t::body::mark_ary (hidden Array object).
+
+	  Index 0 to 2 of mark_ary are reserved by these objects.
+
+	* iseq.c: catch up this fix.
+
+	* compile.c (rb_iseq_original_iseq): trivial rewrite.
+
 Wed Dec  2 17:19:02 2015  Koichi Sasada  <ko1@a...>
 
 	* iseq.h: introduce ISEQ_ORIGINAL_ISEQ() and
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 52864)
+++ vm_core.h	(revision 52865)
@@ -385,24 +385,14 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L385
     unsigned int line_info_size;
 };
 
-struct rb_iseq_variable_body {
-    const VALUE coverage_;     /* coverage array */
-
-    rb_num_t flip_cnt_;
-
-    /* original iseq, before encoding
-     * used for debug/dump (TODO: union with compile_data) */
-    VALUE *iseq_;
-};
-
 /* T_IMEMO/iseq */
 /* typedef rb_iseq_t is in method.h */
 struct rb_iseq_struct {
     VALUE flags;
     struct iseq_compile_data *compile_data_; /* used at compile time */
     struct rb_iseq_constant_body *body;
-    struct rb_iseq_variable_body *variable_body;
-    VALUE dummy2;
+    VALUE reserved1;
+    VALUE reserved2;
 };
 
 enum ruby_special_exceptions {
Index: iseq.c
===================================================================
--- iseq.c	(revision 52864)
+++ iseq.c	(revision 52865)
@@ -92,8 +92,6 @@ rb_iseq_free(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L92
 	    ruby_xfree((void *)iseq->body->param.keyword);
 	}
 	compile_data_free(ISEQ_COMPILE_DATA(iseq));
-	ruby_xfree(iseq->variable_body->iseq_);
-	ruby_xfree(iseq->variable_body);
 	ruby_xfree(iseq->body);
     }
     RUBY_FREE_LEAVE("iseq");
@@ -116,10 +114,6 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L114
 	RUBY_MARK_UNLESS_NULL(body->location.absolute_path);
     }
 
-    if (iseq->variable_body) {
-	RUBY_MARK_UNLESS_NULL(ISEQ_COVERAGE(iseq));
-    }
-
     if (ISEQ_COMPILE_DATA(iseq) != 0) {
 	const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq);
 
@@ -148,19 +142,10 @@ static size_t https://github.com/ruby/ruby/blob/trunk/iseq.c#L142
 iseq_memsize(const rb_iseq_t *iseq)
 {
     size_t size = 0; /* struct already counted as RVALUE size */
-    const struct rb_iseq_variable_body *variable_body;
-    const struct rb_iseq_constant_body *body;
+    const struct rb_iseq_constant_body *body = iseq->body;
     const struct iseq_compile_data *compile_data;
 
-    variable_body = iseq->variable_body;
-    body = iseq->body;
-
-    if (variable_body) {
-	size += sizeof(struct rb_iseq_variable_body);
-	if (variable_body->iseq_ && body) {
-	    size += body->iseq_size * sizeof(VALUE);
-	}
-    }
+    /* TODO: should we count original_iseq? */
 
     if (body) {
 	struct rb_call_info_with_kwarg *ci_kw_entries = (struct rb_call_info_with_kwarg *)&body->ci_entries[body->ci_size];
@@ -220,7 +205,6 @@ iseq_alloc(void) https://github.com/ruby/ruby/blob/trunk/iseq.c#L205
 {
     rb_iseq_t *iseq = (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
     iseq->body = ZALLOC(struct rb_iseq_constant_body);
-    iseq->variable_body = ZALLOC(struct rb_iseq_variable_body);
     return iseq;
 }
 
@@ -269,11 +253,18 @@ set_relation(rb_iseq_t *iseq, const rb_i https://github.com/ruby/ruby/blob/trunk/iseq.c#L253
 void
 rb_iseq_add_mark_object(const rb_iseq_t *iseq, VALUE obj)
 {
-    if (!RTEST(iseq->body->mark_ary)) {
-	RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, rb_ary_tmp_new(3));
-	RBASIC_CLEAR_CLASS(iseq->body->mark_ary);
-    }
-    rb_ary_push(iseq->body->mark_ary, obj);
+    /* TODO: check dedup */
+    rb_ary_push(ISEQ_MARK_ARY(iseq), obj);
+}
+
+static VALUE
+iseq_mark_ary_create(int flip_cnt)
+{
+    VALUE ary = rb_ary_tmp_new(3);
+    rb_ary_push(ary, Qnil);              /* ISEQ_MARK_ARY_COVERAGE */
+    rb_ary_push(ary, INT2FIX(flip_cnt)); /* ISEQ_MARK_ARY_FLIP_CNT */
+    rb_ary_push(ary, Qnil);              /* ISEQ_MARK_ARY_ORIGINAL_ISEQ */
+    return ary;
 }
 
 static VALUE
@@ -292,7 +283,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L283
     if (iseq != iseq->body->local_iseq) {
 	RB_OBJ_WRITE(iseq, &iseq->body->location.base_label, iseq->body->local_iseq->body->location.label);
     }
-    RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, 0);
+    RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, iseq_mark_ary_create(0));
 
     ISEQ_COMPILE_DATA(iseq) = ZALLOC(struct iseq_compile_data);
     RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, Qnil);
Index: iseq.h
===================================================================
--- iseq.h	(revision 52864)
+++ iseq.h	(revision 52865)
@@ -23,12 +23,43 @@ rb_call_info_kw_arg_bytes(int keyword_le https://github.com/ruby/ruby/blob/trunk/iseq.h#L23
     return sizeof(struct rb_call_info_kw_arg) + sizeof(VALUE) * (keyword_len - 1);
 }
 
+enum iseq_mark_ary_index {
+    ISEQ_MARK_ARY_COVERAGE      = 0,
+    ISEQ_MARK_ARY_FLIP_CNT      = 1,
+    ISEQ_MARK_ARY_ORIGINAL_ISEQ = 2,
+};
+
+#define ISEQ_MARK_ARY(iseq)           (iseq)->body->mark_ary
+
+#define ISEQ_COVERAGE(iseq)           RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE)
+#define ISEQ_COVERAGE_SET(iseq, cov)  RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_COVERAGE, cov)
+
+static inline int
+ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
+{
+    VALUE cntv = RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT);
+    int cnt = FIX2INT(cntv);
+    RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_FLIP_CNT, INT2FIX(cnt+1));
+    return cnt;
+}
+
+static inline VALUE *
+ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
+{
+    VALUE str = RARRAY_AREF(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_ORIGINAL_ISEQ);
+    if (RTEST(str)) return (VALUE *)RSTRING_PTR(str);
+    return NULL;
+}
+
+static inline VALUE *
+ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
+{
+    VALUE str = rb_str_tmp_new(size * sizeof(VALUE));
+    RARRAY_ASET(ISEQ_MARK_ARY(iseq), ISEQ_MARK_ARY_ORIGINAL_ISEQ, str);
+    return (VALUE *)RSTRING_PTR(str);
+}
+
 #define ISEQ_COMPILE_DATA(iseq)       (iseq)->compile_data_
-#define ISEQ_COVERAGE(iseq)           (iseq)->variable_body->coverage_
-#define ISEQ_COVERAGE_SET(iseq, cov)  RB_OBJ_WRITE((iseq), &(iseq)->variable_body->coverage_, cov)
-#define ISEQ_FLIP_CNT_INCREMENT(iseq) ((iseq)->variable_body->flip_cnt_++)
-#define ISEQ_ORIGINAL_ISEQ(iseq)      (iseq)->variable_body->iseq_
-#define ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, size) (ISEQ_ORIGINAL_ISEQ(iseq) = ALLOC_N(VALUE, size))
 
 RUBY_SYMBOL_EXPORT_BEGIN
 
Index: compile.c
===================================================================
--- compile.c	(revision 52864)
+++ compile.c	(revision 52865)
@@ -645,7 +645,7 @@ rb_iseq_original_iseq(const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/compile.c#L645
 
     if (ISEQ_ORIGINAL_ISEQ(iseq)) return ISEQ_ORIGINAL_ISEQ(iseq);
     original_code = ISEQ_ORIGINAL_ISEQ_ALLOC(iseq, iseq->body->iseq_size);
-    MEMCPY(ISEQ_ORIGINAL_ISEQ(iseq), iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
+    MEMCPY(original_code, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
 
 #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
     {
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 52864)
+++ test/ruby/test_process.rb	(revision 52865)
@@ -633,9 +633,9 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L633
         trap(:USR1) { print "trap\n" }
         system("cat", :in => "fifo")
       EOS
-        sleep 0.5
+        sleep 1
         Process.kill(:USR1, io.pid)
-        sleep 0.1
+        sleep 1
         File.write("fifo", "ok\n")
         assert_equal("trap\nok\n", io.read)
       }

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

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