Bug 1274588 part 1.1 - Update code coverage reports to accounts for the aliased jump targets. r=bhackett
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Thu, 02 Jun 2016 13:41:04 +0000
changeset 341187 32eb8332d6185ecaaddd2a016d782d1c12227766
parent 341186 0792b0daef2adbd8af9454fae418aa771726a95e
child 341188 e838c11fd532d3bf3d7562fe56337a7a1bcd3c6b
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs1274588
milestone49.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 1274588 part 1.1 - Update code coverage reports to accounts for the aliased jump targets. r=bhackett
js/src/jit-test/tests/coverage/simple.js
js/src/jit-test/tests/debug/Script-getOffsetsCoverage-01.js
js/src/vm/CodeCoverage.cpp
--- a/js/src/jit-test/tests/coverage/simple.js
+++ b/js/src/jit-test/tests/coverage/simple.js
@@ -317,34 +317,34 @@ checkLcov(function () { //FN:$,top-level
   //LF:7
   //LH:4
   //BRF:5
   //BRH:1
 });
 
 checkLcov(function () { //FN:$,top-level //FNDA:1,%
   var l = ",".split(','); //DA:$,1
-  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,1 //BRDA:$,0,3,- //BRDA:$,0,4,-
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,1 //BRDA:$,0,1,- //BRDA:$,0,2,-
     case 2:
       l.push('2');        //DA:$,1
     case 5:
       l.push('5');        //DA:$,1
   }
   l.pop();                //DA:$,1
   //FNF:1
   //FNH:1
   //LF:5
   //LH:5
   //BRF:3
   //BRH:1
 });
 
 checkLcov(function () { //FN:$,top-level //FNDA:1,%
   var l = ",".split(','); //DA:$,1
-  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,2,- //BRDA:$,0,3,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1
     case 3:
       l.push('1');        //DA:$,0
     case 5:
       l.push('5');        //DA:$,0
   }
   l.pop();                //DA:$,1
   //FNF:1
   //FNH:1
@@ -371,10 +371,140 @@ checkLcov(function () { //FN:$,top-level
   //FNF:2
   //FNH:2
   //LF:8
   //LH:6
   //BRF:4
   //BRH:2
 });
 
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,1 //BRDA:$,0,2,- //BRDA:$,0,3,-
+    case 0:
+    case 1:
+      l.push('0');        //DA:$,0
+      l.push('1');        //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    case 2:
+    case 3:
+      l.push('2');        //DA:$,1
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+    default:
+      l.push('1');        //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,- //BRDA:$,0,4,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+      l.push('default');  //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:8
+  //LH:5
+  //BRF:5
+  //BRH:1
+});
+
+checkLcov(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,- //BRDA:$,0,3,1
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
 // If you add a test case here, do the same in
 // jit-test/tests/debug/Script-getOffsetsCoverage-01.js
--- a/js/src/jit-test/tests/debug/Script-getOffsetsCoverage-01.js
+++ b/js/src/jit-test/tests/debug/Script-getOffsetsCoverage-01.js
@@ -335,10 +335,141 @@ checkGetOffsetsCoverage(function () { //
     case f(-42):          //DA:$,1
       l.push('1');        //DA:$,0
     case f(51):           //DA:$,1
       l.push('5');        //DA:$,0
   }
   l.pop();                //DA:$,1
 });
 
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,1 //BRDA:$,0,2,- //BRDA:$,0,3,-
+    case 0:
+    case 1:
+      l.push('0');        //DA:$,0
+      l.push('1');        //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    case 2:
+    case 3:
+      l.push('2');        //DA:$,1
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+    default:
+      l.push('1');        //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,1 //BRDA:$,0,3,- //BRDA:$,0,4,-
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+      l.push('default');  //DA:$,0
+    case 2:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:8
+  //LH:5
+  //BRF:5
+  //BRH:1
+});
+
+checkGetOffsetsCoverage(function () { //FN:$,top-level //FNDA:1,%
+  var l = ",".split(','); //DA:$,1
+  switch (l.length) {     //DA:$,1 //BRDA:$,0,0,- //BRDA:$,0,1,- //BRDA:$,0,2,- //BRDA:$,0,3,1
+    case 0:
+      l.push('0');        //DA:$,0
+    case 1:
+      l.push('1');        //DA:$,0
+    default:
+      l.push('2');        //DA:$,1
+    case 3:
+      l.push('3');        //DA:$,1
+  }
+  l.pop();                //DA:$,1
+  //FNF:1
+  //FNH:1
+  //LF:7
+  //LH:5
+  //BRF:4
+  //BRH:1
+});
+
 // If you add a test case here, do the same in
 // jit-test/tests/coverage/simple.js
--- a/js/src/vm/CodeCoverage.cpp
+++ b/js/src/vm/CodeCoverage.cpp
@@ -258,29 +258,36 @@ LCovSource::writeScript(JSScript* script
 
             jsbytecode* firstcasepc = exitpc;
             for (size_t j = 0; j < numCases; j++) {
                 jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
                 if (testpc < firstcasepc)
                     firstcasepc = testpc;
             }
 
-            jsbytecode* lastcasepc = firstcasepc;
+            // Count the number of hits of the default branch, by subtracting
+            // the number of hits of each cases.
+            uint64_t defaultHits = hits;
+
+            // Count the number of hits of the previous case entry.
             uint64_t fallsThroughHits = 0;
+
+            // Record branches for each cases.
+            size_t caseId = 0;
             for (size_t i = 0; i < numCases; i++) {
                 jsbytecode* casepc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * i);
                 // The case is not present, and jumps to the default pc if used.
                 if (casepc == pc)
                     continue;
 
                 // PCs might not be in increasing order of case indexes.
-                lastcasepc = firstcasepc - 1;
+                jsbytecode* lastcasepc = firstcasepc - 1;
                 for (size_t j = 0; j < numCases; j++) {
                     jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
-                    if (lastcasepc < testpc && testpc < casepc)
+                    if (lastcasepc < testpc && (testpc < casepc || (j < i && testpc == casepc)))
                         lastcasepc = testpc;
                 }
 
                 if (casepc != lastcasepc) {
                     // Case (i + low)
                     uint64_t caseHits = 0;
                     if (sc) {
                         const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(casepc));
@@ -296,65 +303,75 @@ LCovSource::writeScript(JSScript* script
 
                             if (BytecodeFallsThrough(JSOp(*endpc)))
                                 fallsThroughHits = script->getHitCount(endpc);
                         }
 
                         caseHits -= fallsThroughHits;
                     }
 
-                    outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, i);
+                    outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId);
                     if (caseHits)
                         outBRDA_.printf("%d\n", caseHits);
                     else
                         outBRDA_.put("-\n", 2);
 
                     numBranchesFound_++;
                     numBranchesHit_ += !!caseHits;
-                    lastcasepc = casepc;
+                    defaultHits -= caseHits;
+                    caseId++;
                 }
             }
 
-            // Add one branch entry for the default statement.
-            uint64_t defaultHits = 0;
+            // Compute the number of hits of the default branch, if it has its
+            // own case clause.
+            bool defaultHasOwnClause = true;
+            if (defaultpc != exitpc) {
+                defaultHits = 0;
 
-            if (sc) {
                 // Look for the last case entry before the default pc.
-                lastcasepc = firstcasepc - 1;
+                jsbytecode* lastcasepc = firstcasepc - 1;
                 for (size_t j = 0; j < numCases; j++) {
                     jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
-                    if (lastcasepc < testpc && testpc < defaultpc)
+                    if (lastcasepc < testpc && testpc <= defaultpc)
                         lastcasepc = testpc;
                 }
 
+                if (lastcasepc == defaultpc)
+                    defaultHasOwnClause = false;
+
                 // Look if the last case entry fallthrough to the default case,
                 // in which case we have to remove the number of fallthrough
                 // hits out of the default case hits.
-                if (lastcasepc != pc) {
+                if (sc && lastcasepc != pc) {
                     jsbytecode* endpc = lastcasepc;
                     while (GetNextPc(endpc) < defaultpc)
                         endpc = GetNextPc(endpc);
 
                     if (BytecodeFallsThrough(JSOp(*endpc)))
                         fallsThroughHits = script->getHitCount(endpc);
                 }
 
-                const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(defaultpc));
-                if (counts)
-                    defaultHits = counts->numExec();
+                if (sc) {
+                    const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(defaultpc));
+                    if (counts)
+                        defaultHits = counts->numExec();
+                }
                 defaultHits -= fallsThroughHits;
             }
 
-            outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, numCases);
-            if (defaultHits)
-                outBRDA_.printf("%d\n", defaultHits);
-            else
-                outBRDA_.put("-\n", 2);
-            numBranchesFound_++;
-            numBranchesHit_ += !!defaultHits;
+            if (defaultHasOwnClause) {
+                outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId);
+                if (defaultHits)
+                    outBRDA_.printf("%d\n", defaultHits);
+                else
+                    outBRDA_.put("-\n", 2);
+                numBranchesFound_++;
+                numBranchesHit_ += !!defaultHits;
+            }
 
             // Increment the branch identifier, and go to the next instruction.
             branchId++;
             tableswitchExitOffset = 0;
         }
     }
 
     // Report any new OOM.