Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: src/spaces.cc

Issue 23641009: Refactor and cleanup VirtualMemory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nits. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/spaces.h ('k') | src/spaces-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 2faf41912e8e3db3319ed940a5c11c1ad8cad577..84cce8a77473077544aa1573e81c4466e6f98603 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -245,7 +245,8 @@ Address CodeRange::AllocateRawMemory(const size_t requested_size,
bool CodeRange::CommitRawMemory(Address start, size_t length) {
- return isolate_->memory_allocator()->CommitMemory(start, length, EXECUTABLE);
+ return isolate_->memory_allocator()->CommitMemory(
+ start, length, VirtualMemory::EXECUTABLE);
}
@@ -257,7 +258,9 @@ bool CodeRange::UncommitRawMemory(Address start, size_t length) {
void CodeRange::FreeRawMemory(Address address, size_t length) {
ASSERT(IsAddressAligned(address, MemoryChunk::kAlignment));
free_list_.Add(FreeBlock(address, length));
- code_range_->Uncommit(address, length);
+ bool result = code_range_->Uncommit(address, length);
+ ASSERT(result);
+ USE(result);
}
@@ -308,8 +311,8 @@ void MemoryAllocator::TearDown() {
bool MemoryAllocator::CommitMemory(Address base,
size_t size,
- Executability executable) {
- if (!VirtualMemory::CommitRegion(base, size, executable == EXECUTABLE)) {
+ VirtualMemory::Executability executability) {
+ if (!VirtualMemory::CommitRegion(base, size, executability)) {
return false;
}
UpdateAllocatedSpaceLimits(base, base + size);
@@ -318,7 +321,7 @@ bool MemoryAllocator::CommitMemory(Address base,
void MemoryAllocator::FreeMemory(VirtualMemory* reservation,
- Executability executable) {
+ VirtualMemory::Executability executability) {
// TODO(gc) make code_range part of memory allocator?
ASSERT(reservation->IsReserved());
size_t size = reservation->size();
@@ -327,36 +330,38 @@ void MemoryAllocator::FreeMemory(VirtualMemory* reservation,
isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
- if (executable == EXECUTABLE) {
+ if (executability == VirtualMemory::EXECUTABLE) {
ASSERT(size_executable_ >= size);
size_executable_ -= size;
}
// Code which is part of the code-range does not have its own VirtualMemory.
ASSERT(!isolate_->code_range()->contains(
static_cast<Address>(reservation->address())));
- ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists());
+ ASSERT(executability == VirtualMemory::NOT_EXECUTABLE ||
+ !isolate_->code_range()->exists());
reservation->Release();
}
void MemoryAllocator::FreeMemory(Address base,
size_t size,
- Executability executable) {
+ VirtualMemory::Executability executability) {
// TODO(gc) make code_range part of memory allocator?
ASSERT(size_ >= size);
size_ -= size;
isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(size));
- if (executable == EXECUTABLE) {
+ if (executability == VirtualMemory::EXECUTABLE) {
ASSERT(size_executable_ >= size);
size_executable_ -= size;
}
if (isolate_->code_range()->contains(static_cast<Address>(base))) {
- ASSERT(executable == EXECUTABLE);
+ ASSERT(executability == VirtualMemory::EXECUTABLE);
isolate_->code_range()->FreeRawMemory(base, size);
} else {
- ASSERT(executable == NOT_EXECUTABLE || !isolate_->code_range()->exists());
+ ASSERT(executability == VirtualMemory::NOT_EXECUTABLE ||
+ !isolate_->code_range()->exists());
bool result = VirtualMemory::ReleaseRegion(base, size);
USE(result);
ASSERT(result);
@@ -378,17 +383,18 @@ Address MemoryAllocator::ReserveAlignedMemory(size_t size,
}
-Address MemoryAllocator::AllocateAlignedMemory(size_t reserve_size,
- size_t commit_size,
- size_t alignment,
- Executability executable,
- VirtualMemory* controller) {
+Address MemoryAllocator::AllocateAlignedMemory(
+ size_t reserve_size,
+ size_t commit_size,
+ size_t alignment,
+ VirtualMemory::Executability executability,
+ VirtualMemory* controller) {
ASSERT(commit_size <= reserve_size);
VirtualMemory reservation;
Address base = ReserveAlignedMemory(reserve_size, alignment, &reservation);
if (base == NULL) return NULL;
- if (executable == EXECUTABLE) {
+ if (executability == VirtualMemory::EXECUTABLE) {
if (!CommitExecutableMemory(&reservation,
base,
commit_size,
@@ -396,7 +402,7 @@ Address MemoryAllocator::AllocateAlignedMemory(size_t reserve_size,
base = NULL;
}
} else {
- if (reservation.Commit(base, commit_size, false)) {
+ if (reservation.Commit(base, commit_size, VirtualMemory::NOT_EXECUTABLE)) {
UpdateAllocatedSpaceLimits(base, base + commit_size);
} else {
base = NULL;
@@ -433,7 +439,7 @@ NewSpacePage* NewSpacePage::Initialize(Heap* heap,
Page::kPageSize,
area_start,
area_end,
- NOT_EXECUTABLE,
+ VirtualMemory::NOT_EXECUTABLE,
semi_space);
chunk->set_next_chunk(NULL);
chunk->set_prev_chunk(NULL);
@@ -464,7 +470,7 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap,
size_t size,
Address area_start,
Address area_end,
- Executability executable,
+ VirtualMemory::Executability executability,
Space* owner) {
MemoryChunk* chunk = FromAddress(base);
@@ -496,7 +502,7 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap,
ASSERT(OFFSET_OF(MemoryChunk, flags_) == kFlagsOffset);
ASSERT(OFFSET_OF(MemoryChunk, live_byte_count_) == kLiveBytesOffset);
- if (executable == EXECUTABLE) {
+ if (executability == VirtualMemory::EXECUTABLE) {
chunk->SetFlag(IS_EXECUTABLE);
}
@@ -513,9 +519,10 @@ bool MemoryChunk::CommitArea(size_t requested) {
size_t guard_size = IsFlagSet(IS_EXECUTABLE) ?
MemoryAllocator::CodePageGuardSize() : 0;
size_t header_size = area_start() - address() - guard_size;
- size_t commit_size = RoundUp(header_size + requested, OS::CommitPageSize());
+ size_t commit_size = RoundUp(header_size + requested,
+ VirtualMemory::GetPageSize());
size_t committed_size = RoundUp(header_size + (area_end() - area_start()),
- OS::CommitPageSize());
+ VirtualMemory::GetPageSize());
if (commit_size > committed_size) {
// Commit size should be less or equal than the reserved size.
@@ -524,10 +531,10 @@ bool MemoryChunk::CommitArea(size_t requested) {
Address start = address() + committed_size + guard_size;
size_t length = commit_size - committed_size;
if (reservation_.IsReserved()) {
- Executability executable = IsFlagSet(IS_EXECUTABLE)
- ? EXECUTABLE : NOT_EXECUTABLE;
+ VirtualMemory::Executability executability = IsFlagSet(IS_EXECUTABLE)
+ ? VirtualMemory::EXECUTABLE : VirtualMemory::NOT_EXECUTABLE;
if (!heap()->isolate()->memory_allocator()->CommitMemory(
- start, length, executable)) {
+ start, length, executability)) {
return false;
}
} else {
@@ -589,10 +596,11 @@ void MemoryChunk::Unlink() {
}
-MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
- intptr_t commit_area_size,
- Executability executable,
- Space* owner) {
+MemoryChunk* MemoryAllocator::AllocateChunk(
+ intptr_t reserve_area_size,
+ intptr_t commit_area_size,
+ VirtualMemory::Executability executability,
+ Space* owner) {
ASSERT(commit_area_size <= reserve_area_size);
size_t chunk_size;
@@ -632,9 +640,9 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
// +----------------------------+<- base + chunk_size
//
- if (executable == EXECUTABLE) {
+ if (executability == VirtualMemory::EXECUTABLE) {
chunk_size = RoundUp(CodePageAreaStartOffset() + reserve_area_size,
- OS::CommitPageSize()) + CodePageGuardSize();
+ VirtualMemory::GetPageSize()) + CodePageGuardSize();
// Check executable memory limit.
if (size_executable_ + chunk_size > capacity_executable_) {
@@ -646,7 +654,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
// Size of header (not executable) plus area (executable).
size_t commit_size = RoundUp(CodePageGuardStartOffset() + commit_area_size,
- OS::CommitPageSize());
+ VirtualMemory::GetPageSize());
// Allocate executable memory either from code range or from the
// OS.
if (isolate_->code_range()->exists()) {
@@ -663,7 +671,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
base = AllocateAlignedMemory(chunk_size,
commit_size,
MemoryChunk::kAlignment,
- executable,
+ executability,
&reservation);
if (base == NULL) return NULL;
// Update executable memory size.
@@ -679,13 +687,14 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
area_end = area_start + commit_area_size;
} else {
chunk_size = RoundUp(MemoryChunk::kObjectStartOffset + reserve_area_size,
- OS::CommitPageSize());
- size_t commit_size = RoundUp(MemoryChunk::kObjectStartOffset +
- commit_area_size, OS::CommitPageSize());
+ VirtualMemory::GetPageSize());
+ size_t commit_size = RoundUp(
+ MemoryChunk::kObjectStartOffset + commit_area_size,
+ VirtualMemory::GetPageSize());
base = AllocateAlignedMemory(chunk_size,
commit_size,
MemoryChunk::kAlignment,
- executable,
+ executability,
&reservation);
if (base == NULL) return NULL;
@@ -714,7 +723,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size,
chunk_size,
area_start,
area_end,
- executable,
+ executability,
owner);
result->set_reserved_memory(&reservation);
return result;
@@ -730,23 +739,25 @@ void Page::ResetFreeListStatistics() {
}
-Page* MemoryAllocator::AllocatePage(intptr_t size,
- PagedSpace* owner,
- Executability executable) {
- MemoryChunk* chunk = AllocateChunk(size, size, executable, owner);
+Page* MemoryAllocator::AllocatePage(
+ intptr_t size,
+ PagedSpace* owner,
+ VirtualMemory::Executability executability) {
+ MemoryChunk* chunk = AllocateChunk(size, size, executability, owner);
if (chunk == NULL) return NULL;
- return Page::Initialize(isolate_->heap(), chunk, executable, owner);
+ return Page::Initialize(isolate_->heap(), chunk, executability, owner);
}
-LargePage* MemoryAllocator::AllocateLargePage(intptr_t object_size,
- Space* owner,
- Executability executable) {
+LargePage* MemoryAllocator::AllocateLargePage(
+ intptr_t object_size,
+ Space* owner,
+ VirtualMemory::Executability executability) {
MemoryChunk* chunk = AllocateChunk(object_size,
object_size,
- executable,
+ executability,
owner);
if (chunk == NULL) return NULL;
return LargePage::Initialize(isolate_->heap(), chunk);
@@ -769,19 +780,19 @@ void MemoryAllocator::Free(MemoryChunk* chunk) {
VirtualMemory* reservation = chunk->reserved_memory();
if (reservation->IsReserved()) {
- FreeMemory(reservation, chunk->executable());
+ FreeMemory(reservation, chunk->executability());
} else {
FreeMemory(chunk->address(),
chunk->size(),
- chunk->executable());
+ chunk->executability());
}
}
bool MemoryAllocator::CommitBlock(Address start,
size_t size,
- Executability executable) {
- if (!CommitMemory(start, size, executable)) return false;
+ VirtualMemory::Executability executability) {
+ if (!CommitMemory(start, size, executability)) return false;
if (Heap::ShouldZapGarbage()) {
ZapBlock(start, size);
@@ -866,12 +877,12 @@ void MemoryAllocator::ReportStatistics() {
int MemoryAllocator::CodePageGuardStartOffset() {
// We are guarding code pages: the first OS page after the header
// will be protected as non-writable.
- return RoundUp(Page::kObjectStartOffset, OS::CommitPageSize());
+ return RoundUp(Page::kObjectStartOffset, VirtualMemory::GetPageSize());
}
int MemoryAllocator::CodePageGuardSize() {
- return static_cast<int>(OS::CommitPageSize());
+ return static_cast<int>(VirtualMemory::GetPageSize());
}
@@ -885,7 +896,7 @@ int MemoryAllocator::CodePageAreaStartOffset() {
int MemoryAllocator::CodePageAreaEndOffset() {
// We are guarding code pages: the last OS page will be protected as
// non-writable.
- return Page::kPageSize - static_cast<int>(OS::CommitPageSize());
+ return Page::kPageSize - static_cast<int>(VirtualMemory::GetPageSize());
}
@@ -896,24 +907,26 @@ bool MemoryAllocator::CommitExecutableMemory(VirtualMemory* vm,
// Commit page header (not executable).
if (!vm->Commit(start,
CodePageGuardStartOffset(),
- false)) {
+ VirtualMemory::NOT_EXECUTABLE)) {
return false;
}
// Create guard page after the header.
- if (!vm->Guard(start + CodePageGuardStartOffset())) {
+ if (!vm->Guard(start + CodePageGuardStartOffset(),
+ VirtualMemory::GetPageSize())) {
return false;
}
// Commit page body (executable).
if (!vm->Commit(start + CodePageAreaStartOffset(),
commit_size - CodePageGuardStartOffset(),
- true)) {
+ VirtualMemory::EXECUTABLE)) {
return false;
}
// Create guard page before the end.
- if (!vm->Guard(start + reserved_size - CodePageGuardSize())) {
+ if (!vm->Guard(start + reserved_size - CodePageGuardSize(),
+ VirtualMemory::GetPageSize())) {
return false;
}
@@ -942,8 +955,8 @@ void MemoryChunk::IncrementLiveBytesFromMutator(Address address, int by) {
PagedSpace::PagedSpace(Heap* heap,
intptr_t max_capacity,
AllocationSpace id,
- Executability executable)
- : Space(heap, id, executable),
+ VirtualMemory::Executability executability)
+ : Space(heap, id, executability),
free_list_(this),
was_swept_conservatively_(false),
first_unswept_page_(Page::FromAddress(NULL)),
@@ -1041,7 +1054,7 @@ bool PagedSpace::Expand() {
}
Page* p = heap()->isolate()->memory_allocator()->AllocatePage(
- size, this, executable());
+ size, this, executability());
if (p == NULL) return false;
ASSERT(Capacity() <= max_capacity_);
@@ -1288,8 +1301,8 @@ void NewSpace::TearDown() {
LOG(heap()->isolate(), DeleteEvent("InitialChunk", chunk_base_));
ASSERT(reservation_.IsReserved());
- heap()->isolate()->memory_allocator()->FreeMemory(&reservation_,
- NOT_EXECUTABLE);
+ heap()->isolate()->memory_allocator()->FreeMemory(
+ &reservation_, VirtualMemory::NOT_EXECUTABLE);
chunk_base_ = NULL;
chunk_size_ = 0;
}
@@ -1524,7 +1537,7 @@ bool SemiSpace::Commit() {
Address start = end - pages * Page::kPageSize;
if (!heap()->isolate()->memory_allocator()->CommitBlock(start,
capacity_,
- executable())) {
+ executability())) {
return false;
}
@@ -1581,9 +1594,9 @@ bool SemiSpace::GrowTo(int new_capacity) {
Address start = end - new_capacity;
size_t delta = new_capacity - capacity_;
- ASSERT(IsAligned(delta, OS::AllocateAlignment()));
+ ASSERT(IsAligned(delta, VirtualMemory::GetAllocationGranularity()));
if (!heap()->isolate()->memory_allocator()->CommitBlock(
- start, delta, executable())) {
+ start, delta, executability())) {
return false;
}
capacity_ = new_capacity;
@@ -1616,7 +1629,7 @@ bool SemiSpace::ShrinkTo(int new_capacity) {
Address space_end = start_ + maximum_capacity_;
Address old_start = space_end - capacity_;
size_t delta = capacity_ - new_capacity;
- ASSERT(IsAligned(delta, OS::AllocateAlignment()));
+ ASSERT(IsAligned(delta, VirtualMemory::GetAllocationGranularity()));
MemoryAllocator* allocator = heap()->isolate()->memory_allocator();
if (!allocator->UncommitBlock(old_start, delta)) {
@@ -2924,7 +2937,8 @@ static bool ComparePointers(void* key1, void* key2) {
LargeObjectSpace::LargeObjectSpace(Heap* heap,
intptr_t max_capacity,
AllocationSpace id)
- : Space(heap, id, NOT_EXECUTABLE), // Managed on a per-allocation basis
+ // Managed on a per-allocation basis
+ : Space(heap, id, VirtualMemory::NOT_EXECUTABLE),
max_capacity_(max_capacity),
first_page_(NULL),
size_(0),
@@ -2958,8 +2972,8 @@ void LargeObjectSpace::TearDown() {
}
-MaybeObject* LargeObjectSpace::AllocateRaw(int object_size,
- Executability executable) {
+MaybeObject* LargeObjectSpace::AllocateRaw(
+ int object_size, VirtualMemory::Executability executability) {
// Check if we want to force a GC before growing the old space further.
// If so, fail the allocation.
if (!heap()->always_allocate() &&
@@ -2972,7 +2986,7 @@ MaybeObject* LargeObjectSpace::AllocateRaw(int object_size,
}
LargePage* page = heap()->isolate()->memory_allocator()->
- AllocateLargePage(object_size, this, executable);
+ AllocateLargePage(object_size, this, executability);
if (page == NULL) return Failure::RetryAfterGC(identity());
ASSERT(page->area_size() >= object_size);
« no previous file with comments | « src/spaces.h ('k') | src/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698