+2015-03-09 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r181307.
+ https://bugs.webkit.org/show_bug.cgi?id=142525
+
+ Broke ASan tests (Requested by ap on #webkit).
+
+ Reverted changeset:
+
+ "bmalloc: tryFastMalloc shouldn't crash"
+ https://bugs.webkit.org/show_bug.cgi?id=142443
+ http://trac.webkit.org/changeset/181307
+
2015-03-09 Geoffrey Garen <ggaren@apple.com>
bmalloc: tryFastMalloc shouldn't crash
free(p);
}
+TryMallocReturnValue tryFastRealloc(void* p, size_t n)
+{
+ return realloc(p, n);
+}
+
void* fastRealloc(void* p, size_t n)
{
void* result = realloc(p, n);
void* fastMalloc(size_t size)
{
- return bmalloc::api::malloc(size);
+ void* result = bmalloc::api::malloc(size);
+ if (!result)
+ CRASH();
+ return result;
}
void* fastCalloc(size_t numElements, size_t elementSize)
void* fastRealloc(void* object, size_t size)
{
- return bmalloc::api::realloc(object, size);
+ void* result = bmalloc::api::realloc(object, size);
+ if (!result)
+ CRASH();
+ return result;
}
void fastFree(void* object)
void* fastAlignedMalloc(size_t alignment, size_t size)
{
- return bmalloc::api::memalign(alignment, size);
+ void* result = bmalloc::api::memalign(alignment, size);
+ if (!result)
+ CRASH();
+ return result;
}
void fastAlignedFree(void* p)
TryMallocReturnValue tryFastMalloc(size_t size)
{
- return bmalloc::api::tryMalloc(size);
+ return bmalloc::api::malloc(size);
+}
+
+TryMallocReturnValue tryFastRealloc(void* object, size_t size)
+{
+ return bmalloc::api::realloc(object, size);
}
TryMallocReturnValue tryFastCalloc(size_t numElements, size_t elementSize)
WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastMalloc(size_t);
TryMallocReturnValue tryFastZeroedMalloc(size_t);
WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastCalloc(size_t numElements, size_t elementSize);
+WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastRealloc(void*, size_t);
WTF_EXPORT_PRIVATE void fastFree(void*);
using WTF::fastZeroedMalloc;
using WTF::tryFastCalloc;
using WTF::tryFastMalloc;
+using WTF::tryFastRealloc;
using WTF::tryFastZeroedMalloc;
using WTF::fastAlignedMalloc;
using WTF::fastAlignedFree;
+2015-03-09 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r181307.
+ https://bugs.webkit.org/show_bug.cgi?id=142525
+
+ Broke ASan tests (Requested by ap on #webkit).
+
+ Reverted changeset:
+
+ "bmalloc: tryFastMalloc shouldn't crash"
+ https://bugs.webkit.org/show_bug.cgi?id=142443
+ http://trac.webkit.org/changeset/181307
+
2015-03-09 Geoffrey Garen <ggaren@apple.com>
bmalloc: tryFastMalloc shouldn't crash
}
}
-void* Heap::allocateXLarge(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size)
+void* Heap::allocateXLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t size)
{
- void* result = tryAllocateXLarge(lock, alignment, size);
- RELEASE_BASSERT(result);
+ BASSERT(isPowerOfTwo(alignment));
+ BASSERT(alignment >= xLargeAlignment);
+ BASSERT(size == roundUpToMultipleOf<xLargeAlignment>(size));
+
+ void* result = vmAllocate(alignment, size);
+ m_xLargeObjects.push(Range(result, size));
return result;
}
return allocateXLarge(lock, superChunkSize, size);
}
-void* Heap::tryAllocateXLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t size)
-{
- BASSERT(isPowerOfTwo(alignment));
- BASSERT(alignment >= superChunkSize);
- BASSERT(size == roundUpToMultipleOf<xLargeAlignment>(size));
-
- void* result = tryVMAllocate(alignment, size);
- if (!result)
- return nullptr;
- m_xLargeObjects.push(Range(result, size));
- return result;
-}
-
Range Heap::findXLarge(std::lock_guard<StaticMutex>&, void* object)
{
for (auto& range : m_xLargeObjects) {
void* allocateXLarge(std::lock_guard<StaticMutex>&, size_t);
void* allocateXLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t);
- void* tryAllocateXLarge(std::lock_guard<StaticMutex>&, size_t alignment, size_t);
Range findXLarge(std::lock_guard<StaticMutex>&, void*);
void deallocateXLarge(std::unique_lock<StaticMutex>&, void*);
BASSERT(p == mask(p, ~(getpagesize() - 1)));
}
-inline void* tryVMAllocate(size_t vmSize)
+inline void* vmAllocate(size_t vmSize)
{
vmValidate(vmSize);
void* result = mmap(0, vmSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, BMALLOC_VM_TAG, 0);
- if (result == MAP_FAILED)
- return nullptr;
- return result;
-}
-
-inline void* vmAllocate(size_t vmSize)
-{
- void* result = tryVMAllocate(vmSize);
- RELEASE_BASSERT(result);
+ RELEASE_BASSERT(result != MAP_FAILED);
return result;
}
// Allocates vmSize bytes at a specified power-of-two alignment.
// Use this function to create maskable memory regions.
-inline void* tryVMAllocate(size_t vmAlignment, size_t vmSize)
+inline void* vmAllocate(size_t vmAlignment, size_t vmSize)
{
vmValidate(vmSize);
vmValidate(vmAlignment);
size_t mappedSize = std::max(vmSize, vmAlignment) + vmAlignment;
- char* mapped = static_cast<char*>(tryVMAllocate(mappedSize));
- if (!mapped)
- return nullptr;
+ char* mapped = static_cast<char*>(vmAllocate(mappedSize));
char* mappedEnd = mapped + mappedSize;
char* aligned = roundUpToMultipleOf(vmAlignment, mapped);
return aligned;
}
-inline void* vmAllocate(size_t vmAlignment, size_t vmSize)
-{
- void* result = tryVMAllocate(vmAlignment, vmSize);
- RELEASE_BASSERT(result);
- return result;
-}
-
inline void vmDeallocatePhysicalPages(void* p, size_t vmSize)
{
vmValidate(p, vmSize);
namespace bmalloc {
namespace api {
-// Returns null on failure.
-inline void* tryMalloc(size_t size)
-{
- if (size <= largeMax)
- return Cache::allocate(size);
-
- std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
- return PerProcess<Heap>::get()->tryAllocateXLarge(lock, superChunkSize, roundUpToMultipleOf<xLargeAlignment>(size));
-}
-
-// Crashes on failure.
inline void* malloc(size_t size)
{
return Cache::allocate(size);
}
-// Crashes on failure.
inline void* memalign(size_t alignment, size_t size)
{
return Cache::allocate(alignment, size);
}
-// Crashes on failure.
-inline void* realloc(void* object, size_t newSize)
+inline void free(void* object)
{
- return Cache::reallocate(object, newSize);
+ Cache::deallocate(object);
}
-inline void free(void* object)
+inline void* realloc(void* object, size_t newSize)
{
- Cache::deallocate(object);
+ return Cache::reallocate(object, newSize);
}
inline void scavengeThisThread()