Title: [209673] trunk
Revision
209673
Author
[email protected]
Date
2016-12-10 13:04:05 -0800 (Sat, 10 Dec 2016)

Log Message

REGRESSION(r209653) Crash in CallFrameShuffler::snapshot()
https://bugs.webkit.org/show_bug.cgi?id=165728

Reviewed by Filip Pizlo.

JSTests:

New regression test.

* stress/regress-165728.js: Added.
(sum1):
(sum2):
(tailCaller):
(test):

Source/_javascript_Core:

It can be the case that a JSValueReg's CachedRecovery is the source for mutliple
GPRs. We only store the CachedRecovery in one slot of m_newRegisters to simplify
the recovery process. This is also done for the case where the recovery source
and destination are the same GPR.

In light of this change, snapshot needs to be taught that one CacheRecovery is
the source for multiple registers.  This is done by using a two step process.
First find all the argument CachedRecovery's and create a vector mapping all of
the target GPRs and the source recovery.  Then use that vector to get the
recovery for each register.

* jit/CallFrameShuffler.h:
(JSC::CallFrameShuffler::snapshot):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (209672 => 209673)


--- trunk/JSTests/ChangeLog	2016-12-10 20:44:50 UTC (rev 209672)
+++ trunk/JSTests/ChangeLog	2016-12-10 21:04:05 UTC (rev 209673)
@@ -1,3 +1,18 @@
+2016-12-10  Michael Saboff  <[email protected]>
+
+        REGRESSION(r209653) Crash in CallFrameShuffler::snapshot()
+        https://bugs.webkit.org/show_bug.cgi?id=165728
+
+        Reviewed by Filip Pizlo.
+
+        New regression test.
+
+        * stress/regress-165728.js: Added.
+        (sum1):
+        (sum2):
+        (tailCaller):
+        (test):
+
 2016-12-10  Keith Miller  <[email protected]>
 
         Fix indirect_call if the result type is used.

Added: trunk/JSTests/stress/regress-165728.js (0 => 209673)


--- trunk/JSTests/stress/regress-165728.js	                        (rev 0)
+++ trunk/JSTests/stress/regress-165728.js	2016-12-10 21:04:05 UTC (rev 209673)
@@ -0,0 +1,36 @@
+// Test for REGRESSION(r209653) Crash in CallFrameShuffler::snapshot() - This test shouldn't crash.
+"use strict";
+
+function sum1(a, b, c)
+{
+    return a + b + c;
+}
+
+noInline(sum1);
+
+function sum2(a, b, c)
+{
+    return a + b + c;
+}
+
+noInline(sum2);
+
+function tailCaller(f, a, b)
+{
+    return f(a, b, a)
+}
+
+noInline(tailCaller);
+
+function test(a, b)
+{
+    let result = 0;
+    for (let i = 0; i < 4000000; i++)
+        result = tailCaller(i % 2 ? sum1 : sum2, a, b);
+
+    return result;
+}
+
+let result = test(20, 2);
+if (result != 42)
+    throw "Unexpected result: " + result;

Modified: trunk/Source/_javascript_Core/ChangeLog (209672 => 209673)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-10 20:44:50 UTC (rev 209672)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-10 21:04:05 UTC (rev 209673)
@@ -1,3 +1,24 @@
+2016-12-10  Michael Saboff  <[email protected]>
+
+        REGRESSION(r209653) Crash in CallFrameShuffler::snapshot()
+        https://bugs.webkit.org/show_bug.cgi?id=165728
+
+        Reviewed by Filip Pizlo.
+
+        It can be the case that a JSValueReg's CachedRecovery is the source for mutliple
+        GPRs. We only store the CachedRecovery in one slot of m_newRegisters to simplify
+        the recovery process. This is also done for the case where the recovery source
+        and destination are the same GPR.
+
+        In light of this change, snapshot needs to be taught that one CacheRecovery is
+        the source for multiple registers.  This is done by using a two step process.
+        First find all the argument CachedRecovery's and create a vector mapping all of
+        the target GPRs and the source recovery.  Then use that vector to get the
+        recovery for each register.
+
+        * jit/CallFrameShuffler.h:
+        (JSC::CallFrameShuffler::snapshot):
+
 2016-12-10  Keith Miller  <[email protected]>
 
         Fix indirect_call if the result type is used.

Modified: trunk/Source/_javascript_Core/jit/CallFrameShuffler.h (209672 => 209673)


--- trunk/Source/_javascript_Core/jit/CallFrameShuffler.h	2016-12-10 20:44:50 UTC (rev 209672)
+++ trunk/Source/_javascript_Core/jit/CallFrameShuffler.h	2016-12-10 21:04:05 UTC (rev 209673)
@@ -113,13 +113,33 @@
             data.callee = cachedRecovery->recovery();
         }
         data.args.resize(argCount());
+
+        Vector<ValueRecovery> registerArgRecoveries;
+#if USE(JSVALUE64)
+        // Find cached recoveries for all argument registers.
+        // We do this here, because a cached recovery may be the source for multiple
+        // argument registers, but it is only stored in one m_newRegister index.
+        if (data.argumentsInRegisters) {
+            unsigned maxArgumentRegister = std::min(static_cast<unsigned>(argCount()), NUMBER_OF_JS_FUNCTION_ARGUMENT_REGISTERS);
+            registerArgRecoveries.resize(maxArgumentRegister);
+            for (size_t i = 0; i < maxArgumentRegister; ++i) {
+                Reg reg { argumentRegisterForFunctionArgument(i) };
+                CachedRecovery* cachedRecovery { m_newRegisters[reg] };
+                if (cachedRecovery) {
+                    for (auto jsValueReg : cachedRecovery->gprTargets())
+                        registerArgRecoveries[jsFunctionArgumentForArgumentRegister(jsValueReg.gpr())] = cachedRecovery->recovery();
+                }
+            }
+        }
+#endif
+        
         for (size_t i = 0; i < argCount(); ++i) {
             if (argumentsLocation == StackArgs || i >= NUMBER_OF_JS_FUNCTION_ARGUMENT_REGISTERS)
                 data.args[i] = getNew(virtualRegisterForArgument(i))->recovery();
             else {
                 Reg reg { argumentRegisterForFunctionArgument(i) };
-                CachedRecovery* cachedRecovery { m_newRegisters[reg] };
-                data.args[i] = cachedRecovery->recovery();
+                ASSERT(registerArgRecoveries[i]);
+                data.args[i] = registerArgRecoveries[i];
             }
         }
         for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
@@ -440,15 +460,22 @@
     bool tryAcquireTagTypeNumber();
 #endif
 
-    // This stores, for each register, information about the recovery
-    // for the value that should eventually go into that register. The
-    // only registers that have a target recovery will be callee-save
-    // registers, as well as possibly one JSValueRegs for holding the
-    // callee.
+    // This stores information about the recovery for the value that
+    // should eventually go into that register. In some cases there
+    // are recoveries that have multiple targets. For those recoveries,
+    // only the first target register in the map has the recovery.
+    // We optimize the case where there are multiple targets for one
+    // recovery where one of those targets is also the source register.
+    // Restoring the first target becomes a nop and simplifies the logic
+    // of restoring the remaining targets.
     //
     // Once the correct value has been put into the registers, and
     // contrary to what we do with m_newFrame, we keep the entry in
     // m_newRegisters to simplify spilling.
+    //
+    // If a recovery has multiple target registers, we copy the value
+    // from the first target register to the remaining target registers
+    // at the end of the shuffling process.
     RegisterMap<CachedRecovery*> m_newRegisters;
 
     template<typename CheckFunctor>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to