Revision: 9348
Author: [email protected]
Date: Tue Sep 20 08:35:36 2011
Log: Fix new space shrinking to compute correct capacity.
[email protected]
BUG=v8:1702
TEST=cctest/test-heap/GrowAndShrinkNewSpace
Review URL: http://codereview.chromium.org/7983001
http://code.google.com/p/v8/source/detail?r=9348
Modified:
/branches/bleeding_edge/src/spaces.cc
/branches/bleeding_edge/src/spaces.h
/branches/bleeding_edge/test/cctest/test-heap.cc
=======================================
--- /branches/bleeding_edge/src/spaces.cc Tue Sep 20 07:46:33 2011
+++ /branches/bleeding_edge/src/spaces.cc Tue Sep 20 08:35:36 2011
@@ -925,10 +925,12 @@
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::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.
@@ -1143,15 +1144,6 @@
committed_ = false;
return true;
}
-
-
-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) {
@@ -1210,7 +1202,7 @@
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;
}
=======================================
--- /branches/bleeding_edge/src/spaces.h Tue Sep 20 04:20:00 2011
+++ /branches/bleeding_edge/src/spaces.h Tue Sep 20 08:35:36 2011
@@ -1792,15 +1792,10 @@
// 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
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap.cc Tue Sep 20 06:37:40
2011
+++ /branches/bleeding_edge/test/cctest/test-heap.cc Tue Sep 20 08:35:36
2011
@@ -1233,9 +1233,8 @@
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 @@
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_;
-};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev