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

ruby-changes:52296

From: mame <ko1@a...>
Date: Wed, 22 Aug 2018 14:24:57 +0900 (JST)
Subject: [ruby-changes:52296] mame:r64504 (trunk): thread.c (rb_reset_coverages): remove coverage counters from all ISeqs

mame	2018-08-22 14:24:50 +0900 (Wed, 22 Aug 2018)

  New Revision: 64504

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

  Log:
    thread.c (rb_reset_coverages): remove coverage counters from all ISeqs
    
    When coverage measurement is enabled, the compiler makes each iseq have
    a reference to the counter array of coverage.
    Even after coverage measurement is disabled, the reference is kept.
    And, if coverage measurement is restarted, a coverage hook will increase
    the counter.  This is completely meaningless; it brings just overhead.
    
    To remove this meaninglessness, this change removes all the reference
    when coverage measuement is stopped.

  Modified files:
    trunk/iseq.c
    trunk/iseq.h
    trunk/thread.c
Index: iseq.c
===================================================================
--- iseq.c	(revision 64503)
+++ iseq.c	(revision 64504)
@@ -966,6 +966,25 @@ rb_iseq_coverage(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L966
     return ISEQ_COVERAGE(iseq);
 }
 
+static int
+remove_coverage_i(void *vstart, void *vend, size_t stride, void *data)
+{
+    VALUE v = (VALUE)vstart;
+    for (; v != (VALUE)vend; v += stride) {
+	if (rb_obj_is_iseq(v)) {
+            rb_iseq_t *iseq = (rb_iseq_t *)v;
+            ISEQ_COVERAGE_SET(iseq, Qnil);
+	}
+    }
+    return 0;
+}
+
+void
+rb_iseq_remove_coverage_all()
+{
+    rb_objspace_each_objects(remove_coverage_i, NULL);
+}
+
 /* define wrapper class methods (RubyVM::InstructionSequence) */
 
 static void
Index: iseq.h
===================================================================
--- iseq.h	(revision 64503)
+++ iseq.h	(revision 64504)
@@ -178,6 +178,8 @@ VALUE rb_iseq_first_lineno(const rb_iseq https://github.com/ruby/ruby/blob/trunk/iseq.h#L178
 VALUE rb_iseq_method_name(const rb_iseq_t *iseq);
 void rb_iseq_code_location(const rb_iseq_t *iseq, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
 
+void rb_iseq_remove_coverage_all();
+
 /* proc.c */
 const rb_iseq_t *rb_method_iseq(VALUE body);
 const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
Index: thread.c
===================================================================
--- thread.c	(revision 64503)
+++ thread.c	(revision 64504)
@@ -5404,6 +5404,7 @@ rb_reset_coverages(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L5404
 {
     VALUE coverages = rb_get_coverages();
     st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
+    rb_iseq_remove_coverage_all();
     GET_VM()->coverages = Qfalse;
     rb_remove_event_hook((rb_event_hook_func_t) update_line_coverage);
     if (GET_VM()->coverage_mode & COVERAGE_TARGET_BRANCHES) {

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

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