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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "execution.h" 7 #include "execution.h"
8 #include "factory.h" 8 #include "factory.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 #include "global-handles.h" 10 #include "global-handles.h"
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 intptr_t delta = size_of_objects_2 - size_of_objects_1; 1214 intptr_t delta = size_of_objects_2 - size_of_objects_1;
1215 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, " 1215 PrintF("Heap::SizeOfObjects: %" V8_PTR_PREFIX "d, "
1216 "Iterator: %" V8_PTR_PREFIX "d, " 1216 "Iterator: %" V8_PTR_PREFIX "d, "
1217 "delta: %" V8_PTR_PREFIX "d\n", 1217 "delta: %" V8_PTR_PREFIX "d\n",
1218 size_of_objects_1, size_of_objects_2, delta); 1218 size_of_objects_1, size_of_objects_2, delta);
1219 CHECK_GT(size_of_objects_2 / 20, delta); 1219 CHECK_GT(size_of_objects_2 / 20, delta);
1220 } 1220 }
1221 } 1221 }
1222 1222
1223 1223
1224 TEST(GrowAndShrinkNewSpace) {
1225 InitializeVM();
1226 v8::HandleScope scope;
1227 NewSpace* new_space = HEAP->new_space();
1228
1229 // Explicitly growing should double the space capacity.
1230 int old_capacity, new_capacity;
1231 old_capacity = new_space->Capacity();
1232 new_space->Grow();
1233 new_capacity = new_space->Capacity();
1234 ASSERT_EQ(2 * old_capacity, new_capacity);
1235
1236 // Fill up new space to the point that it exceeds old capacity.
1237 while (new_space->SizeAsInt() <= old_capacity) {
1238 Handle<FixedArray> filler = FACTORY->NewFixedArray(1000, NOT_TENURED);
1239 ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED)));
1240 }
1241
1242 // Explicitly shrinking should not affect space capacity.
1243 old_capacity = new_space->Capacity();
1244 new_space->Shrink();
1245 new_capacity = new_space->Capacity();
1246 ASSERT_EQ(old_capacity, new_capacity);
1247
1248 // Perform scavenge to empty the new space.
1249 HEAP->CollectGarbage(NEW_SPACE);
1250 ASSERT_LE(new_space->SizeAsInt(), old_capacity);
1251
1252 // Explicitly shrinking should halve the space capacity.
1253 old_capacity = new_space->Capacity();
1254 new_space->Shrink();
1255 new_capacity = new_space->Capacity();
1256 ASSERT_EQ(old_capacity, 2 * new_capacity);
1257
1258 // Consecutive shrinking should not affect space capacity.
1259 old_capacity = new_space->Capacity();
1260 new_space->Shrink();
1261 new_space->Shrink();
1262 new_space->Shrink();
1263 new_capacity = new_space->Capacity();
1264 ASSERT_EQ(old_capacity, new_capacity);
1265 }
1266
1267
1224 class HeapIteratorTestHelper { 1268 class HeapIteratorTestHelper {
1225 public: 1269 public:
1226 HeapIteratorTestHelper(Object* a, Object* b) 1270 HeapIteratorTestHelper(Object* a, Object* b)
1227 : a_(a), b_(b), a_found_(false), b_found_(false) {} 1271 : a_(a), b_(b), a_found_(false), b_found_(false) {}
1228 bool a_found() { return a_found_; } 1272 bool a_found() { return a_found_; }
1229 bool b_found() { return b_found_; } 1273 bool b_found() { return b_found_; }
1230 void IterateHeap() { 1274 void IterateHeap() {
1231 HeapIterator iterator; 1275 HeapIterator iterator;
1232 for (HeapObject* obj = iterator.next(); 1276 for (HeapObject* obj = iterator.next();
1233 obj != NULL; 1277 obj != NULL;
1234 obj = iterator.next()) { 1278 obj = iterator.next()) {
1235 if (obj == a_) 1279 if (obj == a_)
1236 a_found_ = true; 1280 a_found_ = true;
1237 else if (obj == b_) 1281 else if (obj == b_)
1238 b_found_ = true; 1282 b_found_ = true;
1239 } 1283 }
1240 } 1284 }
1241 private: 1285 private:
1242 Object* a_; 1286 Object* a_;
1243 Object* b_; 1287 Object* b_;
1244 bool a_found_; 1288 bool a_found_;
1245 bool b_found_; 1289 bool b_found_;
1246 }; 1290 };
OLDNEW
« 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