Revision: 9346
Author: [email protected]
Date: Tue Sep 20 06:37:40 2011
Log: Fix new space shrinking to reset from-space.
[email protected]
BUG=v8:1702
TEST=cctest/test-heap/GrowAndShrinkNewSpace
Review URL: http://codereview.chromium.org/7976003
http://code.google.com/p/v8/source/detail?r=9346
Modified:
/branches/bleeding_edge/src/spaces.cc
/branches/bleeding_edge/test/cctest/test-heap.cc
=======================================
--- /branches/bleeding_edge/src/spaces.cc Tue Sep 20 04:20:00 2011
+++ /branches/bleeding_edge/src/spaces.cc Tue Sep 20 06:37:40 2011
@@ -926,10 +926,10 @@
void NewSpace::Grow() {
ASSERT(Capacity() < MaximumCapacity());
if (to_space_.Grow()) {
- // Only grow from space if we managed to grow to space.
+ // Only grow from space if we managed to grow to-space.
if (!from_space_.Grow()) {
- // If we managed to grow to space but couldn't grow from space,
- // attempt to shrink to space.
+ // 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())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
@@ -947,10 +947,11 @@
RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment()));
if (rounded_new_capacity < Capacity() &&
to_space_.ShrinkTo(rounded_new_capacity)) {
- // Only shrink from space if we managed to shrink to space.
+ // Only shrink from-space if we managed to shrink to-space.
+ from_space_.Reset();
if (!from_space_.ShrinkTo(rounded_new_capacity)) {
- // If we managed to shrink to space but couldn't shrink from
- // space, attempt to grow to space again.
+ // If we managed to shrink to-space but couldn't shrink from
+ // space, attempt to grow to-space again.
if (!to_space_.GrowTo(from_space_.Capacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap.cc Mon Sep 19 11:36:47
2011
+++ /branches/bleeding_edge/test/cctest/test-heap.cc Tue Sep 20 06:37:40
2011
@@ -1219,6 +1219,50 @@
CHECK_GT(size_of_objects_2 / 20, delta);
}
}
+
+
+TEST(GrowAndShrinkNewSpace) {
+ InitializeVM();
+ v8::HandleScope scope;
+ NewSpace* new_space = HEAP->new_space();
+
+ // Explicitly growing should double the space capacity.
+ int old_capacity, new_capacity;
+ old_capacity = new_space->Capacity();
+ new_space->Grow();
+ 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);
+ ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED)));
+ }
+
+ // Explicitly shrinking should not affect space capacity.
+ old_capacity = new_space->Capacity();
+ new_space->Shrink();
+ new_capacity = new_space->Capacity();
+ ASSERT_EQ(old_capacity, new_capacity);
+
+ // Perform scavenge to empty the new space.
+ HEAP->CollectGarbage(NEW_SPACE);
+ ASSERT_LE(new_space->SizeAsInt(), old_capacity);
+
+ // Explicitly shrinking should halve the space capacity.
+ old_capacity = new_space->Capacity();
+ new_space->Shrink();
+ new_capacity = new_space->Capacity();
+ ASSERT_EQ(old_capacity, 2 * new_capacity);
+
+ // Consecutive shrinking should not affect space capacity.
+ old_capacity = new_space->Capacity();
+ new_space->Shrink();
+ new_space->Shrink();
+ new_space->Shrink();
+ new_capacity = new_space->Capacity();
+ ASSERT_EQ(old_capacity, new_capacity);
+}
class HeapIteratorTestHelper {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev