Title: [230222] trunk/Source/bmalloc
Revision
230222
Author
[email protected]
Date
2018-04-03 13:41:26 -0700 (Tue, 03 Apr 2018)

Log Message

totalPhysicalSize calculation when splitting a range must account for double rounding effects
https://bugs.webkit.org/show_bug.cgi?id=184275

Reviewed by Mark Lam.

The rounding error could happen when we split a range where the
range's total physical size equals the range's total size. The
rounding may cause the left size to lose a byte, and the right
size to gain a byte. This caused the right side to be a byte
large than its size.

* bmalloc/LargeRange.h:
(bmalloc::LargeRange::LargeRange):
(bmalloc::LargeRange::split const):

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (230221 => 230222)


--- trunk/Source/bmalloc/ChangeLog	2018-04-03 20:40:12 UTC (rev 230221)
+++ trunk/Source/bmalloc/ChangeLog	2018-04-03 20:41:26 UTC (rev 230222)
@@ -1,3 +1,20 @@
+2018-04-03  Saam Barati  <[email protected]>
+
+        totalPhysicalSize calculation when splitting a range must account for double rounding effects
+        https://bugs.webkit.org/show_bug.cgi?id=184275
+
+        Reviewed by Mark Lam.
+
+        The rounding error could happen when we split a range where the
+        range's total physical size equals the range's total size. The
+        rounding may cause the left size to lose a byte, and the right
+        size to gain a byte. This caused the right side to be a byte
+        large than its size.
+
+        * bmalloc/LargeRange.h:
+        (bmalloc::LargeRange::LargeRange):
+        (bmalloc::LargeRange::split const):
+
 2018-04-02  Saam Barati  <[email protected]>
 
         bmalloc should compute its own estimate of its footprint

Modified: trunk/Source/bmalloc/bmalloc/LargeRange.h (230221 => 230222)


--- trunk/Source/bmalloc/bmalloc/LargeRange.h	2018-04-03 20:40:12 UTC (rev 230221)
+++ trunk/Source/bmalloc/bmalloc/LargeRange.h	2018-04-03 20:41:26 UTC (rev 230222)
@@ -45,7 +45,7 @@
         , m_startPhysicalSize(startPhysicalSize)
         , m_totalPhysicalSize(totalPhysicalSize)
     {
-        BASSERT(size() >= this->totalPhysicalSize());
+        BASSERT(this->size() >= this->totalPhysicalSize());
         BASSERT(this->totalPhysicalSize() >= this->startPhysicalSize());
     }
 
@@ -131,8 +131,14 @@
 
     double ratio = static_cast<double>(leftSize) / static_cast<double>(this->size());
     size_t leftTotalPhysicalSize = static_cast<size_t>(ratio * totalPhysicalSize());
+    BASSERT(leftTotalPhysicalSize <= leftSize);
     leftTotalPhysicalSize = std::max(startPhysicalSize(), leftTotalPhysicalSize);
     size_t rightTotalPhysicalSize = totalPhysicalSize() - leftTotalPhysicalSize;
+    if (rightTotalPhysicalSize > rightSize) { // This may happen because of rounding.
+        leftTotalPhysicalSize += rightTotalPhysicalSize - rightSize;
+        BASSERT(leftTotalPhysicalSize <= leftSize);
+        rightTotalPhysicalSize = rightSize;
+    }
 
     LargeRange left(begin(), leftSize, startPhysicalSize(), leftTotalPhysicalSize);
     LargeRange right(left.end(), rightSize, 0, rightTotalPhysicalSize);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to