Title: [253694] branches/safari-609.1.13-branch/Source/_javascript_Core
Revision
253694
Author
[email protected]
Date
2019-12-18 10:47:38 -0800 (Wed, 18 Dec 2019)

Log Message

Cherry-pick r253608. rdar://problem/57978411

    ASSERTION FAILED: length <= maximumLength in js-fixed-array-out-of-memory.js
    https://bugs.webkit.org/show_bug.cgi?id=205259
    <rdar://problem/57978411>

    Reviewed by Mark Lam.

    JSImmutableButterfly has moderate size limit on its length, while JSFixedArray does not.
    We should check this maximumLength when creating it in Spread. And if it exceeds, we should
    throw OOM error.

    * dfg/DFGSpeculativeJIT.cpp:
    (JSC::DFG::SpeculativeJIT::compileSpread):
    * ftl/FTLLowerDFGToB3.cpp:
    (JSC::FTL::DFG::LowerDFGToB3::compileSpread):
    * runtime/ArrayConventions.h:
    * runtime/IndexingHeader.h:
    * runtime/JSImmutableButterfly.h:
    (JSC::JSImmutableButterfly::tryCreate):
    (JSC::JSImmutableButterfly::allocationSize):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253608 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/ChangeLog (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/ChangeLog	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/ChangeLog	2019-12-18 18:47:38 UTC (rev 253694)
@@ -1,3 +1,51 @@
+2019-12-18  Kocsen Chung  <[email protected]>
+
+        Cherry-pick r253608. rdar://problem/57978411
+
+    ASSERTION FAILED: length <= maximumLength in js-fixed-array-out-of-memory.js
+    https://bugs.webkit.org/show_bug.cgi?id=205259
+    <rdar://problem/57978411>
+    
+    Reviewed by Mark Lam.
+    
+    JSImmutableButterfly has moderate size limit on its length, while JSFixedArray does not.
+    We should check this maximumLength when creating it in Spread. And if it exceeds, we should
+    throw OOM error.
+    
+    * dfg/DFGSpeculativeJIT.cpp:
+    (JSC::DFG::SpeculativeJIT::compileSpread):
+    * ftl/FTLLowerDFGToB3.cpp:
+    (JSC::FTL::DFG::LowerDFGToB3::compileSpread):
+    * runtime/ArrayConventions.h:
+    * runtime/IndexingHeader.h:
+    * runtime/JSImmutableButterfly.h:
+    (JSC::JSImmutableButterfly::tryCreate):
+    (JSC::JSImmutableButterfly::allocationSize):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253608 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-12-16  Yusuke Suzuki  <[email protected]>
+
+            ASSERTION FAILED: length <= maximumLength in js-fixed-array-out-of-memory.js
+            https://bugs.webkit.org/show_bug.cgi?id=205259
+            <rdar://problem/57978411>
+
+            Reviewed by Mark Lam.
+
+            JSImmutableButterfly has moderate size limit on its length, while JSFixedArray does not.
+            We should check this maximumLength when creating it in Spread. And if it exceeds, we should
+            throw OOM error.
+
+            * dfg/DFGSpeculativeJIT.cpp:
+            (JSC::DFG::SpeculativeJIT::compileSpread):
+            * ftl/FTLLowerDFGToB3.cpp:
+            (JSC::FTL::DFG::LowerDFGToB3::compileSpread):
+            * runtime/ArrayConventions.h:
+            * runtime/IndexingHeader.h:
+            * runtime/JSImmutableButterfly.h:
+            (JSC::JSImmutableButterfly::tryCreate):
+            (JSC::JSImmutableButterfly::allocationSize):
+
 2019-12-13  Yusuke Suzuki  <[email protected]>
 
         [JSC] Remove JSFixedArray, and use JSImmutableButterfly instead

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2019-12-18 18:47:38 UTC (rev 253694)
@@ -7918,6 +7918,7 @@
 
         m_jit.loadPtr(MacroAssembler::Address(argument, JSObject::butterflyOffset()), lengthGPR);
         m_jit.load32(MacroAssembler::Address(lengthGPR, Butterfly::offsetOfPublicLength()), lengthGPR);
+        slowPath.append(m_jit.branch32(MacroAssembler::Above, lengthGPR, TrustedImm32(MAX_STORAGE_VECTOR_LENGTH)));
         static_assert(sizeof(JSValue) == 8 && 1 << 3 == 8, "This is strongly assumed in the code below.");
         m_jit.move(lengthGPR, scratch1GPR);
         m_jit.lshift32(TrustedImm32(3), scratch1GPR);
@@ -7963,12 +7964,10 @@
             done.append(m_jit.jump());
         }
         
-        m_jit.mutatorFence(vm());
+        addSlowPathGenerator(slowPathCall(slowPath, this, operationSpreadFastArray, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), argument));
 
-        slowPath.link(&m_jit);
-        addSlowPathGenerator(slowPathCall(m_jit.jump(), this, operationSpreadFastArray, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), argument));
-
         done.link(&m_jit);
+        m_jit.mutatorFence(vm());
         cellResult(resultGPR, node);
 #else
         flushRegisters();

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2019-12-18 18:47:38 UTC (rev 253694)
@@ -6691,6 +6691,8 @@
             LBasicBlock slowAllocation = m_out.newBlock();
             LBasicBlock continuation = m_out.newBlock();
 
+            ASSERT(immutableButterfly->length() <= MAX_STORAGE_VECTOR_LENGTH);
+
             LValue fastImmutableButterflyValue = allocateVariableSizedCell<JSImmutableButterfly>(
                 m_out.constIntPtr(JSImmutableButterfly::allocationSize(immutableButterfly->length()).unsafeGet()),
                 m_graph.m_vm.immutableButterflyStructures[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous) - NumberOfIndexingShapes].get(), slowAllocation);
@@ -6729,11 +6731,11 @@
 
             ASSERT(m_graph.isWatchingHavingABadTimeWatchpoint(m_node->child1().node()));
 
+            LBasicBlock fastAllocation = m_out.newBlock();
             LBasicBlock loopHeader = m_out.newBlock();
             LBasicBlock loopBody = m_out.newBlock();
             LBasicBlock slowAllocation = m_out.newBlock();
             LBasicBlock continuation = m_out.newBlock();
-            LBasicBlock lastNext = m_out.insertNewBlocksBefore(loopHeader);
 
             InlineCallFrame* inlineCallFrame = m_node->child1()->origin.semantic.inlineCallFrame();
             unsigned numberOfArgumentsToSkip = m_node->child1()->numberOfArgumentsToSkip();
@@ -6743,7 +6745,9 @@
             LValue size = m_out.add(
                 m_out.shl(m_out.zeroExtPtr(length), m_out.constInt32(3)),
                 m_out.constIntPtr(JSImmutableButterfly::offsetOfData()));
+            m_out.branch(m_out.above(length, m_out.constInt32(MAX_STORAGE_VECTOR_LENGTH)), rarely(slowAllocation), usually(fastAllocation));
 
+            LBasicBlock lastNext = m_out.appendTo(fastAllocation, slowAllocation);
             LValue fastArrayValue = allocateVariableSizedCell<JSImmutableButterfly>(size, m_graph.m_vm.immutableButterflyStructures[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous) - NumberOfIndexingShapes].get(), slowAllocation);
             LValue fastArrayStorage = toButterfly(fastArrayValue);
             m_out.store32(length, fastArrayStorage, m_heaps.Butterfly_vectorLength);
@@ -6790,6 +6794,7 @@
             LBasicBlock loopSelection = m_out.newBlock();
             LBasicBlock contiguousLoopStart = m_out.newBlock();
             LBasicBlock doubleLoopStart = m_out.newBlock();
+            LBasicBlock fastPath = m_out.newBlock();
             LBasicBlock slowPath = m_out.newBlock();
             LBasicBlock continuation = m_out.newBlock();
 
@@ -6808,13 +6813,15 @@
             ValueFromBlock sharedResult = m_out.anchor(m_out.add(butterfly, m_out.constIntPtr(-JSImmutableButterfly::offsetOfData())));
             m_out.jump(continuation);
 
-            m_out.appendTo(preLoop, loopSelection);
+            m_out.appendTo(preLoop, fastPath);
             LValue length = m_out.load32NonNegative(butterfly, m_heaps.Butterfly_publicLength);
             static_assert(sizeof(JSValue) == 8 && 1 << 3 == 8, "Assumed in the code below.");
             LValue size = m_out.add(
                 m_out.shl(m_out.zeroExtPtr(length), m_out.constInt32(3)),
                 m_out.constIntPtr(JSImmutableButterfly::offsetOfData()));
+            m_out.branch(m_out.above(length, m_out.constInt32(MAX_STORAGE_VECTOR_LENGTH)), rarely(slowPath), usually(fastPath));
 
+            m_out.appendTo(fastPath, loopSelection);
             LValue fastAllocation = allocateVariableSizedCell<JSImmutableButterfly>(size, m_graph.m_vm.immutableButterflyStructures[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous) - NumberOfIndexingShapes].get(), slowPath);
             LValue fastStorage = toButterfly(fastAllocation);
             m_out.store32(length, fastStorage, m_heaps.Butterfly_vectorLength);

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/ArrayConventions.h (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/ArrayConventions.h	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/ArrayConventions.h	2019-12-18 18:47:38 UTC (rev 253694)
@@ -54,7 +54,7 @@
 
 // Define the maximum storage vector length to be 2^32 / sizeof(JSValue) / 2 to ensure that
 // there is no risk of overflow.
-#define MAX_STORAGE_VECTOR_LENGTH (static_cast<unsigned>(IndexingHeader::maximumLength))
+#define MAX_STORAGE_VECTOR_LENGTH IndexingHeader::maximumLength
 
 // These values have to be macros to be used in max() and min() without introducing
 // a PIC branch in Mach-O binaries, see <rdar://problem/5971391>.

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/IndexingHeader.h (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/IndexingHeader.h	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/IndexingHeader.h	2019-12-18 18:47:38 UTC (rev 253694)
@@ -39,7 +39,7 @@
 public:
     // Define the maximum storage vector length to be 2^32 / sizeof(JSValue) / 2 to ensure that
     // there is no risk of overflow.
-    enum { maximumLength = 0x10000000 };
+    static constexpr unsigned maximumLength = 0x10000000;
     
     static ptrdiff_t offsetOfIndexingHeader() { return -static_cast<ptrdiff_t>(sizeof(IndexingHeader)); }
     

Modified: branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/JSImmutableButterfly.h (253693 => 253694)


--- branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/JSImmutableButterfly.h	2019-12-18 18:28:49 UTC (rev 253693)
+++ branches/safari-609.1.13-branch/Source/_javascript_Core/runtime/JSImmutableButterfly.h	2019-12-18 18:47:38 UTC (rev 253694)
@@ -47,16 +47,16 @@
         return Structure::create(vm, globalObject, prototype, TypeInfo(JSImmutableButterflyType, StructureFlags), info(), indexingType);
     }
 
-    ALWAYS_INLINE static JSImmutableButterfly* tryCreate(VM& vm, Structure* structure, unsigned size)
+    ALWAYS_INLINE static JSImmutableButterfly* tryCreate(VM& vm, Structure* structure, unsigned length)
     {
-        Checked<size_t, RecordOverflow> checkedAllocationSize = allocationSize(size);
-        if (UNLIKELY(checkedAllocationSize.hasOverflowed()))
+        if (UNLIKELY(length > IndexingHeader::maximumLength))
             return nullptr;
 
-        void* buffer = tryAllocateCell<JSImmutableButterfly>(vm.heap, checkedAllocationSize.unsafeGet());
+        // Because of the above maximumLength requirement, allocationSize can never overflow.
+        void* buffer = tryAllocateCell<JSImmutableButterfly>(vm.heap, allocationSize(length).unsafeGet());
         if (UNLIKELY(!buffer))
             return nullptr;
-        JSImmutableButterfly* result = new (NotNull, buffer) JSImmutableButterfly(vm, structure, size);
+        JSImmutableButterfly* result = new (NotNull, buffer) JSImmutableButterfly(vm, structure, length);
         result->finishCreation(vm);
         return result;
     }
@@ -180,7 +180,7 @@
         return OBJECT_OFFSETOF(JSImmutableButterfly, m_header) + IndexingHeader::offsetOfVectorLength();
     }
 
-    static Checked<size_t, RecordOverflow> allocationSize(Checked<size_t, RecordOverflow> numItems)
+    static Checked<size_t> allocationSize(Checked<size_t> numItems)
     {
         return offsetOfData() + numItems * sizeof(WriteBarrier<Unknown>);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to