Reviewers: Vyacheslav Egorov,
Message:
PTAL.
Description:
Fix new space shrinking to compute correct capacity.
[email protected]
BUG=v8:1702
TEST=cctest/test-heap/GrowAndShrinkNewSpace
Please review this at http://codereview.chromium.org/7983001/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/spaces.h
M src/spaces.cc
M test/cctest/test-heap.cc
Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index
9aacf9603e42ada46f2c1953d1453695dfdeb3f8..a1bc3b9d80886afdb878685d28d0aec62391d4dd
100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -924,10 +924,14 @@ void NewSpace::Flip() {
void NewSpace::Grow() {
+ // Double the semispace size but only up to maximum capacity.
ASSERT(Capacity() < MaximumCapacity());
- if (to_space_.Grow()) {
+ ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment());
+ int new_capacity = Min(MaximumCapacity(), 2 *
static_cast<int>(Capacity()));
+ int rounded_new_capacity = RoundUp(new_capacity, Page::kPageSize);
+ if (to_space_.GrowTo(rounded_new_capacity)) {
// Only grow from space if we managed to grow to-space.
- if (!from_space_.Grow()) {
+ if (!from_space_.GrowTo(rounded_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())) {
@@ -942,9 +946,9 @@ void NewSpace::Grow() {
void NewSpace::Shrink() {
+ ASSERT(static_cast<size_t>(Page::kPageSize) > OS::AllocateAlignment());
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.
@@ -1144,15 +1148,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_);
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index
c649b04e385da4dd58cc8fc7ba94246f9b7f9e46..0180f8b5e9442e508a097e22597a39ab253b78d4
100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -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
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index
86be15a5ca272aad04ad804ad589c322f7ca31a4..aeab4014b7453403706d3a2858aa0593aa170570
100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -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_;
-};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev