Ignore:
Timestamp:
Jun 16, 2022, 7:20:29 PM (3 years ago)
Author:
[email protected]
Message:

The extraMemorySize() get wrong when transferring ArrayBuffer from Worker VM
https://bugs.webkit.org/show_bug.cgi?id=241559

Reviewed by Yusuke Suzuki.

When ArrayBuffer is passed in the transfer option of postMessage(), the size cached in
heap.m_arrayBuffers get incorrect and that makes extraMemorySize() bigger than actual
managed size.

This patch added the code to reduce size from GCIncomingRefCountedSet.m_bytes when
ArrayBuffer is actually transferring from VM.

Also for verification, added a simple check code in GCIncomingRefCountedSet.addReference
with constexpr flag.

  • Source/JavaScriptCore/heap/GCIncomingRefCountedSet.h:
  • Source/JavaScriptCore/heap/GCIncomingRefCountedSetInlines.h:

(JSC::GCIncomingRefCountedSet<T>::sweep):
(JSC::GCIncomingRefCountedSet<T>::reduceSize):

  • Source/JavaScriptCore/heap/Heap.cpp:

(JSC::Heap::reduceArrayBufferSize):

  • Source/JavaScriptCore/heap/Heap.h:
  • Source/JavaScriptCore/runtime/ArrayBuffer.cpp:

(JSC::ArrayBuffer::transferTo):

Canonical link: https://commits.webkit.org/251629@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/GCIncomingRefCountedSetInlines.h

    r243467 r295624  
    7373        m_vector.removeLast();
    7474    }
     75
     76    constexpr bool verify = false;
     77    if constexpr (verify) {
     78        CheckedSize size;
     79        for (size_t i = m_vector.size(); i--;) {
     80            T* object = m_vector[i];
     81            size += object->gcSizeEstimateInBytes();
     82        }
     83        ASSERT(m_bytes == size);
     84    }
     85}
     86
     87template<typename T>
     88void GCIncomingRefCountedSet<T>::reduceSize(size_t bytes)
     89{
     90    ASSERT(m_bytes >= bytes);
     91    m_bytes -= bytes;
    7592}
    7693
Note: See TracChangeset for help on using the changeset viewer.