Commit 82fce0fc authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[heap] Be more precise when calculating allocated memory

The rounding error occured in VirtualMemory class when the provided page
allocator had bigger allocation page size than the commit page size and
the VirtualMemory was requested to reserve an area of a size aligned only
to commit page size.

Bug: v8:8096
Change-Id: Ifb9b7fe5797881408d1bb9e95073991a42b62e80
Reviewed-on: https://chromium-review.googlesource.com/c/1327041Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57365}
parent 03746eee
......@@ -220,12 +220,14 @@ VirtualMemory::VirtualMemory(v8::PageAllocator* page_allocator, size_t size,
void* hint, size_t alignment)
: page_allocator_(page_allocator) {
DCHECK_NOT_NULL(page_allocator);
DCHECK(IsAligned(size, page_allocator_->CommitPageSize()));
size_t page_size = page_allocator_->AllocatePageSize();
alignment = RoundUp(alignment, page_size);
size = RoundUp(size, page_size);
Address address = reinterpret_cast<Address>(AllocatePages(
page_allocator_, hint, size, alignment, PageAllocator::kNoAccess));
Address address = reinterpret_cast<Address>(
AllocatePages(page_allocator_, hint, RoundUp(size, page_size), alignment,
PageAllocator::kNoAccess));
if (address != kNullAddress) {
DCHECK(IsAligned(address, alignment));
region_ = base::AddressRegion(address, size);
}
}
......
......@@ -167,7 +167,7 @@ class V8_EXPORT_PRIVATE VirtualMemory final {
// Reserves virtual memory containing an area of the given size that is
// aligned per |alignment| rounded up to the |page_allocator|'s allocate page
// size.
// size. The |size| must be aligned with |page_allocator|'s commit page size.
// This may not be at the position returned by address().
VirtualMemory(v8::PageAllocator* page_allocator, size_t size, void* hint,
size_t alignment = 1);
......@@ -177,6 +177,8 @@ class V8_EXPORT_PRIVATE VirtualMemory final {
VirtualMemory(v8::PageAllocator* page_allocator, Address address, size_t size)
: page_allocator_(page_allocator), region_(address, size) {
DCHECK_NOT_NULL(page_allocator);
DCHECK(IsAligned(address, page_allocator->AllocatePageSize()));
DCHECK(IsAligned(size, page_allocator->CommitPageSize()));
}
// Releases the reserved memory, if any, controlled by this VirtualMemory
......
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