bmalloc: rolled out the tryLock experiment
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Apr 2014 00:12:16 +0000 (00:12 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Apr 2014 00:12:16 +0000 (00:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131328

Reviewed by Andreas Kling.

It wasn't a speedup.

* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::processSmallAllocatorLog):
(bmalloc::Allocator::processMediumAllocatorLog):
* bmalloc/Deallocator.cpp:
(bmalloc::Deallocator::processObjectLog):
(bmalloc::Deallocator::deallocateSlowCase):
(bmalloc::Deallocator::deallocateSmallLine):
(bmalloc::Deallocator::deallocateMediumLine):
* bmalloc/Deallocator.h:
(bmalloc::Deallocator::deallocateFastCase):
* bmalloc/Heap.h:
(bmalloc::Heap::deallocateSmallLine):
(bmalloc::Heap::deallocateMediumLine):
* bmalloc/Line.h:
(bmalloc::Line<Traits>::deref):
* bmalloc/Page.h:
(bmalloc::Page<Traits>::deref):

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

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/Allocator.cpp
Source/bmalloc/bmalloc/Deallocator.cpp
Source/bmalloc/bmalloc/Deallocator.h
Source/bmalloc/bmalloc/Heap.h
Source/bmalloc/bmalloc/Line.h
Source/bmalloc/bmalloc/Page.h

index a758227..f52e5f1 100644 (file)
@@ -1,5 +1,33 @@
 2014-04-07  Geoffrey Garen  <ggaren@apple.com>
 
+        bmalloc: rolled out the tryLock experiment
+        https://bugs.webkit.org/show_bug.cgi?id=131328
+
+        Reviewed by Andreas Kling.
+
+        It wasn't a speedup.
+
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::processSmallAllocatorLog):
+        (bmalloc::Allocator::processMediumAllocatorLog):
+        * bmalloc/Deallocator.cpp:
+        (bmalloc::Deallocator::processObjectLog):
+        (bmalloc::Deallocator::deallocateSlowCase):
+        (bmalloc::Deallocator::deallocateSmallLine):
+        (bmalloc::Deallocator::deallocateMediumLine):
+        * bmalloc/Deallocator.h:
+        (bmalloc::Deallocator::deallocateFastCase):
+        * bmalloc/Heap.h:
+        (bmalloc::Heap::deallocateSmallLine):
+        (bmalloc::Heap::deallocateMediumLine):
+        * bmalloc/Line.h:
+        (bmalloc::Line<Traits>::deref):
+        * bmalloc/Page.h:
+        (bmalloc::Page<Traits>::deref):
+
+2014-04-07  Geoffrey Garen  <ggaren@apple.com>
+
         bmalloc
         https://bugs.webkit.org/show_bug.cgi?id=131170
 
index 3e537be..2e20ec1 100644 (file)
@@ -7,9 +7,9 @@
        objects = {
 
 /* Begin PBXBuildFile section */
-               14CC390518EA627D004AFE34 /* bmalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 14CC390418EA627D004AFE34 /* bmalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1448C30018F3754600502839 /* mbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1448C2FF18F3754300502839 /* mbmalloc.cpp */; };
+               1448C30118F3754C00502839 /* bmalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 1448C2FE18F3754300502839 /* bmalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14CC394C18EA8858004AFE34 /* libbmalloc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14F271BE18EA3963008C152F /* libbmalloc.a */; };
-               14D2868918EB759A0012420E /* mbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14D2868818EB759A0012420E /* mbmalloc.cpp */; };
                14F271C318EA3978008C152F /* Allocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 145F6855179DC8CA00D65598 /* Allocator.cpp */; };
                14F271C418EA397B008C152F /* Cache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144469E417A46BFE00F9EA1D /* Cache.cpp */; };
                14F271C518EA397E008C152F /* Deallocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 145F6859179DC90200D65598 /* Deallocator.cpp */; };
@@ -48,6 +48,8 @@
                144469E517A46BFE00F9EA1D /* Cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Cache.h; path = bmalloc/Cache.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                144469FD17A61F1F00F9EA1D /* PerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = PerThread.h; path = bmalloc/PerThread.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                14446A0717A61FA400F9EA1D /* PerProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PerProcess.h; path = bmalloc/PerProcess.h; sourceTree = "<group>"; };
+               1448C2FE18F3754300502839 /* bmalloc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = bmalloc.h; path = bmalloc/bmalloc.h; sourceTree = "<group>"; };
+               1448C2FF18F3754300502839 /* mbmalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = mbmalloc.cpp; path = bmalloc/mbmalloc.cpp; sourceTree = "<group>"; };
                144DCED617A649D90093B2F2 /* Mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mutex.h; path = bmalloc/Mutex.h; sourceTree = "<group>"; };
                144DCED817A728570093B2F2 /* Mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mutex.cpp; path = bmalloc/Mutex.cpp; sourceTree = "<group>"; };
                144F7BFB18BFC517003537F3 /* VMHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VMHeap.cpp; path = bmalloc/VMHeap.cpp; sourceTree = "<group>"; };
@@ -74,9 +76,7 @@
                147AAA9718CE5FB6002201E4 /* SmallTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallTraits.h; path = bmalloc/SmallTraits.h; sourceTree = "<group>"; };
                1485655E18A43AF900ED6942 /* BoundaryTag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BoundaryTag.h; path = bmalloc/BoundaryTag.h; sourceTree = "<group>"; };
                1485656018A43DBA00ED6942 /* ObjectType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectType.h; path = bmalloc/ObjectType.h; sourceTree = "<group>"; };
-               14CC390418EA627D004AFE34 /* bmalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bmalloc.h; path = bmalloc/bmalloc.h; sourceTree = SOURCE_ROOT; };
                14CC394418EA8743004AFE34 /* libmbmalloc.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libmbmalloc.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
-               14D2868818EB759A0012420E /* mbmalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mbmalloc.cpp; path = bmalloc/mbmalloc.cpp; sourceTree = SOURCE_ROOT; };
                14D9DB4517F2447100EAAB79 /* FixedVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = FixedVector.h; path = bmalloc/FixedVector.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                14DA32071885F9E6007269E0 /* Line.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Line.h; path = bmalloc/Line.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                14DA320C18875B09007269E0 /* Heap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Heap.h; path = bmalloc/Heap.h; sourceTree = "<group>"; };
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
+               1448C2FD18F3752B00502839 /* api */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1448C2FE18F3754300502839 /* bmalloc.h */,
+                               1448C2FF18F3754300502839 /* mbmalloc.cpp */,
+                       );
+                       name = api;
+                       sourceTree = "<group>";
+               };
                145F6836179DC45F00D65598 = {
                        isa = PBXGroup;
                        children = (
-                               14F271B718EA285B008C152F /* api */,
+                               1448C2FD18F3752B00502839 /* api */,
                                14D9DB4D17F2865C00EAAB79 /* cache */,
                                147AAA9C18CE6010002201E4 /* heap: large | xlarge */,
                                147AAA9A18CE5FD3002201E4 /* heap: small | medium */,
                        name = stdlib;
                        sourceTree = "<group>";
                };
-               14F271B718EA285B008C152F /* api */ = {
-                       isa = PBXGroup;
-                       children = (
-                               14CC390418EA627D004AFE34 /* bmalloc.h */,
-                               14D2868818EB759A0012420E /* mbmalloc.cpp */,
-                       );
-                       name = api;
-                       path = imalloc;
-                       sourceTree = "<group>";
-               };
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
                        isa = PBXHeadersBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               14CC390518EA627D004AFE34 /* bmalloc.h in Headers */,
+                               1448C30118F3754C00502839 /* bmalloc.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               14D2868918EB759A0012420E /* mbmalloc.cpp in Sources */,
+                               1448C30018F3754600502839 /* mbmalloc.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index fb43a58..60708fe 100644 (file)
@@ -75,9 +75,9 @@ void Allocator::processSmallAllocatorLog()
     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
 
     for (auto& logEntry : m_smallAllocatorLog) {
-        if (!logEntry.first->deref(logEntry.second))
+        if (!logEntry.first->deref(lock, logEntry.second))
             continue;
-        m_deallocator.deallocateSmallLine(logEntry.first);
+        m_deallocator.deallocateSmallLine(lock, logEntry.first);
     }
     m_smallAllocatorLog.clear();
 }
@@ -98,9 +98,9 @@ void Allocator::processMediumAllocatorLog()
     std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
 
     for (auto& logEntry : m_mediumAllocatorLog) {
-        if (!logEntry.first->deref(logEntry.second))
+        if (!logEntry.first->deref(lock, logEntry.second))
             continue;
-        m_deallocator.deallocateMediumLine(logEntry.first);
+        m_deallocator.deallocateMediumLine(lock, logEntry.first);
     }
     m_mediumAllocatorLog.clear();
 }
index 3c16493..69d6344 100644 (file)
@@ -65,18 +65,20 @@ void Deallocator::deallocateXLarge(void* object)
 
 void Deallocator::processObjectLog()
 {
+    std::lock_guard<Mutex> lock(PerProcess<Heap>::mutex());
+    
     for (auto object : m_objectLog) {
         if (isSmall(object)) {
             SmallLine* line = SmallLine::get(object);
-            if (!line->deref())
+            if (!line->deref(lock))
                 continue;
-            deallocateSmallLine(line);
+            deallocateSmallLine(lock, line);
         } else {
             ASSERT(isSmallOrMedium(object));
             MediumLine* line = MediumLine::get(object);
-            if (!line->deref())
+            if (!line->deref(lock))
                 continue;
-            deallocateMediumLine(line);
+            deallocateMediumLine(lock, line);
         }
     }
     
@@ -91,17 +93,7 @@ void Deallocator::deallocateSlowCase(void* object)
         return;
 
     if (isSmallOrMedium(object)) {
-        std::unique_lock<Mutex> lock(PerProcess<Heap>::mutex(), std::defer_lock);
-        bool didLock;
-        if (m_objectLog.size() == m_objectLog.capacity()) {
-            didLock = true;
-            lock.lock();
-        } else
-            didLock = lock.try_lock();
-        
-        if (didLock)
-            processObjectLog();
-        
+        processObjectLog();
         m_objectLog.push(object);
         return;
     }
@@ -113,10 +105,10 @@ void Deallocator::deallocateSlowCase(void* object)
     return deallocateXLarge(object);
 }
 
-void Deallocator::deallocateSmallLine(SmallLine* line)
+void Deallocator::deallocateSmallLine(std::lock_guard<Mutex>& lock, SmallLine* line)
 {
     if (m_smallLineCache.size() == m_smallLineCache.capacity())
-        return PerProcess<Heap>::getFastCase()->deallocateSmallLine(line);
+        return PerProcess<Heap>::getFastCase()->deallocateSmallLine(lock, line);
 
     m_smallLineCache.push(line);
 }
@@ -134,10 +126,10 @@ SmallLine* Deallocator::allocateSmallLine()
     return m_smallLineCache.pop();
 }
 
-void Deallocator::deallocateMediumLine(MediumLine* line)
+void Deallocator::deallocateMediumLine(std::lock_guard<Mutex>& lock, MediumLine* line)
 {
     if (m_mediumLineCache.size() == m_mediumLineCache.capacity())
-        return PerProcess<Heap>::getFastCase()->deallocateMediumLine(line);
+        return PerProcess<Heap>::getFastCase()->deallocateMediumLine(lock, line);
 
     m_mediumLineCache.push(line);
 }
index 9887f81..6f55de6 100644 (file)
@@ -44,10 +44,10 @@ public:
     bool deallocateFastCase(void*);
     void deallocateSlowCase(void*);
 
-    void deallocateSmallLine(SmallLine*);
+    void deallocateSmallLine(std::lock_guard<Mutex>&, SmallLine*);
     SmallLine* allocateSmallLine();
 
-    void deallocateMediumLine(MediumLine*);
+    void deallocateMediumLine(std::lock_guard<Mutex>&, MediumLine*);
     MediumLine* allocateMediumLine();
 
 private:
@@ -67,7 +67,7 @@ inline bool Deallocator::deallocateFastCase(void* object)
 
     ASSERT(object);
 
-    if (!(m_objectLog.size() % (m_objectLog.capacity() / 4)))
+    if (m_objectLog.size() == m_objectLog.capacity())
         return false;
 
     m_objectLog.push(object);
index ec79674..8c6f6d6 100644 (file)
@@ -50,10 +50,10 @@ public:
     Heap(std::lock_guard<Mutex>&);
     
     SmallLine* allocateSmallLine(std::lock_guard<Mutex>&);
-    void deallocateSmallLine(SmallLine*);
+    void deallocateSmallLine(std::lock_guard<Mutex>&, SmallLine*);
 
     MediumLine* allocateMediumLine(std::lock_guard<Mutex>&);
-    void deallocateMediumLine(MediumLine*);
+    void deallocateMediumLine(std::lock_guard<Mutex>&, MediumLine*);
     
     void* allocateLarge(std::lock_guard<Mutex>&, size_t);
     void deallocateLarge(std::lock_guard<Mutex>&, void*);
@@ -94,10 +94,10 @@ private:
     AsyncTask<Heap, decltype(&Heap::concurrentScavenge)> m_scavenger;
 };
 
-inline void Heap::deallocateSmallLine(SmallLine* line)
+inline void Heap::deallocateSmallLine(std::lock_guard<Mutex>& lock, SmallLine* line)
 {
     SmallPage* page = SmallPage::get(line);
-    if (page->deref()) {
+    if (page->deref(lock)) {
         m_smallPages.push(page);
         m_scavenger.run();
         return;
@@ -119,10 +119,10 @@ inline SmallLine* Heap::allocateSmallLine(std::lock_guard<Mutex>& lock)
     return allocateSmallLineSlowCase(lock);
 }
 
-inline void Heap::deallocateMediumLine(MediumLine* line)
+inline void Heap::deallocateMediumLine(std::lock_guard<Mutex>& lock, MediumLine* line)
 {
     MediumPage* page = MediumPage::get(line);
-    if (page->deref()) {
+    if (page->deref(lock)) {
         m_mediumPages.push(page);
         m_scavenger.run();
         return;
index bd1a70d..84e003c 100644 (file)
@@ -46,7 +46,7 @@ public:
     static Line* get(void*);
 
     void concurrentRef(unsigned char = 1);
-    bool deref(unsigned char = 1);
+    bool deref(std::lock_guard<Mutex>&, unsigned char = 1);
     
     char* begin();
     char* end();
@@ -88,7 +88,7 @@ inline void Line<Traits>::concurrentRef(unsigned char count)
 }
 
 template<class Traits>
-inline bool Line<Traits>::deref(unsigned char count)
+inline bool Line<Traits>::deref(std::lock_guard<Mutex>&, unsigned char count)
 {
     ASSERT(count <= m_refCount);
     m_refCount -= count;
index 485ad01..981a8e7 100644 (file)
@@ -46,7 +46,7 @@ public:
     static Page* get(Line*);
 
     void ref(std::lock_guard<Mutex>&);
-    bool deref();
+    bool deref(std::lock_guard<Mutex>&);
     unsigned refCount(std::lock_guard<Mutex>&);
     
     Line* begin();
@@ -64,7 +64,7 @@ inline void Page<Traits>::ref(std::lock_guard<Mutex>&)
 }
 
 template<typename Traits>
-inline bool Page<Traits>::deref()
+inline bool Page<Traits>::deref(std::lock_guard<Mutex>&)
 {
     ASSERT(m_refCount);
     --m_refCount;