[JSC] Use new extra memory reporting in SparseArrayMap
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Oct 2018 19:49:45 +0000 (19:49 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Oct 2018 19:49:45 +0000 (19:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190278

Reviewed by Keith Miller.

This patch switches the extra memory reporting mechanism from deprecatedReportExtraMemory
to reportExtraMemoryAllocated & reportExtraMemoryVisited in SparseArrayMap.

* runtime/SparseArrayValueMap.cpp:
(JSC::SparseArrayValueMap::add):
(JSC::SparseArrayValueMap::visitChildren):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/SparseArrayValueMap.cpp

index 64e35cf..9a19cb2 100644 (file)
@@ -1,5 +1,19 @@
 2018-10-05  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
 
+        [JSC] Use new extra memory reporting in SparseArrayMap
+        https://bugs.webkit.org/show_bug.cgi?id=190278
+
+        Reviewed by Keith Miller.
+
+        This patch switches the extra memory reporting mechanism from deprecatedReportExtraMemory
+        to reportExtraMemoryAllocated & reportExtraMemoryVisited in SparseArrayMap.
+
+        * runtime/SparseArrayValueMap.cpp:
+        (JSC::SparseArrayValueMap::add):
+        (JSC::SparseArrayValueMap::visitChildren):
+
+2018-10-05  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
         [JSC][Linux] Support Perf JITDump logging
         https://bugs.webkit.org/show_bug.cgi?id=189893
 
index e3cfa5a..73553d9 100644 (file)
@@ -69,18 +69,18 @@ Structure* SparseArrayValueMap::createStructure(VM& vm, JSGlobalObject* globalOb
 SparseArrayValueMap::AddResult SparseArrayValueMap::add(JSObject* array, unsigned i)
 {
     AddResult result;
-    size_t capacity;
+    size_t increasedCapacity = 0;
     {
         auto locker = holdLock(cellLock());
         result = m_map.add(i, SparseArrayEntry());
-        capacity = m_map.capacity();
-    }
-    if (capacity > m_reportedCapacity) {
-        // FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
-        // https://bugs.webkit.org/show_bug.cgi?id=142595
-        Heap::heap(array)->deprecatedReportExtraMemory((capacity - m_reportedCapacity) * (sizeof(unsigned) + sizeof(WriteBarrier<Unknown>)));
-        m_reportedCapacity = capacity;
+        size_t capacity = m_map.capacity();
+        if (capacity > m_reportedCapacity) {
+            increasedCapacity = capacity - m_reportedCapacity;
+            m_reportedCapacity = capacity;
+        }
     }
+    if (increasedCapacity)
+        Heap::heap(array)->reportExtraMemoryAllocated(increasedCapacity * sizeof(Map::KeyValuePairType));
     return result;
 }
 
@@ -212,15 +212,16 @@ JSValue SparseArrayEntry::getNonSparseMode() const
     return Base::get();
 }
 
-void SparseArrayValueMap::visitChildren(JSCell* thisObject, SlotVisitor& visitor)
+void SparseArrayValueMap::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
-    Base::visitChildren(thisObject, visitor);
-
-    auto locker = holdLock(thisObject->cellLock());
-    SparseArrayValueMap* thisMap = jsCast<SparseArrayValueMap*>(thisObject);
-    iterator end = thisMap->m_map.end();
-    for (iterator it = thisMap->m_map.begin(); it != end; ++it)
-        visitor.append(it->value.asValue());
+    Base::visitChildren(cell, visitor);
+    SparseArrayValueMap* thisObject = jsCast<SparseArrayValueMap*>(cell);
+    {
+        auto locker = holdLock(thisObject->cellLock());
+        for (auto& entry : thisObject->m_map)
+            visitor.append(entry.value.asValue());
+    }
+    visitor.reportExtraMemoryVisited(thisObject->m_reportedCapacity * sizeof(Map::KeyValuePairType));
 }
 
 } // namespace JSC