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

ruby-changes:39258

From: ko1 <ko1@a...>
Date: Wed, 22 Jul 2015 19:55:28 +0900 (JST)
Subject: [ruby-changes:39258] ko1:r51339 (trunk): * vm_core.h: separate rb_iseq_body into rb_iseq_constant_body and

ko1	2015-07-22 19:55:02 +0900 (Wed, 22 Jul 2015)

  New Revision: 51339

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

  Log:
    * vm_core.h: separate rb_iseq_body into rb_iseq_constant_body and
      rb_iseq_variable_body (rb_iseq_t::variable_body).
      rb_iseq_variable_body can be modified after compilation.
    * compile.c: use rb_iseq_t::variable_body.
    * iseq.c: ditto.
    * thread.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/thread.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51338)
+++ ChangeLog	(revision 51339)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 22 19:52:45 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_core.h: separate rb_iseq_body into rb_iseq_constant_body and
+	  rb_iseq_variable_body (rb_iseq_t::variable_body).
+
+	  rb_iseq_variable_body can be modified after compilation.
+
+	* compile.c: use rb_iseq_t::variable_body.
+
+	* iseq.c: ditto.
+
+	* thread.c: ditto.
+
 Wed Jul 22 17:50:35 2015  SHIBATA Hiroshi  <hsbt@r...>
 
 	* lib/matrix/eigenvalue_decomposition.rb: refine code style.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 51338)
+++ vm_core.h	(revision 51339)
@@ -241,11 +241,7 @@ typedef struct rb_iseq_location_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L241
     VALUE first_lineno; /* TODO: may be unsigned short */
 } rb_iseq_location_t;
 
-struct rb_iseq_body {
-    /***************/
-    /* static data */
-    /***************/
-
+struct rb_iseq_constant_body {
     enum iseq_type {
 	ISEQ_TYPE_TOP,
 	ISEQ_TYPE_METHOD,
@@ -267,7 +263,6 @@ struct rb_iseq_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L263
     unsigned int line_info_size;
 
     const VALUE mark_ary;     /* Array: includes operands which should be GC marked */
-    const VALUE coverage;     /* coverage array */
 
     /* insn info, must be freed */
     struct iseq_line_info_entry *line_info_table;
@@ -360,12 +355,11 @@ struct rb_iseq_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L355
     /* for child iseq */
     const struct rb_iseq_struct *parent_iseq;
     struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
+};
 
-    /****************/
-    /* dynamic data */
-    /****************/
+struct rb_iseq_variable_body {
+    const VALUE coverage;     /* coverage array */
 
-    /* misc */
     rb_num_t flip_cnt;
 
     /* original iseq, before encoding
@@ -378,8 +372,8 @@ struct rb_iseq_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L372
 struct rb_iseq_struct {
     VALUE flags;
     struct iseq_compile_data *compile_data; /* used at compile time */
-    struct rb_iseq_body *body;
-    VALUE dummy1;
+    struct rb_iseq_constant_body *body;
+    struct rb_iseq_variable_body *variable_body;
     VALUE dummy2;
 };
 
Index: iseq.c
===================================================================
--- iseq.c	(revision 51338)
+++ iseq.c	(revision 51339)
@@ -92,7 +92,7 @@ rb_iseq_free(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L92
 	    ruby_xfree(iseq->body->param.keyword);
 	}
 	compile_data_free(iseq->compile_data);
-	ruby_xfree(iseq->body->iseq);
+	ruby_xfree(iseq->variable_body->iseq);
 	ruby_xfree(iseq->body);
     }
     RUBY_FREE_LEAVE("iseq");
@@ -106,14 +106,17 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L106
     RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->body->location.label), RSTRING_PTR(iseq->body->location.path));
 
     if (iseq->body) {
-	const struct rb_iseq_body *body = iseq->body;
+	const struct rb_iseq_constant_body *body = iseq->body;
 
 	RUBY_MARK_UNLESS_NULL(body->mark_ary);
 	RUBY_MARK_UNLESS_NULL(body->location.label);
 	RUBY_MARK_UNLESS_NULL(body->location.base_label);
 	RUBY_MARK_UNLESS_NULL(body->location.path);
 	RUBY_MARK_UNLESS_NULL(body->location.absolute_path);
-	RUBY_MARK_UNLESS_NULL(body->coverage);
+    }
+
+    if (iseq->variable_body) {
+	RUBY_MARK_UNLESS_NULL(iseq->variable_body->coverage);
     }
 
     if (iseq->compile_data != 0) {
@@ -173,7 +176,8 @@ static rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L176
 iseq_alloc(void)
 {
     rb_iseq_t *iseq = (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
-    iseq->body = ZALLOC(struct rb_iseq_body);
+    iseq->body = ZALLOC(struct rb_iseq_constant_body);
+    iseq->variable_body = ZALLOC(struct rb_iseq_variable_body);
     return iseq;
 }
 
@@ -264,13 +268,13 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L268
     iseq->compile_data->option = option;
     iseq->compile_data->last_coverable_line = -1;
 
-    RB_OBJ_WRITE(iseq, &iseq->body->coverage, Qfalse);
+    RB_OBJ_WRITE(iseq, &iseq->variable_body->coverage, Qfalse);
 
     if (!GET_THREAD()->parse_in_eval) {
 	VALUE coverages = rb_get_coverages();
 	if (RTEST(coverages)) {
-	    RB_OBJ_WRITE(iseq, &iseq->body->coverage, rb_hash_lookup(coverages, path));
-	    if (NIL_P(iseq->body->coverage)) RB_OBJ_WRITE(iseq, &iseq->body->coverage, Qfalse);
+	    RB_OBJ_WRITE(iseq, &iseq->variable_body->coverage, rb_hash_lookup(coverages, path));
+	    if (NIL_P(iseq->variable_body->coverage)) RB_OBJ_WRITE(iseq, &iseq->variable_body->coverage, Qfalse);
 	}
     }
 
Index: compile.c
===================================================================
--- compile.c	(revision 51338)
+++ compile.c	(revision 51339)
@@ -225,9 +225,9 @@ r_value(VALUE value) https://github.com/ruby/ruby/blob/trunk/compile.c#L225
 
 #define ADD_TRACE(seq, line, event) \
   do { \
-      if ((event) == RUBY_EVENT_LINE && iseq->body->coverage && \
+      if ((event) == RUBY_EVENT_LINE && iseq->variable_body->coverage && \
 	  (line) != iseq->compile_data->last_coverable_line) { \
-	  RARRAY_ASET(iseq->body->coverage, (line) - 1, INT2FIX(0)); \
+	  RARRAY_ASET(iseq->variable_body->coverage, (line) - 1, INT2FIX(0)); \
 	  iseq->compile_data->last_coverable_line = (line); \
 	  ADD_INSN1((seq), (line), trace, INT2FIX(RUBY_EVENT_COVERAGE)); \
       } \
@@ -608,26 +608,26 @@ rb_vm_insn_addr2insn(const void *addr) / https://github.com/ruby/ruby/blob/trunk/compile.c#L608
 VALUE *
 rb_iseq_original_iseq(const rb_iseq_t *iseq) /* cold path */
 {
-    if (iseq->body->iseq) return iseq->body->iseq;
+    if (iseq->variable_body->iseq) return iseq->variable_body->iseq;
 
-    iseq->body->iseq = ALLOC_N(VALUE, iseq->body->iseq_size);
+    iseq->variable_body->iseq = ALLOC_N(VALUE, iseq->body->iseq_size);
 
-    MEMCPY(iseq->body->iseq, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
+    MEMCPY(iseq->variable_body->iseq, iseq->body->iseq_encoded, VALUE, iseq->body->iseq_size);
 
 #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE
     {
 	unsigned int i;
 
 	for (i = 0; i < iseq->body->iseq_size; /* */ ) {
-	    const void *addr = (const void *)iseq->body->iseq[i];
+	    const void *addr = (const void *)iseq->variable_body->iseq[i];
 	    const int insn = rb_vm_insn_addr2insn(addr);
 
-	    iseq->body->iseq[i] = insn;
+	    iseq->variable_body->iseq[i] = insn;
 	    i += insn_len(insn);
 	}
     }
 #endif
-    return iseq->body->iseq;
+    return iseq->variable_body->iseq;
 }
 
 /*********************************************/
@@ -5299,7 +5299,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5299
 	rb_num_t cnt;
 	VALUE key;
 
-	cnt = local_iseq->body->flip_cnt++ + VM_SVAR_FLIPFLOP_START;
+	cnt = local_iseq->variable_body->flip_cnt++ + VM_SVAR_FLIPFLOP_START;
 	key = INT2FIX(cnt);
 
 	ADD_INSN2(ret, line, getspecial, key, INT2FIX(0));
Index: thread.c
===================================================================
--- thread.c	(revision 51338)
+++ thread.c	(revision 51339)
@@ -5227,7 +5227,7 @@ rb_check_deadlock(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/thread.c#L5227
 static void
 update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
 {
-    VALUE coverage = GET_THREAD()->cfp->iseq->body->coverage;
+    VALUE coverage = GET_THREAD()->cfp->iseq->variable_body->coverage;
     if (coverage && RBASIC(coverage)->klass == 0) {
 	long line = rb_sourceline() - 1;
 	long count;

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

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