Commit a1fc3c7b authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[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/898095Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51065}
parent a231fed8
...@@ -143,6 +143,8 @@ void* GetRandomMmapAddr() { return GetPageAllocator()->GetRandomMmapAddr(); } ...@@ -143,6 +143,8 @@ void* GetRandomMmapAddr() { return GetPageAllocator()->GetRandomMmapAddr(); }
void* AllocatePages(void* address, size_t size, size_t alignment, void* AllocatePages(void* address, size_t size, size_t alignment,
PageAllocator::Permission access) { PageAllocator::Permission access) {
DCHECK_EQ(address, AlignedAddress(address, alignment));
DCHECK_EQ(0UL, size & (GetPageAllocator()->AllocatePageSize() - 1));
void* result = nullptr; void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) { for (int i = 0; i < kAllocationTries; ++i) {
result = result =
......
...@@ -710,7 +710,8 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size, ...@@ -710,7 +710,8 @@ MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size,
VirtualMemory reservation; VirtualMemory reservation;
Address area_start = nullptr; Address area_start = nullptr;
Address area_end = nullptr; Address area_end = nullptr;
void* address_hint = heap->GetRandomMmapAddr(); void* address_hint =
AlignedAddress(heap->GetRandomMmapAddr(), MemoryChunk::kAlignment);
// //
// MemoryChunk layout: // MemoryChunk layout:
......
...@@ -134,8 +134,8 @@ TEST(AllocationTest, AllocateAndFree) { ...@@ -134,8 +134,8 @@ TEST(AllocationTest, AllocateAndFree) {
// A large allocation, aligned significantly beyond native granularity. // A large allocation, aligned significantly beyond native granularity.
const size_t kBigAlignment = 64 * v8::internal::MB; const size_t kBigAlignment = 64 * v8::internal::MB;
void* aligned_mem_addr = v8::internal::AllocatePages( void* aligned_mem_addr = v8::internal::AllocatePages(
v8::internal::GetRandomMmapAddr(), kAllocationSize, kBigAlignment, AlignedAddress(v8::internal::GetRandomMmapAddr(), kBigAlignment),
PageAllocator::Permission::kReadWrite); kAllocationSize, kBigAlignment, PageAllocator::Permission::kReadWrite);
CHECK_NOT_NULL(aligned_mem_addr); CHECK_NOT_NULL(aligned_mem_addr);
CHECK_EQ(aligned_mem_addr, AlignedAddress(aligned_mem_addr, kBigAlignment)); CHECK_EQ(aligned_mem_addr, AlignedAddress(aligned_mem_addr, kBigAlignment));
CHECK(v8::internal::FreePages(aligned_mem_addr, kAllocationSize)); CHECK(v8::internal::FreePages(aligned_mem_addr, kAllocationSize));
......
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