Title: [241837] trunk/Source/bmalloc
Revision
241837
Author
[email protected]
Date
2019-02-20 14:22:07 -0800 (Wed, 20 Feb 2019)

Log Message

[bmalloc] DebugHeap::malloc does not have "try" version.
https://bugs.webkit.org/show_bug.cgi?id=194837

Reviewed by Mark Lam.

Since DebugHeap::malloc does not have "try" version, our tryAllocate implementation does not work well with DebugHeap.
This patch adds crashOnFailure flag to DebugHeap::malloc.

* bmalloc/Cache.cpp:
(bmalloc::Cache::tryAllocateSlowCaseNullCache):
(bmalloc::Cache::allocateSlowCaseNullCache):
* bmalloc/DebugHeap.cpp:
(bmalloc::DebugHeap::malloc):
* bmalloc/DebugHeap.h:
* bmalloc/IsoTLS.cpp:
(bmalloc::IsoTLS::debugMalloc):

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (241836 => 241837)


--- trunk/Source/bmalloc/ChangeLog	2019-02-20 22:22:07 UTC (rev 241836)
+++ trunk/Source/bmalloc/ChangeLog	2019-02-20 22:22:07 UTC (rev 241837)
@@ -1,5 +1,24 @@
 2019-02-20  Yusuke Suzuki  <[email protected]>
 
+        [bmalloc] DebugHeap::malloc does not have "try" version.
+        https://bugs.webkit.org/show_bug.cgi?id=194837
+
+        Reviewed by Mark Lam.
+
+        Since DebugHeap::malloc does not have "try" version, our tryAllocate implementation does not work well with DebugHeap.
+        This patch adds crashOnFailure flag to DebugHeap::malloc.
+
+        * bmalloc/Cache.cpp:
+        (bmalloc::Cache::tryAllocateSlowCaseNullCache):
+        (bmalloc::Cache::allocateSlowCaseNullCache):
+        * bmalloc/DebugHeap.cpp:
+        (bmalloc::DebugHeap::malloc):
+        * bmalloc/DebugHeap.h:
+        * bmalloc/IsoTLS.cpp:
+        (bmalloc::IsoTLS::debugMalloc):
+
+2019-02-20  Yusuke Suzuki  <[email protected]>
+
         [bmalloc] bmalloc::Cache should not be instantiated if we are using system malloc
         https://bugs.webkit.org/show_bug.cgi?id=194811
 

Modified: trunk/Source/bmalloc/bmalloc/Cache.cpp (241836 => 241837)


--- trunk/Source/bmalloc/bmalloc/Cache.cpp	2019-02-20 22:22:07 UTC (rev 241836)
+++ trunk/Source/bmalloc/bmalloc/Cache.cpp	2019-02-20 22:22:07 UTC (rev 241837)
@@ -66,17 +66,19 @@
 
 BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t size)
 {
-    // FIXME: DebugHeap does not have tryAllocate feature.
-    // https://bugs.webkit.org/show_bug.cgi?id=194837
-    if (auto* heap = debugHeap())
-        return heap->malloc(size);
+    if (auto* heap = debugHeap()) {
+        constexpr bool crashOnFailure = false;
+        return heap->malloc(size, crashOnFailure);
+    }
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(size);
 }
 
 BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t size)
 {
-    if (auto* heap = debugHeap())
-        return heap->malloc(size);
+    if (auto* heap = debugHeap()) {
+        constexpr bool crashOnFailure = true;
+        return heap->malloc(size, crashOnFailure);
+    }
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(size);
 }
 

Modified: trunk/Source/bmalloc/bmalloc/DebugHeap.cpp (241836 => 241837)


--- trunk/Source/bmalloc/bmalloc/DebugHeap.cpp	2019-02-20 22:22:07 UTC (rev 241836)
+++ trunk/Source/bmalloc/bmalloc/DebugHeap.cpp	2019-02-20 22:22:07 UTC (rev 241837)
@@ -43,10 +43,10 @@
     malloc_set_zone_name(m_zone, "WebKit Using System Malloc");
 }
 
-void* DebugHeap::malloc(size_t size)
+void* DebugHeap::malloc(size_t size, bool crashOnFailure)
 {
     void* result = malloc_zone_malloc(m_zone, size);
-    if (!result)
+    if (!result && crashOnFailure)
         BCRASH();
     return result;
 }
@@ -79,10 +79,10 @@
 {
 }
 
-void* DebugHeap::malloc(size_t size)
+void* DebugHeap::malloc(size_t size, bool crashOnFailure)
 {
     void* result = ::malloc(size);
-    if (!result)
+    if (!result && crashOnFailure)
         BCRASH();
     return result;
 }

Modified: trunk/Source/bmalloc/bmalloc/DebugHeap.h (241836 => 241837)


--- trunk/Source/bmalloc/bmalloc/DebugHeap.h	2019-02-20 22:22:07 UTC (rev 241836)
+++ trunk/Source/bmalloc/bmalloc/DebugHeap.h	2019-02-20 22:22:07 UTC (rev 241837)
@@ -39,7 +39,7 @@
 public:
     DebugHeap(std::lock_guard<Mutex>&);
     
-    void* malloc(size_t);
+    void* malloc(size_t, bool crashOnFailure);
     void* memalign(size_t alignment, size_t, bool crashOnFailure);
     void* realloc(void*, size_t, bool crashOnFailure);
     void free(void*);

Modified: trunk/Source/bmalloc/bmalloc/IsoTLS.cpp (241836 => 241837)


--- trunk/Source/bmalloc/bmalloc/IsoTLS.cpp	2019-02-20 22:22:07 UTC (rev 241836)
+++ trunk/Source/bmalloc/bmalloc/IsoTLS.cpp	2019-02-20 22:22:07 UTC (rev 241837)
@@ -182,8 +182,10 @@
 auto IsoTLS::debugMalloc(size_t size) -> DebugMallocResult
 {
     DebugMallocResult result;
-    if ((result.usingDebugHeap = isUsingDebugHeap()))
-        result.ptr = PerProcess<DebugHeap>::get()->malloc(size);
+    if ((result.usingDebugHeap = isUsingDebugHeap())) {
+        constexpr bool crashOnFailure = true;
+        result.ptr = PerProcess<DebugHeap>::get()->malloc(size, crashOnFailure);
+    }
     return result;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to