Apply Jacoco's instruction filtering to Java branch coverage#13896
Closed
c-mita wants to merge 3 commits intobazelbuild:masterfrom
Closed
Apply Jacoco's instruction filtering to Java branch coverage#13896c-mita wants to merge 3 commits intobazelbuild:masterfrom
c-mita wants to merge 3 commits intobazelbuild:masterfrom
Conversation
Member
Author
|
To be clear, I don't think supporting the other filter operations is impossible; the main issue is testing, especially for the |
1fbb937 to
0cf44ce
Compare
This acts as a preliminary test for the application of Jacoco's filters. The java compiler will generate a large number of branches on a string switch statement (one set for testing against String::hashCode and a second set as backup) - the majority of these should be filtered as Jacoco normally would.
Jacoco's filters operate on asm.tree.AbstractInsnNode objects. We track these as we walk through the ASM tree in the same way Jacoco does, apply the filters to them appropriately, and then map ignored nodes back to the Instruction objects we already operated on. We only handle IFilter::ignore for now; this covers the majority of filters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jacoco applies a set of filters during its coverage analysis to remove
various compiler constructs that could lead to surprising outputs in
coverage results, leaving behind coverage data that closer fits the
code given to the compiler.
A simple java example is the function:
This would generate at least double the number of expected branches as
the compiler generates a second set of branches to operate on hashCode.
Jacoco would normally ignore the first set of branches, reducing the
number to the expected 4.
Because Bazel applies its own branch analysis step, Bazel's branch
coverage output does not benefit from this filtering.
This change adapts the custom analyzer to record the necessary
information during the ASM Tree walk in the same manner as Jacoco's
regular analyzer in order to apply the filters.
The filters have three output operations:
The first of these, ignore, is by far the simplest to implement and
covers the vast majority of use cases in Java.
By mapping the AbstractInsnNode objects recorded during the ASM Tree
walk to the Instruction objects used during branch analysis, we can
simply skip over Instruction objects that have had their associated
AbstractInsnNode object ignored by a filter.
The remaining operations, merge and replaceBranches, are left
unimplemeted for now; these require more care to handle, are harder
to test, and affect only a minority of cases, specifically:
Part of #12696