https://bugs.webkit.org/show_bug.cgi?id=140572
Reviewed by Andreas Kling.
* bmalloc/Algorithm.h:
(bmalloc::isPowerOfTwo):
(bmalloc::roundUpToMultipleOf):
(bmalloc::roundDownToMultipleOf): Refactored some duplicate code to use our
isPowerOfTwo helper function.
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::allocate):
* bmalloc/Allocator.h: Stubbed out an implementation of aligned allocation.
Doesn't do anything yet, but does correctly forward to system malloc
when bmalloc is disabled.
* bmalloc/Cache.cpp:
(bmalloc::Cache::allocateSlowCaseNullCache):
* bmalloc/Cache.h:
(bmalloc::Cache::allocate):
* bmalloc/bmalloc.h:
(bmalloc::api::memalign):
* bmalloc/mbmalloc.cpp: Stubbed out an API for aligned allocation.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@178609
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-01-16 Geoffrey Garen <ggaren@apple.com>
+
+ bmalloc: added some infrastructure for aligned allocation
+ https://bugs.webkit.org/show_bug.cgi?id=140572
+
+ Reviewed by Andreas Kling.
+
+ * bmalloc/Algorithm.h:
+ (bmalloc::isPowerOfTwo):
+ (bmalloc::roundUpToMultipleOf):
+ (bmalloc::roundDownToMultipleOf): Refactored some duplicate code to use our
+ isPowerOfTwo helper function.
+
+ * bmalloc/Allocator.cpp:
+ (bmalloc::Allocator::allocate):
+ * bmalloc/Allocator.h: Stubbed out an implementation of aligned allocation.
+ Doesn't do anything yet, but does correctly forward to system malloc
+ when bmalloc is disabled.
+
+ * bmalloc/Cache.cpp:
+ (bmalloc::Cache::allocateSlowCaseNullCache):
+ * bmalloc/Cache.h:
+ (bmalloc::Cache::allocate):
+ * bmalloc/bmalloc.h:
+ (bmalloc::api::memalign):
+ * bmalloc/mbmalloc.cpp: Stubbed out an API for aligned allocation.
+
2015-01-13 Geoffrey Garen <ggaren@apple.com>
Consider alignment when allocating from a SegregatedFreeList
return !!(reinterpret_cast<uintptr_t>(value) & mask);
}
+inline constexpr bool isPowerOfTwo(size_t size)
+{
+ return !(size & (size - 1));
+}
+
template<typename T> inline T roundUpToMultipleOf(size_t divisor, T x)
{
- BASSERT(divisor && !(divisor & (divisor - 1)));
+ BASSERT(isPowerOfTwo(divisor));
return reinterpret_cast<T>((reinterpret_cast<uintptr_t>(x) + (divisor - 1ul)) & ~(divisor - 1ul));
}
template<size_t divisor, typename T> inline constexpr T roundUpToMultipleOf(T x)
{
- static_assert(divisor && !(divisor & (divisor - 1)), "'divisor' must be a power of two.");
+ static_assert(isPowerOfTwo(divisor), "'divisor' must be a power of two.");
return roundUpToMultipleOf(divisor, x);
}
template<size_t divisor, typename T> inline constexpr T roundDownToMultipleOf(T x)
{
- static_assert(divisor && !(divisor & (divisor - 1)), "'divisor' must be a power of two.");
+ static_assert(isPowerOfTwo(divisor), "'divisor' must be a power of two.");
return reinterpret_cast<T>(mask(reinterpret_cast<uintptr_t>(x), ~(divisor - 1ul)));
}
return sizeof(T) * 8;
}
-inline constexpr bool isPowerOfTwo(size_t size)
-{
- return !(size & (size - 1));
-}
-
} // namespace bmalloc
#endif // Algorithm_h
scavenge();
}
+void* Allocator::allocate(size_t alignment, size_t size)
+{
+ if (!m_isBmallocEnabled) {
+ void* result = nullptr;
+ posix_memalign(&result, alignment, size);
+ return result;
+ }
+
+ BASSERT(isPowerOfTwo(alignment));
+ return nullptr;
+}
+
void* Allocator::reallocate(void* object, size_t newSize)
{
if (!m_isBmallocEnabled)
~Allocator();
void* allocate(size_t);
+ void* allocate(size_t alignment, size_t);
void* reallocate(void*, size_t);
void scavenge();
return PerThread<Cache>::getSlowCase()->allocator().allocate(size);
}
+NO_INLINE void* Cache::allocateSlowCaseNullCache(size_t alignment, size_t size)
+{
+ return PerThread<Cache>::getSlowCase()->allocator().allocate(alignment, size);
+}
+
NO_INLINE void Cache::deallocateSlowCaseNullCache(void* object)
{
PerThread<Cache>::getSlowCase()->deallocator().deallocate(object);
void operator delete(void*, size_t);
static void* allocate(size_t);
+ static void* allocate(size_t alignment, size_t);
static void deallocate(void*);
static void* reallocate(void*, size_t);
static void scavenge();
private:
static void* allocateSlowCaseNullCache(size_t);
+ static void* allocateSlowCaseNullCache(size_t alignment, size_t);
static void deallocateSlowCaseNullCache(void*);
static void* reallocateSlowCaseNullCache(void*, size_t);
return cache->allocator().allocate(size);
}
+inline void* Cache::allocate(size_t alignment, size_t size)
+{
+ Cache* cache = PerThread<Cache>::getFastCase();
+ if (!cache)
+ return allocateSlowCaseNullCache(alignment, size);
+ return cache->allocator().allocate(alignment, size);
+}
+
inline void Cache::deallocate(void* object)
{
Cache* cache = PerThread<Cache>::getFastCase();
return Cache::allocate(size);
}
+inline void* memalign(size_t alignment, size_t size)
+{
+ return Cache::allocate(alignment, size);
+}
+
inline void free(void* object)
{
Cache::deallocate(object);
extern "C" {
EXPORT void* mbmalloc(size_t);
+EXPORT void* mbmemalign(size_t, size_t);
EXPORT void mbfree(void*, size_t);
EXPORT void* mbrealloc(void*, size_t, size_t);
EXPORT void mbscavenge();
return bmalloc::api::malloc(size);
}
+void* mbmemalign(size_t alignment, size_t size)
+{
+ return bmalloc::api::memalign(alignment, size);
+}
+
void mbfree(void* p, size_t)
{
bmalloc::api::free(p);