Title: [196584] branches/safari-601.1.46-branch/Source/bmalloc

Diff

Modified: branches/safari-601.1.46-branch/Source/bmalloc/ChangeLog (196583 => 196584)


--- branches/safari-601.1.46-branch/Source/bmalloc/ChangeLog	2016-02-15 19:56:18 UTC (rev 196583)
+++ branches/safari-601.1.46-branch/Source/bmalloc/ChangeLog	2016-02-15 19:58:59 UTC (rev 196584)
@@ -1,3 +1,27 @@
+2016-02-15  Babak Shafiei  <[email protected]>
+
+        Merge r196421.
+
+    2016-02-11  Michael Saboff  <[email protected]>
+
+            bmalloc: large aligned allocations will put 1 or 2 free object on free list without merging with free neighbors
+            https://bugs.webkit.org/show_bug.cgi?id=154091
+
+            Reviewed by Geoffrey Garen.
+
+            If we split off any unused free object in the aligned version of Heap::allocateLarge(), we merge them with
+            free neighbors before putting them back on the free list.  Added helpers to verify that when we
+            add LargeObjects to the free list their neighbors are allocated.
+
+            * bmalloc/Heap.cpp:
+            (bmalloc::Heap::allocateLarge): Deleted private helper version and rolled it into the two the
+            two public versions of allocateLarge().
+            * bmalloc/Heap.h:
+            * bmalloc/LargeObject.h:
+            (bmalloc::LargeObject::prevIsAllocated): New helper.
+            (bmalloc::LargeObject::nextIsAllocated): New helper.
+            (bmalloc::LargeObject::merge): Check that the merge object has allocated neighbors.
+
 2015-07-26  Babak Shafiei  <[email protected]>
 
         Merge r187270.

Modified: branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.cpp (196583 => 196584)


--- branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.cpp	2016-02-15 19:56:18 UTC (rev 196583)
+++ branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.cpp	2016-02-15 19:58:59 UTC (rev 196584)
@@ -327,22 +327,8 @@
     lock.lock();
 }
 
-void* Heap::allocateLarge(std::lock_guard<StaticMutex>&, LargeObject& largeObject, size_t size)
+void* Heap::allocateLarge(std::lock_guard<StaticMutex>&, size_t size)
 {
-    BASSERT(largeObject.isFree());
-
-    if (largeObject.size() - size > largeMin) {
-        std::pair<LargeObject, LargeObject> split = largeObject.split(size);
-        largeObject = split.first;
-        m_largeObjects.insert(split.second);
-    }
-
-    largeObject.setFree(false);
-    return largeObject.begin();
-}
-
-void* Heap::allocateLarge(std::lock_guard<StaticMutex>& lock, size_t size)
-{
     BASSERT(size <= largeMax);
     BASSERT(size >= largeMin);
     BASSERT(size == roundUpToMultipleOf<largeAlignment>(size));
@@ -353,10 +339,27 @@
         largeObject = m_vmHeap.allocateLargeObject(size);
     }
 
-    return allocateLarge(lock, largeObject, size);
+    BASSERT(largeObject.isFree());
+
+    LargeObject nextLargeObject;
+
+    if (largeObject.size() - size > largeMin) {
+        std::pair<LargeObject, LargeObject> split = largeObject.split(size);
+        largeObject = split.first;
+        nextLargeObject = split.second;
+    }
+    
+    largeObject.setFree(false);
+    
+    if (nextLargeObject) {
+        BASSERT(nextLargeObject.nextIsAllocated());
+        m_largeObjects.insert(nextLargeObject);
+    }
+    
+    return largeObject.begin();
 }
 
-void* Heap::allocateLarge(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size, size_t unalignedSize)
+void* Heap::allocateLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t size, size_t unalignedSize)
 {
     BASSERT(size <= largeMax);
     BASSERT(size >= largeMin);
@@ -374,15 +377,38 @@
         largeObject = m_vmHeap.allocateLargeObject(alignment, size, unalignedSize);
     }
 
+    LargeObject prevLargeObject;
+    LargeObject nextLargeObject;
+
     size_t alignmentMask = alignment - 1;
     if (test(largeObject.begin(), alignmentMask)) {
         size_t prefixSize = roundUpToMultipleOf(alignment, largeObject.begin() + largeMin) - largeObject.begin();
         std::pair<LargeObject, LargeObject> pair = largeObject.split(prefixSize);
-        m_largeObjects.insert(pair.first);
+        prevLargeObject = pair.first;
         largeObject = pair.second;
     }
 
-    return allocateLarge(lock, largeObject, size);
+    BASSERT(largeObject.isFree());
+    
+    if (largeObject.size() - size > largeMin) {
+        std::pair<LargeObject, LargeObject> split = largeObject.split(size);
+        largeObject = split.first;
+        nextLargeObject = split.second;
+    }
+    
+    largeObject.setFree(false);
+
+    if (prevLargeObject) {
+        LargeObject merged = prevLargeObject.merge();
+        m_largeObjects.insert(merged);
+    }
+
+    if (nextLargeObject) {
+        LargeObject merged = nextLargeObject.merge();
+        m_largeObjects.insert(merged);
+    }
+
+    return largeObject.begin();
 }
 
 void Heap::deallocateLarge(std::lock_guard<StaticMutex>&, const LargeObject& largeObject)

Modified: branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.h (196583 => 196584)


--- branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.h	2016-02-15 19:56:18 UTC (rev 196583)
+++ branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/Heap.h	2016-02-15 19:58:59 UTC (rev 196584)
@@ -82,7 +82,6 @@
     void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*);
     void deallocateMediumLine(std::lock_guard<StaticMutex>&, MediumLine*);
 
-    void* allocateLarge(std::lock_guard<StaticMutex>&, LargeObject&, size_t);
     void deallocateLarge(std::lock_guard<StaticMutex>&, const LargeObject&);
 
     void splitLarge(BeginTag*, size_t, EndTag*&, Range&);

Modified: branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/LargeObject.h (196583 => 196584)


--- branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/LargeObject.h	2016-02-15 19:56:18 UTC (rev 196583)
+++ branches/safari-601.1.46-branch/Source/bmalloc/bmalloc/LargeObject.h	2016-02-15 19:58:59 UTC (rev 196584)
@@ -53,6 +53,9 @@
 
     void setFree(bool) const;
     bool isFree() const;
+
+    bool prevIsAllocated() const;
+    bool nextIsAllocated() const;
     
     Owner owner() const;
     void setOwner(Owner) const;
@@ -118,6 +121,21 @@
     return m_beginTag->isFree();
 }
 
+inline bool LargeObject::prevIsAllocated() const
+{
+    EndTag* prev = m_beginTag->prev();
+
+    return !prev->isFree() || prev->owner() != this->owner();
+}
+
+inline bool LargeObject::nextIsAllocated() const
+{
+    BeginTag* next = m_endTag->next();
+
+    return !next->isFree() || next->owner() != this->owner();
+}
+
+
 inline Owner LargeObject::owner() const
 {
     validate();
@@ -201,7 +219,11 @@
     beginTag->setOwner(owner);
     endTag->init(beginTag);
 
-    return LargeObject(beginTag, endTag, range.begin());
+    LargeObject result(beginTag, endTag, range.begin());
+    BASSERT(result.prevIsAllocated());
+    BASSERT(result.nextIsAllocated());
+
+    return result;
 }
 
 inline std::pair<LargeObject, LargeObject> LargeObject::split(size_t size) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to