Title: [251399] trunk/Source/_javascript_Core
Revision
251399
Author
[email protected]
Date
2019-10-21 17:04:27 -0700 (Mon, 21 Oct 2019)

Log Message

Fix issues when setting public length on ArrayWithContiguous type butterflies.
https://bugs.webkit.org/show_bug.cgi?id=203211
<rdar://problem/56476097>

Reviewed by Keith Miller and Saam Barati.

For ArrayWithContiguous type butterflies, SlotVisitor scans up to the public
length of the butterfly.  When setting a new public length, if the new public
length is greater than the current, we should always writeBarrier after the
setting of the new public length.  Otherwise, there can be a race where the GC
scans the butterfly after new values have been written to it but before the
public length as been updated.  As a result, the new values never get scanned.

For the DFG and FTL, the StoreBarrierInsertionPhase is responsible for inserting
the writeBarriers after the node.  Hence, the writeBarrier is guaranteed to be
after the publicLength has been updated.

* runtime/JSArray.cpp:
(JSC::JSArray::shiftCountWithArrayStorage):
(JSC::JSArray::shiftCountWithAnyIndexingType):
* runtime/JSArrayInlines.h:
(JSC::JSArray::pushInline):
* runtime/JSObject.cpp:
(JSC::JSObject::putByIndex):
(JSC::JSObject::reallocateAndShrinkButterfly):
* runtime/JSObject.h:
(JSC::JSObject::setIndexQuickly):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (251398 => 251399)


--- trunk/Source/_javascript_Core/ChangeLog	2019-10-21 23:56:48 UTC (rev 251398)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-10-22 00:04:27 UTC (rev 251399)
@@ -1,3 +1,33 @@
+2019-10-21  Mark Lam  <[email protected]>
+
+        Fix issues when setting public length on ArrayWithContiguous type butterflies.
+        https://bugs.webkit.org/show_bug.cgi?id=203211
+        <rdar://problem/56476097>
+
+        Reviewed by Keith Miller and Saam Barati.
+
+        For ArrayWithContiguous type butterflies, SlotVisitor scans up to the public
+        length of the butterfly.  When setting a new public length, if the new public
+        length is greater than the current, we should always writeBarrier after the
+        setting of the new public length.  Otherwise, there can be a race where the GC
+        scans the butterfly after new values have been written to it but before the
+        public length as been updated.  As a result, the new values never get scanned.
+
+        For the DFG and FTL, the StoreBarrierInsertionPhase is responsible for inserting
+        the writeBarriers after the node.  Hence, the writeBarrier is guaranteed to be
+        after the publicLength has been updated.
+
+        * runtime/JSArray.cpp:
+        (JSC::JSArray::shiftCountWithArrayStorage):
+        (JSC::JSArray::shiftCountWithAnyIndexingType):
+        * runtime/JSArrayInlines.h:
+        (JSC::JSArray::pushInline):
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::putByIndex):
+        (JSC::JSObject::reallocateAndShrinkButterfly):
+        * runtime/JSObject.h:
+        (JSC::JSObject::setIndexQuickly):
+
 2019-10-21  Devin Rousso  <[email protected]>
 
         Web Inspector: make ObjC protocol dispatcher commands optional and add `respondsToSelector` checks to allow other inspector clients to choose what they implement

Modified: trunk/Source/_javascript_Core/runtime/JSArray.cpp (251398 => 251399)


--- trunk/Source/_javascript_Core/runtime/JSArray.cpp	2019-10-21 23:56:48 UTC (rev 251398)
+++ trunk/Source/_javascript_Core/runtime/JSArray.cpp	2019-10-22 00:04:27 UTC (rev 251399)
@@ -894,7 +894,8 @@
 
     Butterfly* butterfly = this->butterfly();
     
-    switch (indexingType()) {
+    auto indexingType = this->indexingType();
+    switch (indexingType) {
     case ArrayClass:
         return true;
         
@@ -934,13 +935,14 @@
 
         for (unsigned i = end; i < oldLength; ++i)
             butterfly->contiguous().at(this, i).clear();
-        
+
         butterfly->setPublicLength(oldLength - count);
 
         // Our memmoving of values around in the array could have concealed some of them from
         // the collector. Let's make sure that the collector scans this object again.
-        vm.heap.writeBarrier(this);
-        
+        if (indexingType == ArrayWithContiguous)
+            vm.heap.writeBarrier(this);
+
         return true;
     }
         

Modified: trunk/Source/_javascript_Core/runtime/JSArrayInlines.h (251398 => 251399)


--- trunk/Source/_javascript_Core/runtime/JSArrayInlines.h	2019-10-21 23:56:48 UTC (rev 251398)
+++ trunk/Source/_javascript_Core/runtime/JSArrayInlines.h	2019-10-22 00:04:27 UTC (rev 251399)
@@ -157,8 +157,9 @@
         unsigned length = butterfly->publicLength();
         ASSERT(length <= butterfly->vectorLength());
         if (length < butterfly->vectorLength()) {
-            butterfly->contiguous().at(this, length).set(vm, this, value);
+            butterfly->contiguous().at(this, length).setWithoutWriteBarrier(value);
             butterfly->setPublicLength(length + 1);
+            vm.heap.writeBarrier(this, value);
             return;
         }
 

Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (251398 => 251399)


--- trunk/Source/_javascript_Core/runtime/JSObject.cpp	2019-10-21 23:56:48 UTC (rev 251398)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp	2019-10-22 00:04:27 UTC (rev 251399)
@@ -891,9 +891,10 @@
         Butterfly* butterfly = thisObject->butterfly();
         if (propertyName >= butterfly->vectorLength())
             break;
-        butterfly->contiguous().at(thisObject, propertyName).set(vm, thisObject, value);
+        butterfly->contiguous().at(thisObject, propertyName).setWithoutWriteBarrier(value);
         if (propertyName >= butterfly->publicLength())
             butterfly->setPublicLength(propertyName + 1);
+        vm.heap.writeBarrier(thisObject, value);
         return true;
     }
         
@@ -3429,6 +3430,7 @@
     ASSERT(length <= MAX_STORAGE_VECTOR_LENGTH);
     ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType()));
     ASSERT(m_butterfly->vectorLength() > length);
+    ASSERT(m_butterfly->publicLength() >= length);
     ASSERT(!m_butterfly->indexingHeader()->preCapacity(structure(vm)));
 
     DeferGC deferGC(vm.heap);

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (251398 => 251399)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2019-10-21 23:56:48 UTC (rev 251398)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2019-10-22 00:04:27 UTC (rev 251399)
@@ -409,9 +409,10 @@
         }
         case ALL_CONTIGUOUS_INDEXING_TYPES: {
             ASSERT(i < butterfly->vectorLength());
-            butterfly->contiguous().at(this, i).set(vm, this, v);
+            butterfly->contiguous().at(this, i).setWithoutWriteBarrier(v);
             if (i >= butterfly->publicLength())
                 butterfly->setPublicLength(i + 1);
+            vm.heap.writeBarrier(this, v);
             break;
         }
         case ALL_DOUBLE_INDEXING_TYPES: {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to