Fix new space shrinking to compute correct capacity.

R=vegorov@chromium.org
BUG=v8:1702
TEST=cctest/test-heap/GrowAndShrinkNewSpace

Review URL: http://codereview.chromium.org/7983001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9348 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9702f38c
......@@ -925,10 +925,12 @@ void NewSpace::Flip() {
void NewSpace::Grow() {
// Double the semispace size but only up to maximum capacity.
ASSERT(Capacity() < MaximumCapacity());
if (to_space_.Grow()) {
int new_capacity = Min(MaximumCapacity(), 2 * static_cast<int>(Capacity()));
if (to_space_.GrowTo(new_capacity)) {
// Only grow from space if we managed to grow to-space.
if (!from_space_.Grow()) {
if (!from_space_.GrowTo(new_capacity)) {
// If we managed to grow to-space but couldn't grow from-space,
// attempt to shrink to-space.
if (!to_space_.ShrinkTo(from_space_.Capacity())) {
......@@ -944,8 +946,7 @@ void NewSpace::Grow() {
void NewSpace::Shrink() {
int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt());
int rounded_new_capacity =
RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment()));
int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize);
if (rounded_new_capacity < Capacity() &&
to_space_.ShrinkTo(rounded_new_capacity)) {
// Only shrink from-space if we managed to shrink to-space.
......@@ -1145,15 +1146,6 @@ bool SemiSpace::Uncommit() {
}
bool SemiSpace::Grow() {
// Double the semispace size but only up to maximum capacity.
ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment());
int new_capacity = Min(maximum_capacity_,
RoundUp(capacity_ * 2, static_cast<int>(Page::kPageSize)));
return GrowTo(new_capacity);
}
bool SemiSpace::GrowTo(int new_capacity) {
ASSERT((new_capacity & Page::kPageAlignmentMask) == 0);
ASSERT(new_capacity <= maximum_capacity_);
......@@ -1210,7 +1202,7 @@ bool SemiSpace::ShrinkTo(int new_capacity) {
NewSpacePage::FromAddress(space_end - pages_after * Page::kPageSize);
new_last_page->set_next_page(anchor());
anchor()->set_prev_page(new_last_page);
ASSERT(current_page_ == first_page());
ASSERT((current_page_ <= first_page()) && (current_page_ >= new_last_page));
return true;
}
......
......@@ -1793,14 +1793,9 @@ class SemiSpace : public Space {
// True if the space has been set up but not torn down.
bool HasBeenSetup() { return start_ != NULL; }
// Grow the size of the semispace by committing extra virtual memory.
// Assumes that the caller has checked that the semispace has not reached
// its maximum capacity (and thus there is space available in the reserved
// address range to grow).
bool Grow();
// Grow the semispace to the new capacity. The new capacity
// requested must be larger than the current capacity.
// requested must be larger than the current capacity and less than
// the maximum capacity.
bool GrowTo(int new_capacity);
// Shrinks the semispace to the new capacity. The new capacity
......
......@@ -1233,9 +1233,8 @@ TEST(GrowAndShrinkNewSpace) {
new_capacity = new_space->Capacity();
ASSERT_EQ(2 * old_capacity, new_capacity);
// Fill up new space to the point that it exceeds old capacity.
while (new_space->SizeAsInt() <= old_capacity) {
Handle<FixedArray> filler = FACTORY->NewFixedArray(1000, NOT_TENURED);
// Fill up new space to the point that it is almost full.
while (new_space->SizeAsInt() + FixedArray::SizeFor(1000) < new_capacity) {
ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED)));
}
......@@ -1263,28 +1262,3 @@ TEST(GrowAndShrinkNewSpace) {
new_capacity = new_space->Capacity();
ASSERT_EQ(old_capacity, new_capacity);
}
class HeapIteratorTestHelper {
public:
HeapIteratorTestHelper(Object* a, Object* b)
: a_(a), b_(b), a_found_(false), b_found_(false) {}
bool a_found() { return a_found_; }
bool b_found() { return b_found_; }
void IterateHeap() {
HeapIterator iterator;
for (HeapObject* obj = iterator.next();
obj != NULL;
obj = iterator.next()) {
if (obj == a_)
a_found_ = true;
else if (obj == b_)
b_found_ = true;
}
}
private:
Object* a_;
Object* b_;
bool a_found_;
bool b_found_;
};
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