Index: src/spaces.cc |
diff --git a/src/spaces.cc b/src/spaces.cc |
index 8e7a947f171e86b7693bc682f71ed702e9644980..db4ca7c474638b7a66b625b346fa65f94c5a52fe 100644 |
--- a/src/spaces.cc |
+++ b/src/spaces.cc |
@@ -324,70 +324,29 @@ void MemoryAllocator::FreeMemory(Address base, |
} |
-Address MemoryAllocator::ReserveAlignedMemory(const size_t requested, |
- size_t alignment, |
- size_t* allocated_size) { |
+Address MemoryAllocator::ReserveAlignedMemory(const size_t size, |
+ size_t alignment) { |
ASSERT(IsAligned(alignment, OS::AllocateAlignment())); |
- if (size_ + requested > capacity_) return NULL; |
- |
- size_t allocated = RoundUp(requested + alignment, |
- static_cast<intptr_t>(OS::AllocateAlignment())); |
- |
- Address base = reinterpret_cast<Address>( |
- VirtualMemory::ReserveRegion(allocated)); |
- |
- Address end = base + allocated; |
- |
- if (base == 0) return NULL; |
- |
- Address aligned_base = RoundUp(base, alignment); |
- |
- ASSERT(aligned_base + requested <= base + allocated); |
- |
- // The difference between re-aligned base address and base address is |
- // multiple of OS::AllocateAlignment(). |
- if (aligned_base != base) { |
- ASSERT(aligned_base > base); |
- // TODO(gc) check result of operation? |
- VirtualMemory::ReleaseRegion(reinterpret_cast<void*>(base), |
- aligned_base - base); |
- allocated -= (aligned_base - base); |
- base = aligned_base; |
- } |
- |
- ASSERT(base + allocated == end); |
- |
- Address requested_end = base + requested; |
- Address aligned_requested_end = |
- RoundUp(requested_end, OS::AllocateAlignment()); |
- |
- if (aligned_requested_end < end) { |
- // TODO(gc) check result of operation? |
- VirtualMemory::ReleaseRegion(reinterpret_cast<void*>(aligned_requested_end), |
- end - aligned_requested_end); |
- allocated = aligned_requested_end - base; |
- } |
- |
- size_ += allocated; |
- *allocated_size = allocated; |
- return base; |
+ Address result = static_cast<Address>( |
+ VirtualMemory::ReserveAlignedRegion(size, alignment)); |
+ size_ += size; |
+ return result; |
} |
-Address MemoryAllocator::AllocateAlignedMemory(const size_t requested, |
+Address MemoryAllocator::AllocateAlignedMemory(const size_t size, |
size_t alignment, |
- Executability executable, |
- size_t* allocated_size) { |
+ Executability executable) { |
Address base = |
- ReserveAlignedMemory(requested, Page::kPageSize, allocated_size); |
+ ReserveAlignedMemory(size, Page::kPageSize); |
if (base == NULL) return NULL; |
if (!VirtualMemory::CommitRegion(base, |
- *allocated_size, |
+ size, |
executable == EXECUTABLE)) { |
- VirtualMemory::ReleaseRegion(base, *allocated_size); |
- size_ -= *allocated_size; |
+ VirtualMemory::ReleaseRegion(base, size); |
+ size_ -= size; |
return NULL; |
} |
@@ -507,8 +466,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t body_size, |
} else { |
base = AllocateAlignedMemory(chunk_size, |
MemoryChunk::kAlignment, |
- executable, |
- &chunk_size); |
+ executable); |
} |
if (base == NULL) return NULL; |
@@ -518,8 +476,7 @@ MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t body_size, |
} else { |
base = AllocateAlignedMemory(chunk_size, |
MemoryChunk::kAlignment, |
- executable, |
- &chunk_size); |
+ executable); |
if (base == NULL) return NULL; |
} |
@@ -839,12 +796,11 @@ bool NewSpace::Setup(int reserved_semispace_capacity, |
// this chunk must be a power of two and it must be aligned to its size. |
int initial_semispace_capacity = heap()->InitialSemiSpaceSize(); |
- size_t size = 0; |
+ size_t size = 2 * reserved_semispace_capacity; |
Address base = |
heap()->isolate()->memory_allocator()->ReserveAlignedMemory( |
- 2 * reserved_semispace_capacity, |
- 2 * reserved_semispace_capacity, |
- &size); |
+ size, |
+ size); |
if (base == NULL) return false; |