Commit 041d7339 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] Fix memory allocator counters for partially releasing pages

Bug: chromium:724947
Change-Id: I287677b2cf18154bcbc0d0a5b15d12455d73d0c3
Reviewed-on: https://chromium-review.googlesource.com/534153Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45923}
parent a0aec7b2
......@@ -342,21 +342,22 @@ class V8_BASE_EXPORT VirtualMemory {
// Creates a single guard page at the given address.
bool Guard(void* address);
// Releases the memory after |free_start|.
void ReleasePartial(void* free_start) {
// Releases the memory after |free_start|. Returns the bytes released.
size_t ReleasePartial(void* free_start) {
DCHECK(IsReserved());
// Notice: Order is important here. The VirtualMemory object might live
// inside the allocated region.
size_t size = size_ - (reinterpret_cast<size_t>(free_start) -
reinterpret_cast<size_t>(address_));
const size_t size = size_ - (reinterpret_cast<size_t>(free_start) -
reinterpret_cast<size_t>(address_));
CHECK(InVM(free_start, size));
DCHECK_LT(address_, free_start);
DCHECK_LT(free_start, reinterpret_cast<void*>(
reinterpret_cast<size_t>(address_) + size_));
bool result = ReleasePartialRegion(address_, size_, free_start, size);
const bool result = ReleasePartialRegion(address_, size_, free_start, size);
USE(result);
DCHECK(result);
size_ -= size;
return size;
}
void Release() {
......
......@@ -874,10 +874,6 @@ void MemoryAllocator::PartialFreeMemory(MemoryChunk* chunk, Address start_free,
size_t bytes_to_free) {
base::VirtualMemory* reservation = chunk->reserved_memory();
DCHECK(reservation->IsReserved());
DCHECK_GE(size_.Value(), bytes_to_free);
size_.Decrement(bytes_to_free);
isolate_->counters()->memory_allocated()->Decrement(
static_cast<int>(bytes_to_free));
chunk->size_ -= bytes_to_free;
chunk->area_end_ -= bytes_to_free;
if (chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE)) {
......@@ -885,9 +881,16 @@ void MemoryAllocator::PartialFreeMemory(MemoryChunk* chunk, Address start_free,
static_cast<uintptr_t>(GetCommitPageSize()));
DCHECK_EQ(chunk->address() + chunk->size(),
chunk->area_end() + CodePageGuardSize());
chunk->reservation_.Guard(chunk->area_end_);
}
reservation->ReleasePartial(start_free);
reservation->Guard(chunk->area_end_);
}
// On e.g. Windows, a reservation may be larger than a page and releasing
// partially starting at |start_free| will also release the potentially
// unused part behind the current page.
const size_t released_bytes = reservation->ReleasePartial(start_free);
DCHECK_GE(size_.Value(), released_bytes);
size_.Decrement(released_bytes);
isolate_->counters()->memory_allocated()->Decrement(
static_cast<int>(released_bytes));
}
void MemoryAllocator::PreFreeMemory(MemoryChunk* 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