Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: test/cctest/test-heap.cc

Issue 7976003: Fix new space shrinking to reset from-space. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Lasse Reichstein. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index 28933fb86beaa169eb0b19e76241a4d6e2132ef3..86be15a5ca272aad04ad804ad589c322f7ca31a4 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -1221,6 +1221,50 @@ TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
}
+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 {
public:
HeapIteratorTestHelper(Object* a, Object* b)
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698