[memory] Make sure parameters are properly aligned in AllocatePages.
- Adds a DCHECK to AllocatePages to enforce hint address alignment. - Adds a DCHECK to AllocatePages to make length a multiple of allocation granularity. - Properly aligns the hint address in MemoryAllocator::AllocateChunk to MemoryChunk::kAlignment. This is to conform more closely to Chromium's page allocator API. Bug:chromium:756050 Change-Id: Ib991fa80609834107829a9559f4b5b6b0996fc72 Reviewed-on: https://chromium-review.googlesource.com/898095 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Bill Budge <bbudge@chromium.org> Cr-Commit-Position: refs/heads/master@{#51065}
This commit is contained in:
parent
a231fed8bf
commit
a1fc3c7b14
@ -143,6 +143,8 @@ void* GetRandomMmapAddr() { return GetPageAllocator()->GetRandomMmapAddr(); }
|
||||
|
||||
void* AllocatePages(void* address, size_t size, size_t alignment,
|
||||
PageAllocator::Permission access) {
|
||||
DCHECK_EQ(address, AlignedAddress(address, alignment));
|
||||
DCHECK_EQ(0UL, size & (GetPageAllocator()->AllocatePageSize() - 1));
|
||||
void* result = nullptr;
|
||||
for (int i = 0; i < kAllocationTries; ++i) {
|
||||
result =
|
||||
|
@ -710,7 +710,8 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size,
|
||||
VirtualMemory reservation;
|
||||
Address area_start = nullptr;
|
||||
Address area_end = nullptr;
|
||||
void* address_hint = heap->GetRandomMmapAddr();
|
||||
void* address_hint =
|
||||
AlignedAddress(heap->GetRandomMmapAddr(), MemoryChunk::kAlignment);
|
||||
|
||||
//
|
||||
// MemoryChunk layout:
|
||||
|
@ -134,8 +134,8 @@ TEST(AllocationTest, AllocateAndFree) {
|
||||
// A large allocation, aligned significantly beyond native granularity.
|
||||
const size_t kBigAlignment = 64 * v8::internal::MB;
|
||||
void* aligned_mem_addr = v8::internal::AllocatePages(
|
||||
v8::internal::GetRandomMmapAddr(), kAllocationSize, kBigAlignment,
|
||||
PageAllocator::Permission::kReadWrite);
|
||||
AlignedAddress(v8::internal::GetRandomMmapAddr(), kBigAlignment),
|
||||
kAllocationSize, kBigAlignment, PageAllocator::Permission::kReadWrite);
|
||||
CHECK_NOT_NULL(aligned_mem_addr);
|
||||
CHECK_EQ(aligned_mem_addr, AlignedAddress(aligned_mem_addr, kBigAlignment));
|
||||
CHECK(v8::internal::FreePages(aligned_mem_addr, kAllocationSize));
|
||||
|
Loading…
Reference in New Issue
Block a user