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())) {
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.
}
-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_);
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;
}
// 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
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)));
}
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_;
-};