bmalloc: tryFastMalloc shouldn't crash
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Mar 2015 04:10:15 +0000 (04:10 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Mar 2015 04:10:15 +0000 (04:10 +0000)
commit1c73adb37d72319f4df01c060c4c8ee741180fbd
tree6f1e97802d7da757411a7d02a74c77ae6f6ddaf6
parent0bbb0fa21430f3470bcd72b09205303977072853
bmalloc: tryFastMalloc shouldn't crash
https://bugs.webkit.org/show_bug.cgi?id=142443

Reviewed by Darin Adler.

Source/bmalloc:

Added support for tryMalloc.

We assume that non-x-large allocations always succeed, and we crash
otherwise, since normal allocation failure will just cause the next
non-try allocation or internal metadata allocation to fail, and it's
hard and not really useful to keep limping along after that. But
extra-large allocations can meaningfully fail, and we can recover.

* bmalloc/Heap.cpp:
(bmalloc::Heap::allocateXLarge):
(bmalloc::Heap::tryAllocateXLarge):
* bmalloc/Heap.h: Added support for non-crashy x-large allocation.

* bmalloc/VMAllocate.h:
(bmalloc::tryVMAllocate):
(bmalloc::vmAllocate): Added support for non-crashy VM allocation.

* bmalloc/bmalloc.h:
(bmalloc::api::tryMalloc):
(bmalloc::api::realloc):
(bmalloc::api::free): Tried to clarify our behavior with some comments.
Unfortunately, calling what we do "malloc" is still not quite right, since
malloc returns null on failure and we don't.

Source/WTF:

* wtf/FastMalloc.cpp:
(WTF::fastMalloc):
(WTF::fastRealloc):
(WTF::fastAlignedMalloc): Don't check for null. bmalloc automatically
crashes on allocation failure, and we'd rather not pay for an extra check.

(WTF::tryFastMalloc): Added an opt-out API to return null rather than
crashing, since some clients need this.

(WTF::tryFastRealloc): Deleted. Unused.

* wtf/FastMalloc.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181307 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/wtf/FastMalloc.cpp
Source/WTF/wtf/FastMalloc.h
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Heap.cpp
Source/bmalloc/bmalloc/Heap.h
Source/bmalloc/bmalloc/VMAllocate.h
Source/bmalloc/bmalloc/bmalloc.h