Commit 793053fd authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[coverage] Don't skip collection if invocation_count is zero

Function-granularity coverage skips functions that are both uncovered
and have an uncovered parent. This optimization needs to be tweaked once
block coverage and incremental collection is in play, as it is possible
to have a function with invocation_count == 0 (i.e. uncovered at
function granularity) that still has relevant block-granularity
coverage.

Bug: v8:6000
Change-Id: I4cc81b8a6935aa58e29d383ed4fa749cbfe69352
Reviewed-on: https://chromium-review.googlesource.com/589508Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46991}
parent 962de532
......@@ -474,19 +474,24 @@ Coverage* Coverage::Collect(Isolate* isolate,
break;
}
}
// Only include a function range if it has a non-0 count, or
// if it is directly nested inside a function with non-0 count.
if (count != 0 ||
(!nesting.empty() && functions->at(nesting.back()).count != 0)) {
Handle<String> name(info->DebugName(), isolate);
nesting.push_back(functions->size());
functions->emplace_back(start, end, count, name);
if (FLAG_block_coverage && IsBlockMode(collectionMode) &&
info->HasCoverageInfo()) {
CoverageFunction* function = &functions->back();
CollectBlockCoverage(isolate, function, info, collectionMode);
}
Handle<String> name(info->DebugName(), isolate);
CoverageFunction function(start, end, count, name);
if (FLAG_block_coverage && IsBlockMode(collectionMode) &&
info->HasCoverageInfo()) {
CollectBlockCoverage(isolate, &function, info, collectionMode);
}
// Only include a function range if itself or its parent function is
// covered, or if it contains non-trivial block coverage.
bool is_covered = (count != 0);
bool parent_is_covered =
(!nesting.empty() && functions->at(nesting.back()).count != 0);
bool has_block_coverage = !function.blocks.empty();
if (is_covered || parent_is_covered || has_block_coverage) {
nesting.push_back(functions->size());
functions->emplace_back(function);
}
}
......
......@@ -929,6 +929,27 @@ Running test: testPreciseBinaryCoverage
[0] : {
functions : [
[0] : {
functionName : fib
isBlockCoverage : true
ranges : [
[0] : {
count : 0
endOffset : 73
startOffset : 1
}
[1] : {
count : 1
endOffset : 41
startOffset : 32
}
[2] : {
count : 1
endOffset : 71
startOffset : 41
}
]
}
[1] : {
functionName : is_optimized
isBlockCoverage : true
ranges : [
......
......@@ -21,4 +21,23 @@ f(); f(); f(); f(); f(); f(); // 0150
{"start":50,"end":76,"count":8}]
);
// In contrast to the corresponding test in -opt.js, f is not optimized here
// and therefore reports its invocation count correctly.
TestCoverage("Partial coverage collection",
`
!function() { // 0000
function f(x) { // 0050
if (x) { nop(); } else { nop(); } // 0100
} // 0150
f(true); f(true); // 0200
%OptimizeFunctionOnNextCall(f); // 0250
%DebugCollectCoverage(); // 0300
f(false); // 0350
}(); // 0400
`,
[{"start":52,"end":153,"count":1},
{"start":111,"end":121,"count":0}]
);
%DebugToggleBlockCoverage(false);
......@@ -22,4 +22,25 @@ f(); f(); f(); f(); f(); f(); // 0150
{"start":50,"end":76,"count":2}] // TODO(jgruber): Invocation count is off.
);
// This test is tricky: it requires a non-toplevel, optimized function.
// After initial collection, counts are cleared. Further invocation_counts
// are not collected for optimized functions, and on the next coverage
// collection we and up with an uncovered function with an uncovered parent
// but with non-trivial block coverage.
TestCoverage("Partial coverage collection",
`
!function() { // 0000
function f(x) { // 0050
if (x) { nop(); } else { nop(); } // 0100
} // 0150
f(true); f(true); // 0200
%OptimizeFunctionOnNextCall(f); // 0250
%DebugCollectCoverage(); // 0300
f(false); // 0350
}(); // 0400
`,
[{"start":52,"end":153,"count":0},
{"start":127,"end":153,"count":1}]
);
%DebugToggleBlockCoverage(false);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment