Title: [249588] trunk/Source/bmalloc
Revision
249588
Author
[email protected]
Date
2019-09-06 13:23:31 -0700 (Fri, 06 Sep 2019)

Log Message

Use FailureAction everywhere in bmalloc instead of a crashOnFailure boolean.
https://bugs.webkit.org/show_bug.cgi?id=201553

Reviewed by Yusuke Suzuki.

* bmalloc/Cache.cpp:
(bmalloc::Cache::tryAllocateSlowCaseNullCache):
(bmalloc::Cache::allocateSlowCaseNullCache):
(bmalloc::Cache::tryReallocateSlowCaseNullCache):
(bmalloc::Cache::reallocateSlowCaseNullCache):
* bmalloc/DebugHeap.cpp:
(bmalloc::DebugHeap::malloc):
(bmalloc::DebugHeap::memalign):
(bmalloc::DebugHeap::realloc):
* bmalloc/DebugHeap.h:

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (249587 => 249588)


--- trunk/Source/bmalloc/ChangeLog	2019-09-06 20:08:56 UTC (rev 249587)
+++ trunk/Source/bmalloc/ChangeLog	2019-09-06 20:23:31 UTC (rev 249588)
@@ -1,5 +1,23 @@
 2019-09-06  Mark Lam  <[email protected]>
 
+        Use FailureAction everywhere in bmalloc instead of a crashOnFailure boolean.
+        https://bugs.webkit.org/show_bug.cgi?id=201553
+
+        Reviewed by Yusuke Suzuki.
+
+        * bmalloc/Cache.cpp:
+        (bmalloc::Cache::tryAllocateSlowCaseNullCache):
+        (bmalloc::Cache::allocateSlowCaseNullCache):
+        (bmalloc::Cache::tryReallocateSlowCaseNullCache):
+        (bmalloc::Cache::reallocateSlowCaseNullCache):
+        * bmalloc/DebugHeap.cpp:
+        (bmalloc::DebugHeap::malloc):
+        (bmalloc::DebugHeap::memalign):
+        (bmalloc::DebugHeap::realloc):
+        * bmalloc/DebugHeap.h:
+
+2019-09-06  Mark Lam  <[email protected]>
+
         Fix bmalloc::Allocator:tryAllocate() to return null on failure to allocate.
         https://bugs.webkit.org/show_bug.cgi?id=201529
         <rdar://problem/53935772>

Modified: trunk/Source/bmalloc/bmalloc/Cache.cpp (249587 => 249588)


--- trunk/Source/bmalloc/bmalloc/Cache.cpp	2019-09-06 20:08:56 UTC (rev 249587)
+++ trunk/Source/bmalloc/bmalloc/Cache.cpp	2019-09-06 20:23:31 UTC (rev 249588)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -53,37 +53,29 @@
 
 BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t size)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = false;
-        return debugHeap->malloc(size, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->malloc(size, FailureAction::ReturnNull);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(size);
 }
 
 BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t size)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = true;
-        return debugHeap->malloc(size, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->malloc(size, FailureAction::Crash);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(size);
 }
 
 BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = false;
-        return debugHeap->memalign(alignment, size, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->memalign(alignment, size, FailureAction::ReturnNull);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(alignment, size);
 }
 
 BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = true;
-        return debugHeap->memalign(alignment, size, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->memalign(alignment, size, FailureAction::Crash);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(alignment, size);
 }
 
@@ -98,19 +90,15 @@
 
 BNO_INLINE void* Cache::tryReallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = false;
-        return debugHeap->realloc(object, newSize, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->realloc(object, newSize, FailureAction::ReturnNull);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryReallocate(object, newSize);
 }
 
 BNO_INLINE void* Cache::reallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize)
 {
-    if (auto* debugHeap = DebugHeap::tryGet()) {
-        constexpr bool crashOnFailure = true;
-        return debugHeap->realloc(object, newSize, crashOnFailure);
-    }
+    if (auto* debugHeap = DebugHeap::tryGet())
+        return debugHeap->realloc(object, newSize, FailureAction::Crash);
     return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().reallocate(object, newSize);
 }
 

Modified: trunk/Source/bmalloc/bmalloc/DebugHeap.cpp (249587 => 249588)


--- trunk/Source/bmalloc/bmalloc/DebugHeap.cpp	2019-09-06 20:08:56 UTC (rev 249587)
+++ trunk/Source/bmalloc/bmalloc/DebugHeap.cpp	2019-09-06 20:23:31 UTC (rev 249588)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -47,27 +47,24 @@
     malloc_set_zone_name(m_zone, "WebKit Using System Malloc");
 }
 
-void* DebugHeap::malloc(size_t size, bool crashOnFailure)
+void* DebugHeap::malloc(size_t size, FailureAction action)
 {
     void* result = malloc_zone_malloc(m_zone, size);
-    if (!result && crashOnFailure)
-        BCRASH();
+    RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 
-void* DebugHeap::memalign(size_t alignment, size_t size, bool crashOnFailure)
+void* DebugHeap::memalign(size_t alignment, size_t size, FailureAction action)
 {
     void* result = malloc_zone_memalign(m_zone, alignment, size);
-    if (!result && crashOnFailure)
-        BCRASH();
+    RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 
-void* DebugHeap::realloc(void* object, size_t size, bool crashOnFailure)
+void* DebugHeap::realloc(void* object, size_t size, FailureAction action)
 {
     void* result = malloc_zone_realloc(m_zone, object, size);
-    if (!result && crashOnFailure)
-        BCRASH();
+    RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 
@@ -96,30 +93,25 @@
 {
 }
 
-void* DebugHeap::malloc(size_t size, bool crashOnFailure)
+void* DebugHeap::malloc(size_t size, FailureAction action)
 {
     void* result = ::malloc(size);
-    if (!result && crashOnFailure)
-        BCRASH();
+    RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 
-void* DebugHeap::memalign(size_t alignment, size_t size, bool crashOnFailure)
+void* DebugHeap::memalign(size_t alignment, size_t size, FailureAction action)
 {
     void* result;
-    if (posix_memalign(&result, alignment, size)) {
-        if (crashOnFailure)
-            BCRASH();
-        return nullptr;
-    }
+    if (posix_memalign(&result, alignment, size))
+        RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 
-void* DebugHeap::realloc(void* object, size_t size, bool crashOnFailure)
+void* DebugHeap::realloc(void* object, size_t size, FailureAction action)
 {
     void* result = ::realloc(object, size);
-    if (!result && crashOnFailure)
-        BCRASH();
+    RELEASE_BASSERT(action == FailureAction::ReturnNull || result);
     return result;
 }
 

Modified: trunk/Source/bmalloc/bmalloc/DebugHeap.h (249587 => 249588)


--- trunk/Source/bmalloc/bmalloc/DebugHeap.h	2019-09-06 20:08:56 UTC (rev 249587)
+++ trunk/Source/bmalloc/bmalloc/DebugHeap.h	2019-09-06 20:23:31 UTC (rev 249588)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "Environment.h"
+#include "FailureAction.h"
 #include "Mutex.h"
 #include "StaticPerProcess.h"
 #include <mutex>
@@ -41,9 +42,9 @@
 public:
     DebugHeap(std::lock_guard<Mutex>&);
     
-    void* malloc(size_t, bool crashOnFailure);
-    void* memalign(size_t alignment, size_t, bool crashOnFailure);
-    void* realloc(void*, size_t, bool crashOnFailure);
+    void* malloc(size_t, FailureAction);
+    void* memalign(size_t alignment, size_t, FailureAction);
+    void* realloc(void*, size_t, FailureAction);
     void free(void*);
     
     void* memalignLarge(size_t alignment, size_t);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to