- Revision
- 252160
- Author
- [email protected]
- Date
- 2019-11-06 16:29:19 -0800 (Wed, 06 Nov 2019)
Log Message
JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut() should fire its watchpoint as the last step.
https://bugs.webkit.org/show_bug.cgi?id=203867
<rdar://problem/56813514>
Reviewed by Saam Barati.
JSTests:
* stress/racy-slow-put-cloned-arguments-when-having-a-bad-time.js: Added.
Source/_javascript_Core:
JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut() should make all
the array structures SlowPut before firing the watchpoint. Otherwise, the
concurrent JIT may think it's grabbing the slow put version of the structure, but
is actually grabbing the non-SlowPut version because it happened to beat the
mutator in a race to read the structure before the mutator makes it SlowPut.
Also removed some assertions in DFGSpeculativeJIT.cpp that are vulnerable to races
between when the mutator makes all array structures SlowPut and when it fires the
HavingABadTime watchpoint. The FTL equivalent did not have these assertions.
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileCreateRest):
(JSC::DFG::SpeculativeJIT::compileNewArray):
(JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (252159 => 252160)
--- trunk/JSTests/ChangeLog 2019-11-07 00:12:17 UTC (rev 252159)
+++ trunk/JSTests/ChangeLog 2019-11-07 00:29:19 UTC (rev 252160)
@@ -1,3 +1,13 @@
+2019-11-06 Mark Lam <[email protected]>
+
+ JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut() should fire its watchpoint as the last step.
+ https://bugs.webkit.org/show_bug.cgi?id=203867
+ <rdar://problem/56813514>
+
+ Reviewed by Saam Barati.
+
+ * stress/racy-slow-put-cloned-arguments-when-having-a-bad-time.js: Added.
+
2019-11-06 Commit Queue <[email protected]>
Unreviewed, rolling out r251940.
Added: trunk/JSTests/stress/racy-slow-put-cloned-arguments-when-having-a-bad-time.js (0 => 252160)
--- trunk/JSTests/stress/racy-slow-put-cloned-arguments-when-having-a-bad-time.js (rev 0)
+++ trunk/JSTests/stress/racy-slow-put-cloned-arguments-when-having-a-bad-time.js 2019-11-07 00:29:19 UTC (rev 252160)
@@ -0,0 +1,17 @@
+//@ requireOptions("--jitPolicyScale=0")
+//@ skip if ["arm", "mips"].include?($architecture)
+//@ slow!
+
+for (let j = 0; j < 500; j++) {
+ runString(`
+ function test() {
+ "use strict";
+ return arguments;
+ }
+ noInline(test);
+ for (var i = 0; i < 10; i++)
+ test();
+ Object.defineProperty(Object.prototype, 0, {});
+ test();
+ `);
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (252159 => 252160)
--- trunk/Source/_javascript_Core/ChangeLog 2019-11-07 00:12:17 UTC (rev 252159)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-11-07 00:29:19 UTC (rev 252160)
@@ -1,3 +1,28 @@
+2019-11-06 Mark Lam <[email protected]>
+
+ JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut() should fire its watchpoint as the last step.
+ https://bugs.webkit.org/show_bug.cgi?id=203867
+ <rdar://problem/56813514>
+
+ Reviewed by Saam Barati.
+
+ JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut() should make all
+ the array structures SlowPut before firing the watchpoint. Otherwise, the
+ concurrent JIT may think it's grabbing the slow put version of the structure, but
+ is actually grabbing the non-SlowPut version because it happened to beat the
+ mutator in a race to read the structure before the mutator makes it SlowPut.
+
+ Also removed some assertions in DFGSpeculativeJIT.cpp that are vulnerable to races
+ between when the mutator makes all array structures SlowPut and when it fires the
+ HavingABadTime watchpoint. The FTL equivalent did not have these assertions.
+
+ * dfg/DFGSpeculativeJIT.cpp:
+ (JSC::DFG::SpeculativeJIT::compileCreateRest):
+ (JSC::DFG::SpeculativeJIT::compileNewArray):
+ (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
+ * runtime/JSGlobalObject.cpp:
+ (JSC::JSGlobalObject::fireWatchpointAndMakeAllArrayStructuresSlowPut):
+
2019-11-06 Commit Queue <[email protected]>
Unreviewed, rolling out r251940.
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (252159 => 252160)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2019-11-07 00:12:17 UTC (rev 252159)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2019-11-07 00:29:19 UTC (rev 252160)
@@ -7815,7 +7815,6 @@
// always be bounded by stack size. Realistically, we won't be able to push enough
// arguments to have arrayLength exceed MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH.
bool shouldAllowForArrayStorageStructureForLargeArrays = false;
- ASSERT(m_jit.graph().globalObjectFor(node->origin.semantic)->restParameterStructure()->indexingMode() == ArrayWithContiguous || m_jit.graph().globalObjectFor(node->origin.semantic)->isHavingABadTime());
compileAllocateNewArrayWithSize(m_jit.graph().globalObjectFor(node->origin.semantic), arrayResultGPR, arrayLengthGPR, ArrayWithContiguous, shouldAllowForArrayStorageStructureForLargeArrays);
GPRTemporary argumentsStart(this);
@@ -7979,7 +7978,6 @@
JSGlobalObject* globalObject = m_jit.graph().globalObjectFor(node->origin.semantic);
RegisteredStructure structure = m_jit.graph().registerStructure(globalObject->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
if (!globalObject->isHavingABadTime() && !hasAnyArrayStorage(node->indexingType())) {
- DFG_ASSERT(m_jit.graph(), node, structure->indexingType() == node->indexingType(), structure->indexingType(), node->indexingType());
ASSERT(
hasUndecided(structure->indexingType())
|| hasInt32(structure->indexingType())
@@ -8173,7 +8171,6 @@
// ensured above that the spread array length will definitely fit in a
// non-ArrayStorage shaped array.
bool shouldAllowForArrayStorageStructureForLargeArrays = false;
- ASSERT(m_jit.graph().globalObjectFor(node->origin.semantic)->restParameterStructure()->indexingType() == ArrayWithContiguous || m_jit.graph().globalObjectFor(node->origin.semantic)->isHavingABadTime());
compileAllocateNewArrayWithSize(m_jit.graph().globalObjectFor(node->origin.semantic), resultGPR, lengthGPR, ArrayWithContiguous, shouldAllowForArrayStorageStructureForLargeArrays);
}
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (252159 => 252160)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2019-11-07 00:12:17 UTC (rev 252159)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2019-11-07 00:29:19 UTC (rev 252160)
@@ -1565,12 +1565,6 @@
if (isHavingABadTime())
return;
- // Make sure that all allocations or indexed storage transitions that are inlining
- // the assumption that it's safe to transition to a non-SlowPut array storage don't
- // do so anymore.
- m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
- ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
-
// Make sure that all JSArray allocations that load the appropriate structure from
// this object now load a structure that uses SlowPut.
for (unsigned i = 0; i < NumberOfArrayIndexingModes; ++i)
@@ -1584,6 +1578,16 @@
m_regExpMatchesArrayWithGroupsStructure.set(vm, this, slowPutStructure);
slowPutStructure = ClonedArguments::createSlowPutStructure(vm, this, m_objectPrototype.get());
m_clonedArgumentsStructure.set(vm, this, slowPutStructure);
+
+ // Make sure that all allocations or indexed storage transitions that are inlining
+ // the assumption that it's safe to transition to a non-SlowPut array storage don't
+ // do so anymore.
+ // Note: we are deliberately firing the watchpoint here at the end only after
+ // making all the array structures SlowPut. This ensures that the concurrent
+ // JIT threads will always get the SlowPut versions of the structures if
+ // isHavingABadTime() returns true. The concurrent JIT relies on this.
+ m_havingABadTimeWatchpoint->fireAll(vm, "Having a bad time");
+ ASSERT(isHavingABadTime()); // The watchpoint is what tells us that we're having a bad time.
};
void JSGlobalObject::haveABadTime(VM& vm)