Bug 1261826 part 9 - initScriptCounts relies on jump targets for allocating PCCounts. r=bhackett
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Tue, 17 May 2016 17:15:53 +0000
changeset 297697 d3912b7cd8ea15d4bc426319c9a4e402738452f2
parent 297696 4bb616c2f9125789a708c7c1c7fb94222cf72271
child 297698 2e29695fee8730d8dae52960dc98ff7ade38aacb
push id76868
push usernpierron@mozilla.com
push dateTue, 17 May 2016 17:16:30 +0000
treeherdermozilla-inbound@2e29695fee87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs1261826
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 1261826 part 9 - initScriptCounts relies on jump targets for allocating PCCounts. r=bhackett
js/src/jsscript.cpp
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1336,95 +1336,27 @@ JSScript::maybeForwardedScriptSource() c
 
 bool
 JSScript::initScriptCounts(JSContext* cx)
 {
     MOZ_ASSERT(!hasScriptCounts());
 
     // Record all pc which are the first instruction of a basic block.
     mozilla::Vector<jsbytecode*, 16, SystemAllocPolicy> jumpTargets;
+    jsbytecode* mainPc = main();
     jsbytecode* end = codeEnd();
-    jsbytecode* mainEntry = main();
     for (jsbytecode* pc = code(); pc != end; pc = GetNextPc(pc)) {
-        if (pc == mainEntry) {
+        if (BytecodeIsJumpTarget(JSOp(*pc)) || pc == mainPc) {
             if (!jumpTargets.append(pc)) {
                 ReportOutOfMemory(cx);
                 return false;
             }
         }
-
-        bool jump = IsJumpOpcode(JSOp(*pc));
-        if (jump) {
-            jsbytecode* target = pc + GET_JUMP_OFFSET(pc);
-            if (!jumpTargets.append(target)) {
-                ReportOutOfMemory(cx);
-                return false;
-            }
-
-            if (BytecodeFallsThrough(JSOp(*pc))) {
-                jsbytecode* fallthrough = GetNextPc(pc);
-                if (!jumpTargets.append(fallthrough)) {
-                    ReportOutOfMemory(cx);
-                    return false;
-                }
-            }
-        }
-
-        if (JSOp(*pc) == JSOP_TABLESWITCH) {
-            jsbytecode* pc2 = pc;
-            int32_t len = GET_JUMP_OFFSET(pc2);
-
-            // Default target.
-            if (!jumpTargets.append(pc + len)) {
-                ReportOutOfMemory(cx);
-                return false;
-            }
-
-            pc2 += JUMP_OFFSET_LEN;
-            int32_t low = GET_JUMP_OFFSET(pc2);
-            pc2 += JUMP_OFFSET_LEN;
-            int32_t high = GET_JUMP_OFFSET(pc2);
-
-            for (int i = 0; i < high-low+1; i++) {
-                pc2 += JUMP_OFFSET_LEN;
-                int32_t off = (int32_t) GET_JUMP_OFFSET(pc2);
-                if (off) {
-                    // Case (i + low)
-                    if (!jumpTargets.append(pc + off)) {
-                        ReportOutOfMemory(cx);
-                        return false;
-                    }
-                }
-            }
-        }
     }
 
-    // Mark catch/finally blocks as being jump targets.
-    if (hasTrynotes()) {
-        JSTryNote* tn = trynotes()->vector;
-        JSTryNote* tnlimit = tn + trynotes()->length;
-        for (; tn < tnlimit; tn++) {
-            jsbytecode* tryStart = mainEntry + tn->start;
-            jsbytecode* tryPc = tryStart - 1;
-            if (JSOp(*tryPc) != JSOP_TRY)
-                continue;
-
-            jsbytecode* tryTarget = tryStart + tn->length;
-            if (!jumpTargets.append(tryTarget)) {
-                ReportOutOfMemory(cx);
-                return false;
-            }
-        }
-    }
-
-    // Sort all pc, and remove duplicates.
-    std::sort(jumpTargets.begin(), jumpTargets.end());
-    auto last = std::unique(jumpTargets.begin(), jumpTargets.end());
-    jumpTargets.erase(last, jumpTargets.end());
-
     // Initialize all PCCounts counters to 0.
     ScriptCounts::PCCountsVector base;
     if (!base.reserve(jumpTargets.length())) {
         ReportOutOfMemory(cx);
         return false;
     }
 
     for (size_t i = 0; i < jumpTargets.length(); i++)