Bug 1435001 - Make LF and LH more consistent with DA in LCovSource output. r=nbp.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 01 Feb 2018 13:12:07 -0600
changeset 402620 0104a3c366e71354eb34fecf1e280c75f2aa276c
parent 402619 21d459aa8ca8fcf4bf646d586d15db42660e53a3
child 402621 e30390f2f53a505a1dc514dad36c181d75e4c83c
push id33393
push userrgurzau@mozilla.com
push dateTue, 06 Feb 2018 21:54:26 +0000
treeherdermozilla-central@0790ec12200d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1435001
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435001 - Make LF and LH more consistent with DA in LCovSource output. r=nbp.
js/src/jit-test/tests/coverage/simple.js
js/src/vm/CodeCoverage.cpp
--- a/js/src/jit-test/tests/coverage/simple.js
+++ b/js/src/jit-test/tests/coverage/simple.js
@@ -534,10 +534,45 @@ checkLcov(function () { //FN:$,top-level
   //FNF:1
   //FNH:1
   //LF:6
   //LH:3
   //BRF:4
   //BRH:1
 });
 
+// These tests are not included in ../debug/Script-getOffsetsCoverage-01.js
+// because we're specifically testing a feature of Lcov output that
+// Debugger.Script doesn't have (the aggregation of hits that are on the
+// same line but in different functions).
+{
+    checkLcov(function () { //FN:$,top-level //FNDA:1,%
+        function f() { return 0; } var l = f(); //DA:$,2
+        //FNF:2
+        //FNH:2
+        //LF:1
+        //LH:1
+    });
+
+    // A single line has two functions on it, and both hit.
+    checkLcov(function () { //FN:$,top-level //FNDA:1,%
+        function f() { return 0; } function g() { return 1; } //DA:$,2
+        var v = f() + g(); //DA:$,1
+        //FNF:3
+        //FNH:3
+        //LF:2
+        //LH:2
+    });
+
+    // A line has both function code and toplevel code, and only one of them hits.
+    checkLcov(function () { //FN:$,top-level //FNDA:1,%
+        if (1 === 2)  //DA:$,1
+            throw "0 hits here"; function f() { return "1 hit here"; } //DA:$,1
+        f();  //DA:$,1
+        //FNF:2
+        //FNH:2
+        //LF:3
+        //LH:3
+    });
+}
+
 // If you add a test case here, do the same in
 // jit-test/tests/debug/Script-getOffsetsCoverage-01.js
--- a/js/src/vm/CodeCoverage.cpp
+++ b/js/src/vm/CodeCoverage.cpp
@@ -216,26 +216,27 @@ LCovSource::writeScript(JSScript* script
             if ((oldLine != lineno || !firstLineHasBeenWritten) &&
                 pc >= script->main() &&
                 fallsthrough)
             {
                 auto p = linesHit_.lookupForAdd(lineno);
                 if (!p) {
                     if (!linesHit_.add(p, lineno, hits))
                         return false;
+                    numLinesInstrumented_++;
+                    if (hits != 0)
+                        numLinesHit_++;
+                    maxLineHit_ = std::max(lineno, maxLineHit_);
                 } else {
+                    if (p->value() == 0 && hits != 0)
+                        numLinesHit_++;
                     p->value() += hits;
                 }
 
-                // Count the number of lines instrumented & hit.
                 firstLineHasBeenWritten = true;
-                maxLineHit_ = std::max(lineno, maxLineHit_);
-                numLinesInstrumented_++;
-                if (hits)
-                    numLinesHit_++;
             }
         }
 
         // If the current instruction has thrown, then decrement the hit counts
         // with the number of throws.
         if (sc) {
             const PCCounts* counts = sc->maybeGetThrowCounts(script->pcToOffset(pc));
             if (counts)