Use pages from lower to higher addresses in new space.

This CL constitutes the invariant that the top pointer in new space is always larger than objects allocated since the last new space garbage collection.

BUG=
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/26865004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17185 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
hpayer@chromium.org 2013-10-14 09:48:44 +00:00
parent 530109c73b
commit 629b26c519

View File

@ -1527,20 +1527,18 @@ void SemiSpace::TearDown() {
bool SemiSpace::Commit() { bool SemiSpace::Commit() {
ASSERT(!is_committed()); ASSERT(!is_committed());
int pages = capacity_ / Page::kPageSize; int pages = capacity_ / Page::kPageSize;
Address end = start_ + maximum_capacity_; if (!heap()->isolate()->memory_allocator()->CommitBlock(start_,
Address start = end - pages * Page::kPageSize;
if (!heap()->isolate()->memory_allocator()->CommitBlock(start,
capacity_, capacity_,
executable())) { executable())) {
return false; return false;
} }
NewSpacePage* page = anchor(); NewSpacePage* current = anchor();
for (int i = 1; i <= pages; i++) { for (int i = 0; i < pages; i++) {
NewSpacePage* new_page = NewSpacePage* new_page =
NewSpacePage::Initialize(heap(), end - i * Page::kPageSize, this); NewSpacePage::Initialize(heap(), start_ + i * Page::kPageSize, this);
new_page->InsertAfter(page); new_page->InsertAfter(current);
page = new_page; current = new_page;
} }
committed_ = true; committed_ = true;
@ -1584,20 +1582,18 @@ bool SemiSpace::GrowTo(int new_capacity) {
int pages_before = capacity_ / Page::kPageSize; int pages_before = capacity_ / Page::kPageSize;
int pages_after = new_capacity / Page::kPageSize; int pages_after = new_capacity / Page::kPageSize;
Address end = start_ + maximum_capacity_;
Address start = end - new_capacity;
size_t delta = new_capacity - capacity_; size_t delta = new_capacity - capacity_;
ASSERT(IsAligned(delta, OS::AllocateAlignment())); ASSERT(IsAligned(delta, OS::AllocateAlignment()));
if (!heap()->isolate()->memory_allocator()->CommitBlock( if (!heap()->isolate()->memory_allocator()->CommitBlock(
start, delta, executable())) { start_ + capacity_, delta, executable())) {
return false; return false;
} }
capacity_ = new_capacity; capacity_ = new_capacity;
NewSpacePage* last_page = anchor()->prev_page(); NewSpacePage* last_page = anchor()->prev_page();
ASSERT(last_page != anchor()); ASSERT(last_page != anchor());
for (int i = pages_before + 1; i <= pages_after; i++) { for (int i = pages_before; i < pages_after; i++) {
Address page_address = end - i * Page::kPageSize; Address page_address = start_ + i * Page::kPageSize;
NewSpacePage* new_page = NewSpacePage::Initialize(heap(), NewSpacePage* new_page = NewSpacePage::Initialize(heap(),
page_address, page_address,
this); this);
@ -1617,25 +1613,20 @@ bool SemiSpace::ShrinkTo(int new_capacity) {
ASSERT(new_capacity >= initial_capacity_); ASSERT(new_capacity >= initial_capacity_);
ASSERT(new_capacity < capacity_); ASSERT(new_capacity < capacity_);
if (is_committed()) { if (is_committed()) {
// Semispaces grow backwards from the end of their allocated capacity,
// so we find the before and after start addresses relative to the
// end of the space.
Address space_end = start_ + maximum_capacity_;
Address old_start = space_end - capacity_;
size_t delta = capacity_ - new_capacity; size_t delta = capacity_ - new_capacity;
ASSERT(IsAligned(delta, OS::AllocateAlignment())); ASSERT(IsAligned(delta, OS::AllocateAlignment()));
MemoryAllocator* allocator = heap()->isolate()->memory_allocator(); MemoryAllocator* allocator = heap()->isolate()->memory_allocator();
if (!allocator->UncommitBlock(old_start, delta)) { if (!allocator->UncommitBlock(start_ + new_capacity, delta)) {
return false; return false;
} }
int pages_after = new_capacity / Page::kPageSize; int pages_after = new_capacity / Page::kPageSize;
NewSpacePage* new_last_page = NewSpacePage* new_last_page =
NewSpacePage::FromAddress(space_end - pages_after * Page::kPageSize); NewSpacePage::FromAddress(start_ + (pages_after - 1) * Page::kPageSize);
new_last_page->set_next_page(anchor()); new_last_page->set_next_page(anchor());
anchor()->set_prev_page(new_last_page); anchor()->set_prev_page(new_last_page);
ASSERT((current_page_ <= first_page()) && (current_page_ >= new_last_page)); ASSERT((current_page_ >= first_page()) && (current_page_ <= new_last_page));
} }
capacity_ = new_capacity; capacity_ = new_capacity;