Title: [263071] trunk
Revision
263071
Author
[email protected]
Date
2020-06-15 18:26:07 -0700 (Mon, 15 Jun 2020)

Log Message

JSTests:
Bytecode liveness should be aware of checkpoints
https://bugs.webkit.org/show_bug.cgi?id=213106
<rdar://problem/63416838>

Reviewed by Keith Miller.

* stress/iterator-open-checkpoint-liveness.js: Added.
(f):
(next):
(iterator):
(catch):

Source/_javascript_Core:
op_iterator_open getNext checkpoint needs to declare it uses m_iterator
https://bugs.webkit.org/show_bug.cgi?id=213106
<rdar://problem/63416838>

 Reviewed by Keith Miller.

Currently, we have no way of specifying that a checkpoint uses an operand defined at an earlier
point in the same bytecode, which is the case for op_iterator_open: we assume that it will have
already allocated the iterator and stored it in m_iterator by the time we get to the getNext
checkpoint. In order to support that, we change tmpLivenessForCheckpoint to livenessForCheckpoint
and allow it to also declare the use of the operands defined within the bytecode.


* bytecode/BytecodeLivenessAnalysis.cpp:
(JSC::livenessForCheckpoint):
(JSC::tmpLivenessForCheckpoint): Deleted.
* bytecode/BytecodeLivenessAnalysis.h:
* bytecode/FullBytecodeLiveness.h:
* dfg/DFGForAllKills.h:
(JSC::DFG::forAllKilledOperands):
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::isLiveInBytecode):
* dfg/DFGGraph.h:

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (263070 => 263071)


--- trunk/JSTests/ChangeLog	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/JSTests/ChangeLog	2020-06-16 01:26:07 UTC (rev 263071)
@@ -1,3 +1,17 @@
+2020-06-15  Tadeu Zagallo  <[email protected]>
+
+        Bytecode liveness should be aware of checkpoints
+        https://bugs.webkit.org/show_bug.cgi?id=213106
+        <rdar://problem/63416838>
+
+        Reviewed by Keith Miller.
+
+        * stress/iterator-open-checkpoint-liveness.js: Added.
+        (f):
+        (next):
+        (iterator):
+        (catch):
+
 2020-06-15  Alexey Shvayka  <[email protected]>
 
         Expand JSObject::defineOwnIndexedProperty() fast path for existing properties

Added: trunk/JSTests/stress/iterator-open-checkpoint-liveness.js (0 => 263071)


--- trunk/JSTests/stress/iterator-open-checkpoint-liveness.js	                        (rev 0)
+++ trunk/JSTests/stress/iterator-open-checkpoint-liveness.js	2020-06-16 01:26:07 UTC (rev 263071)
@@ -0,0 +1,35 @@
+let x = false;
+function f(x) {
+    return Array.from(x);
+}
+noInline(f);
+
+function next() {
+    if (x) {
+        x = false;
+        return {value: 2, done: false, x: 1};
+    }
+    return {value: 1, done: true };
+}
+noInline(next);
+
+var iterator = function() {
+    if (x)
+        return {};
+    return { next };
+};
+noInline(iterator);
+
+var node_list = {
+    [Symbol.iterator]: iterator,
+}
+for (var i = 0; i < 1e5; ++i) {
+    f(node_list);
+}
+x = true;
+try {
+    f(node_list);
+} catch (err) {
+    if (err.message !== 'undefined is not a function')
+        throw err;
+}

Modified: trunk/Source/_javascript_Core/ChangeLog (263070 => 263071)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-16 01:26:07 UTC (rev 263071)
@@ -1,3 +1,28 @@
+2020-06-15  Tadeu Zagallo  <[email protected]>
+
+        op_iterator_open getNext checkpoint needs to declare it uses m_iterator
+        https://bugs.webkit.org/show_bug.cgi?id=213106
+        <rdar://problem/63416838>
+
+         Reviewed by Keith Miller.
+
+        Currently, we have no way of specifying that a checkpoint uses an operand defined at an earlier
+        point in the same bytecode, which is the case for op_iterator_open: we assume that it will have
+        already allocated the iterator and stored it in m_iterator by the time we get to the getNext
+        checkpoint. In order to support that, we change tmpLivenessForCheckpoint to livenessForCheckpoint
+        and allow it to also declare the use of the operands defined within the bytecode.
+
+        * bytecode/BytecodeLivenessAnalysis.cpp:
+        (JSC::livenessForCheckpoint):
+        (JSC::tmpLivenessForCheckpoint): Deleted.
+        * bytecode/BytecodeLivenessAnalysis.h:
+        * bytecode/FullBytecodeLiveness.h:
+        * dfg/DFGForAllKills.h:
+        (JSC::DFG::forAllKilledOperands):
+        * dfg/DFGGraph.cpp:
+        (JSC::DFG::Graph::isLiveInBytecode):
+        * dfg/DFGGraph.h:
+
 2020-06-15  Alexey Shvayka  <[email protected]>
 
         Expand JSObject::defineOwnIndexedProperty() fast path for existing properties

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.cpp (263070 => 263071)


--- trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.cpp	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.cpp	2020-06-16 01:26:07 UTC (rev 263071)
@@ -31,6 +31,7 @@
 #include "CodeBlock.h"
 #include "FullBytecodeLiveness.h"
 #include "JSCJSValueInlines.h"
+#include <wtf/Scope.h>
 
 namespace JSC {
 
@@ -175,11 +176,15 @@
         return static_cast<IntType2>(v1) == static_cast<IntType2>(v2);
 }
 
-Bitmap<maxNumCheckpointTmps> tmpLivenessForCheckpoint(const CodeBlock& codeBlock, BytecodeIndex bytecodeIndex)
+Vector<Operand, maxNumCheckpointTmps> livenessForCheckpoint(const CodeBlock& codeBlock, BytecodeIndex bytecodeIndex)
 {
-    Bitmap<maxNumCheckpointTmps> result;
+    Vector<Operand, maxNumCheckpointTmps> result;
     uint8_t checkpoint = bytecodeIndex.checkpoint();
 
+    auto scopeExit = makeScopeExit([&] {
+        ASSERT(result.size() <= maxNumCheckpointTmps);
+    });
+
     if (!checkpoint)
         return result;
 
@@ -190,14 +195,16 @@
         static_assert(enumValuesEqualAsIntegral(OpCallVarargs::makeCall, OpTailCallVarargs::makeCall) && enumValuesEqualAsIntegral(OpCallVarargs::argCountIncludingThis, OpTailCallVarargs::argCountIncludingThis));
         static_assert(enumValuesEqualAsIntegral(OpCallVarargs::makeCall, OpConstructVarargs::makeCall) && enumValuesEqualAsIntegral(OpCallVarargs::argCountIncludingThis, OpConstructVarargs::argCountIncludingThis));
         if (checkpoint == OpCallVarargs::makeCall)
-            result.set(OpCallVarargs::argCountIncludingThis);
+            result.append(Operand::tmp(OpCallVarargs::argCountIncludingThis));
         return result;
     }
     case op_iterator_open: {
+        if (checkpoint == OpIteratorOpen::getNext)
+            result.append(codeBlock.instructions().at(bytecodeIndex)->as<OpIteratorOpen>().m_iterator);
         return result;
     }
     case op_iterator_next: {
-        result.set(OpIteratorNext::nextResult);
+        result.append(Operand::tmp(OpIteratorNext::nextResult));
         return result;
     }
     default:

Modified: trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.h (263070 => 263071)


--- trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.h	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/bytecode/BytecodeLivenessAnalysis.h	2020-06-16 01:26:07 UTC (rev 263071)
@@ -97,7 +97,7 @@
     BytecodeGraph m_graph;
 };
 
-Bitmap<maxNumCheckpointTmps> tmpLivenessForCheckpoint(const CodeBlock&, BytecodeIndex);
+Vector<Operand, maxNumCheckpointTmps> livenessForCheckpoint(const CodeBlock&, BytecodeIndex);
 
 inline bool operandIsAlwaysLive(int operand);
 inline bool operandThatIsNotAlwaysLiveIsLive(const FastBitVector& out, int operand);

Modified: trunk/Source/_javascript_Core/bytecode/FullBytecodeLiveness.h (263070 => 263071)


--- trunk/Source/_javascript_Core/bytecode/FullBytecodeLiveness.h	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/bytecode/FullBytecodeLiveness.h	2020-06-16 01:26:07 UTC (rev 263071)
@@ -35,7 +35,7 @@
 class CodeBlock;
 
 // Note: Full bytecode liveness does not track any information about the liveness of temps.
-// If you want tmp liveness for a checkpoint ask tmpLivenessForCheckpoint.
+// If you want tmp liveness for a checkpoint ask livenessForCheckpoint.
 class FullBytecodeLiveness {
     WTF_MAKE_FAST_ALLOCATED;
 public:

Modified: trunk/Source/_javascript_Core/dfg/DFGForAllKills.h (263070 => 263071)


--- trunk/Source/_javascript_Core/dfg/DFGForAllKills.h	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/dfg/DFGForAllKills.h	2020-06-16 01:26:07 UTC (rev 263071)
@@ -79,15 +79,17 @@
             ASSERT(before.bytecodeIndex().checkpoint() != after.bytecodeIndex().checkpoint());
             ASSERT_WITH_MESSAGE(before.bytecodeIndex().offset() == after.bytecodeIndex().offset() || nodeAfter->op() == ExitOK || nodeAfter->op() == InvalidationPoint, "When the DFG does code motion it should change the forExit origin to match the surrounding bytecodes.");
 
-            auto liveBefore = tmpLivenessForCheckpoint(*codeBlock, before.bytecodeIndex());
-            auto liveAfter = tmpLivenessForCheckpoint(*codeBlock, after.bytecodeIndex());
-            liveAfter.invert();
-            liveBefore.filter(liveAfter);
+            auto checkpointLiveBefore = livenessForCheckpoint(*codeBlock, before.bytecodeIndex());
+            auto checkpointLiveAfter = livenessForCheckpoint(*codeBlock, after.bytecodeIndex());
 
-            liveBefore.forEachSetBit([&] (size_t tmp) {
-                functor(remapOperand(beforeInlineCallFrame, Operand::tmp(tmp)));
-            });
-            // No locals can die at a checkpoint.
+            FullBytecodeLiveness& fullLiveness = graph.livenessFor(codeBlock);
+            const FastBitVector& liveAfter = fullLiveness.getLiveness(after.bytecodeIndex(), LivenessCalculationPoint::BeforeUse);
+
+            for (Operand operand : checkpointLiveBefore) {
+                if (checkpointLiveAfter.contains(operand) || (!operand.isTmp() && liveAfter[operand.virtualRegister().offset()]))
+                    continue;
+                functor(remapOperand(beforeInlineCallFrame, operand));
+            }
             return;
         }
 

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.cpp (263070 => 263071)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.cpp	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.cpp	2020-06-16 01:26:07 UTC (rev 263071)
@@ -1152,8 +1152,8 @@
             if (!codeBlock->numTmps() || operandIndex < tmpOffset)
                 continue;
 
-            auto bitMap = tmpLivenessForCheckpoint(*codeBlock, codeOriginPtr->bytecodeIndex());
-            return bitMap.get(operandIndex - tmpOffset);
+            auto live = livenessForCheckpoint(*codeBlock, codeOriginPtr->bytecodeIndex());
+            return live.contains(operand);
         }
 
         VirtualRegister reg = operand.virtualRegister() - codeOriginPtr->stackOffset();

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.h (263070 => 263071)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.h	2020-06-16 01:23:44 UTC (rev 263070)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.h	2020-06-16 01:26:07 UTC (rev 263071)
@@ -904,10 +904,9 @@
 
             if (codeOriginPtr->bytecodeIndex().checkpoint()) {
                 ASSERT(codeBlock->numTmps());
-                auto liveTmps = tmpLivenessForCheckpoint(*codeBlock, codeOriginPtr->bytecodeIndex());
-                liveTmps.forEachSetBit([&] (size_t tmp) {
-                    functor(remapOperand(inlineCallFrame, Operand::tmp(tmp)));
-                });
+                auto live = livenessForCheckpoint(*codeBlock, codeOriginPtr->bytecodeIndex());
+                for (Operand operand : live)
+                    functor(remapOperand(inlineCallFrame, operand));
             }
             
             if (!inlineCallFrame)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to