1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

thread.c (update_line_coverage): Use RUBY_EVENT_LINE

This change makes coverage use the general event type RUBY_EVENT_LINE
instead of a special event type RUBY_EVENT_COVERAGE.
Just a refactoring.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-12-06 06:39:05 +00:00
parent 9fbd48ee71
commit ec02c4861b
4 changed files with 30 additions and 26 deletions

View file

@ -251,15 +251,12 @@ struct iseq_compile_data_ensure_node_stack {
#define ADD_TRACE(seq, event) \ #define ADD_TRACE(seq, event) \
ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event))) ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event)))
#define ADD_TRACE_LINE_COVERAGE(seq, line) \ #define SETUP_LINE_COVERAGE(seq, line) \
do { \ do { \
if (ISEQ_COVERAGE(iseq) && \ if (ISEQ_COVERAGE(iseq) && \
ISEQ_LINE_COVERAGE(iseq) && \ ISEQ_LINE_COVERAGE(iseq) && \
(line) > 0 && \ (line) > 0) { \
(line) != ISEQ_COMPILE_DATA(iseq)->last_coverable_line) { \
RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \ RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
ISEQ_COMPILE_DATA(iseq)->last_coverable_line = (line); \
ADD_INSN2((seq), (line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(COVERAGE_INDEX_LINES)); \
} \ } \
} while (0) } while (0)
#define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \ #define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \
@ -5424,7 +5421,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
else { else {
if (node->flags & NODE_FL_NEWLINE) { if (node->flags & NODE_FL_NEWLINE) {
ISEQ_COMPILE_DATA(iseq)->last_line = line; ISEQ_COMPILE_DATA(iseq)->last_line = line;
ADD_TRACE_LINE_COVERAGE(ret, line); SETUP_LINE_COVERAGE(ret, line);
ADD_TRACE(ret, RUBY_EVENT_LINE); ADD_TRACE(ret, RUBY_EVENT_LINE);
} }
} }

1
iseq.c
View file

@ -330,7 +330,6 @@ prepare_iseq_build(rb_iseq_t *iseq,
ISEQ_COMPILE_DATA(iseq)->storage_head->size = ISEQ_COMPILE_DATA(iseq)->storage_head->size =
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE; INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
ISEQ_COMPILE_DATA(iseq)->option = option; ISEQ_COMPILE_DATA(iseq)->option = option;
ISEQ_COMPILE_DATA(iseq)->last_coverable_line = -1;
ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL; ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;

1
iseq.h
View file

@ -114,7 +114,6 @@ struct iseq_compile_data {
struct iseq_compile_data_storage *storage_head; struct iseq_compile_data_storage *storage_head;
struct iseq_compile_data_storage *storage_current; struct iseq_compile_data_storage *storage_current;
int last_line; int last_line;
int last_coverable_line;
int label_no; int label_no;
int node_level; int node_level;
unsigned int ci_index; unsigned int ci_index;

View file

@ -4976,13 +4976,10 @@ rb_check_deadlock(rb_vm_t *vm)
} }
static void static void
update_coverage(VALUE data, const rb_trace_arg_t *trace_arg) update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
{ {
VALUE coverage = rb_iseq_coverage(GET_EC()->cfp->iseq); VALUE coverage = rb_iseq_coverage(GET_EC()->cfp->iseq);
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) { if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
long arg = FIX2INT(trace_arg->data);
switch (arg % 16) {
case COVERAGE_INDEX_LINES: {
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES); VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
if (lines) { if (lines) {
long line = rb_sourceline() - 1; long line = rb_sourceline() - 1;
@ -4998,8 +4995,16 @@ update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
RARRAY_ASET(lines, line, LONG2FIX(count)); RARRAY_ASET(lines, line, LONG2FIX(count));
} }
} }
break;
} }
}
static void
update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
{
VALUE coverage = rb_iseq_coverage(GET_EC()->cfp->iseq);
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
long arg = FIX2INT(trace_arg->data);
switch (arg % 16) {
case COVERAGE_INDEX_BRANCHES: { case COVERAGE_INDEX_BRANCHES: {
VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES); VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES);
if (branches) { if (branches) {
@ -5106,6 +5111,7 @@ rb_set_coverages(VALUE coverages, int mode, VALUE me2counter)
{ {
GET_VM()->coverages = coverages; GET_VM()->coverages = coverages;
GET_VM()->coverage_mode = mode; GET_VM()->coverage_mode = mode;
rb_add_event_hook2((rb_event_hook_func_t) update_line_coverage, RUBY_EVENT_LINE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
if (mode & COVERAGE_TARGET_METHODS) { if (mode & COVERAGE_TARGET_METHODS) {
rb_add_event_hook2((rb_event_hook_func_t) update_method_coverage, RUBY_EVENT_CALL, me2counter, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); rb_add_event_hook2((rb_event_hook_func_t) update_method_coverage, RUBY_EVENT_CALL, me2counter, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
@ -5130,6 +5136,9 @@ rb_reset_coverages(void)
VALUE coverages = rb_get_coverages(); VALUE coverages = rb_get_coverages();
st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0); st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
GET_VM()->coverages = Qfalse; GET_VM()->coverages = Qfalse;
if (GET_VM()->coverage_mode & COVERAGE_TARGET_LINES) {
rb_remove_event_hook((rb_event_hook_func_t) update_line_coverage);
}
rb_remove_event_hook((rb_event_hook_func_t) update_coverage); rb_remove_event_hook((rb_event_hook_func_t) update_coverage);
if (GET_VM()->coverage_mode & COVERAGE_TARGET_METHODS) { if (GET_VM()->coverage_mode & COVERAGE_TARGET_METHODS) {
rb_remove_event_hook((rb_event_hook_func_t) update_method_coverage); rb_remove_event_hook((rb_event_hook_func_t) update_method_coverage);