Commit c7ea845
committed
Implement method coverage
Coverage's methods mode now works and produces the same results as CRuby:
{ file => { methods: { [owner, name, start_line, start_column,
end_line, end_column] => call_count } } }
Design follows CRuby's per-method-entry counters and JaCoCo-style probes:
* A MethodCoverage counter is created for every method entry (each def
or define_method landing in a module, in RubyModule#putMethod) whose
source file is being tracked, and attached to the DynamicMethod.
Aliases, visibility changes of inherited methods and other forwarding
entries get no counter of their own. Their calls count toward the
original, as in CRuby.
* Every Ruby-level call path (interpreted, mixed-mode, JIT-compiled, and
proc-based define_method) hands the counter to the body through the
ThreadContext. The body takes it in its first instruction
(ReceiveMethodCoverageInstr) and counts the call once its arguments
have been received (CoverMethodInstr), so calls that fail on arity,
keywords or a raising default value are not counted, matching where
CRuby fires the CALL event. Blocks get the same probes since any block
may become a method via define_method. Indy call sites no longer bind
directly to the compiled handle of a method that is being counted.
* Counting is a lock-free atomic add, so threads calling the same method
in parallel neither serialize nor lose increments. Entries sharing a
key are summed like CRuby.
* The parser now records byte columns and end positions of def, block
and lambda definitions (DefNode/IterNode source spans), carried into
IRScope. Both generated parsers were regenerated from RubyParser.y
with jay.
Coverage data is now kept per file in FileCoverage (lines, methods, and
room for branches), results only contain the requested modes (branches
still reports an empty hash), files are listed in parse order, and
Coverage.supported?(:methods) is true.
Also fixes two pre-existing issues this work surfaced: IRClosure dropped
the coverageMode it was given, so blocks converted into methods for
define_method were built without any coverage and oneshot_lines probes
disarmed themselves when hit while coverage was suspended.
Un-excludes the CRuby method coverage tests and the :all-modes spec, and
adds JRuby-specific tests for parallel counting and every execution
mode.
See #5147.1 parent 336fd77 commit c7ea845
42 files changed
Lines changed: 1138 additions & 115 deletions
File tree
- core/src/main/java/org/jruby
- ast
- ext
- coverage
- ripper
- internal/runtime
- methods
- ir
- builder
- instructions
- interpreter
- persistence
- runtime
- targets
- indy
- parser
- runtime
- spec/tags/ruby/library/coverage
- test
- jruby
- mri/excludes
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
| 684 | + | |
| 685 | + | |
684 | 686 | | |
685 | 687 | | |
686 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
35 | 49 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
120 | 145 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | 62 | | |
56 | 63 | | |
| 64 | + | |
| 65 | + | |
57 | 66 | | |
58 | 67 | | |
59 | 68 | | |
| |||
98 | 107 | | |
99 | 108 | | |
100 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
101 | 118 | | |
102 | 119 | | |
103 | 120 | | |
| |||
0 commit comments