Commit f449fc78 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Replace WTF_ALIGN_OF with the standard alignof.

Bug: 565837
Change-Id: I392128332981dd9d282648f6d4fa8ab3392188b1
Reviewed-on: https://chromium-review.googlesource.com/c/1347045
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610778}
parent 1058b144
...@@ -201,7 +201,7 @@ class ContiguousContainer : public ContiguousContainerBase { ...@@ -201,7 +201,7 @@ class ContiguousContainer : public ContiguousContainerBase {
DerivedElementType& AllocateAndConstruct(Args&&... args) { DerivedElementType& AllocateAndConstruct(Args&&... args) {
static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::value, static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::value,
"Must use subclass of BaseElementType."); "Must use subclass of BaseElementType.");
static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, static_assert(alignment % alignof(DerivedElementType) == 0,
"Derived type requires stronger alignment."); "Derived type requires stronger alignment.");
return *new (AlignedAllocate(sizeof(DerivedElementType))) return *new (AlignedAllocate(sizeof(DerivedElementType)))
DerivedElementType(std::forward<Args>(args)...); DerivedElementType(std::forward<Args>(args)...);
......
...@@ -512,7 +512,7 @@ TEST(ContiguousContainerTest, CapacityInBytesAfterClear) { ...@@ -512,7 +512,7 @@ TEST(ContiguousContainerTest, CapacityInBytesAfterClear) {
} }
TEST(ContiguousContainerTest, Alignment) { TEST(ContiguousContainerTest, Alignment) {
const size_t kMaxAlign = WTF_ALIGN_OF(long double); const size_t kMaxAlign = alignof(long double);
ContiguousContainer<Point2D, kMaxAlign> list(kMaxPointSize); ContiguousContainer<Point2D, kMaxAlign> list(kMaxPointSize);
list.AllocateAndConstruct<Point2D>(); list.AllocateAndConstruct<Point2D>();
......
...@@ -20,8 +20,7 @@ struct PaintChunk; ...@@ -20,8 +20,7 @@ struct PaintChunk;
// each derived display item; the ideal value is the least common multiple. // each derived display item; the ideal value is the least common multiple.
// The validity of kDisplayItemAlignment and kMaximumDisplayItemSize are checked // The validity of kDisplayItemAlignment and kMaximumDisplayItemSize are checked
// in PaintController::CreateAndAppend(). // in PaintController::CreateAndAppend().
static const size_t kDisplayItemAlignment = static const size_t kDisplayItemAlignment = alignof(ForeignLayerDisplayItem);
WTF_ALIGN_OF(ForeignLayerDisplayItem);
static const size_t kMaximumDisplayItemSize = sizeof(ForeignLayerDisplayItem); static const size_t kMaximumDisplayItemSize = sizeof(ForeignLayerDisplayItem);
// A container for a list of display items. // A container for a list of display items.
......
...@@ -114,7 +114,7 @@ class PLATFORM_EXPORT PaintController { ...@@ -114,7 +114,7 @@ class PLATFORM_EXPORT PaintController {
static_assert( static_assert(
sizeof(DisplayItemClass) <= kMaximumDisplayItemSize, sizeof(DisplayItemClass) <= kMaximumDisplayItemSize,
"DisplayItem subclass is larger than kMaximumDisplayItemSize."); "DisplayItem subclass is larger than kMaximumDisplayItemSize.");
static_assert(kDisplayItemAlignment % WTF_ALIGN_OF(DisplayItemClass) == 0, static_assert(kDisplayItemAlignment % alignof(DisplayItemClass) == 0,
"DisplayItem subclass alignment is not a factor of " "DisplayItem subclass alignment is not a factor of "
"kDisplayItemAlignment."); "kDisplayItemAlignment.");
......
...@@ -64,7 +64,7 @@ class PLATFORM_EXPORT SparseHeapBitmap { ...@@ -64,7 +64,7 @@ class PLATFORM_EXPORT SparseHeapBitmap {
// The assumed minimum alignment of the pointers being added. Cannot // The assumed minimum alignment of the pointers being added. Cannot
// exceed |log2(allocationGranularity)|; having it be equal to // exceed |log2(allocationGranularity)|; having it be equal to
// the platform pointer alignment is what's wanted. // the platform pointer alignment is what's wanted.
static const int kPointerAlignmentInBits = WTF_ALIGN_OF(void*) == 8 ? 3 : 2; static const int kPointerAlignmentInBits = alignof(void*) == 8 ? 3 : 2;
static const size_t kPointerAlignmentMask = static const size_t kPointerAlignmentMask =
(0x1u << kPointerAlignmentInBits) - 1; (0x1u << kPointerAlignmentInBits) - 1;
...@@ -87,7 +87,7 @@ class PLATFORM_EXPORT SparseHeapBitmap { ...@@ -87,7 +87,7 @@ class PLATFORM_EXPORT SparseHeapBitmap {
static_assert(kPointerAlignmentMask <= kAllocationMask, static_assert(kPointerAlignmentMask <= kAllocationMask,
"address shift exceeds heap pointer alignment"); "address shift exceeds heap pointer alignment");
// For now, only recognize 8 and 4. // For now, only recognize 8 and 4.
static_assert(WTF_ALIGN_OF(void*) == 8 || WTF_ALIGN_OF(void*) == 4, static_assert(alignof(void*) == 8 || alignof(void*) == 4,
"unsupported pointer alignment"); "unsupported pointer alignment");
} }
......
...@@ -531,7 +531,7 @@ class PLATFORM_EXPORT TransformationMatrix { ...@@ -531,7 +531,7 @@ class PLATFORM_EXPORT TransformationMatrix {
// m_matrix can cause this class to require higher than usual alignment. // m_matrix can cause this class to require higher than usual alignment.
// Make sure the allocator handles this. // Make sure the allocator handles this.
DCHECK_EQ((reinterpret_cast<uintptr_t>(this) & DCHECK_EQ((reinterpret_cast<uintptr_t>(this) &
(WTF_ALIGN_OF(TransformationMatrix) - 1)), (alignof(TransformationMatrix) - 1)),
0UL); 0UL);
#endif #endif
} }
......
...@@ -115,17 +115,13 @@ class PODArena final : public RefCounted<PODArena> { ...@@ -115,17 +115,13 @@ class PODArena final : public RefCounted<PODArena> {
current_(nullptr), current_(nullptr),
current_chunk_size_(kDefaultChunkSize) {} current_chunk_size_(kDefaultChunkSize) {}
// Returns the alignment requirement for classes and structs on the
// current platform.
template <class T>
static size_t MinAlignment() {
return WTF_ALIGN_OF(T);
}
template <class T> template <class T>
void* AllocateBase() { void* AllocateBase() {
static_assert(
sizeof(T) % alignof(T) == 0,
"We are guaranteed that sizeof(T) is a multiple of alignof(T).");
void* ptr = nullptr; void* ptr = nullptr;
size_t rounded_size = RoundUp(sizeof(T), MinAlignment<T>()); size_t rounded_size = sizeof(T);
if (current_) if (current_)
ptr = current_->Allocate(rounded_size); ptr = current_->Allocate(rounded_size);
...@@ -140,12 +136,6 @@ class PODArena final : public RefCounted<PODArena> { ...@@ -140,12 +136,6 @@ class PODArena final : public RefCounted<PODArena> {
return ptr; return ptr;
} }
// Rounds up the given allocation size to the specified alignment.
size_t RoundUp(size_t size, size_t alignment) {
DCHECK(!(alignment % 2));
return (size + alignment - 1) & ~(alignment - 1);
}
// Manages a chunk of memory and individual allocations out of it. // Manages a chunk of memory and individual allocations out of it.
class Chunk final { class Chunk final {
USING_FAST_MALLOC(Chunk); USING_FAST_MALLOC(Chunk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment