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

Side by Side Diff: test/cctest/test-heap.cc

Issue 7983001: Fix new space shrinking to compute correct capacity. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Vyacheslav Egorov. 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 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 v8::HandleScope scope; 1226 v8::HandleScope scope;
1227 NewSpace* new_space = HEAP->new_space(); 1227 NewSpace* new_space = HEAP->new_space();
1228 1228
1229 // Explicitly growing should double the space capacity. 1229 // Explicitly growing should double the space capacity.
1230 int old_capacity, new_capacity; 1230 int old_capacity, new_capacity;
1231 old_capacity = new_space->Capacity(); 1231 old_capacity = new_space->Capacity();
1232 new_space->Grow(); 1232 new_space->Grow();
1233 new_capacity = new_space->Capacity(); 1233 new_capacity = new_space->Capacity();
1234 ASSERT_EQ(2 * old_capacity, new_capacity); 1234 ASSERT_EQ(2 * old_capacity, new_capacity);
1235 1235
1236 // Fill up new space to the point that it exceeds old capacity. 1236 // Fill up new space to the point that it is almost full.
1237 while (new_space->SizeAsInt() <= old_capacity) { 1237 while (new_space->SizeAsInt() + FixedArray::SizeFor(1000) < new_capacity) {
1238 Handle<FixedArray> filler = FACTORY->NewFixedArray(1000, NOT_TENURED);
1239 ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); 1238 ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED)));
1240 } 1239 }
1241 1240
1242 // Explicitly shrinking should not affect space capacity. 1241 // Explicitly shrinking should not affect space capacity.
1243 old_capacity = new_space->Capacity(); 1242 old_capacity = new_space->Capacity();
1244 new_space->Shrink(); 1243 new_space->Shrink();
1245 new_capacity = new_space->Capacity(); 1244 new_capacity = new_space->Capacity();
1246 ASSERT_EQ(old_capacity, new_capacity); 1245 ASSERT_EQ(old_capacity, new_capacity);
1247 1246
1248 // Perform scavenge to empty the new space. 1247 // Perform scavenge to empty the new space.
1249 HEAP->CollectGarbage(NEW_SPACE); 1248 HEAP->CollectGarbage(NEW_SPACE);
1250 ASSERT_LE(new_space->SizeAsInt(), old_capacity); 1249 ASSERT_LE(new_space->SizeAsInt(), old_capacity);
1251 1250
1252 // Explicitly shrinking should halve the space capacity. 1251 // Explicitly shrinking should halve the space capacity.
1253 old_capacity = new_space->Capacity(); 1252 old_capacity = new_space->Capacity();
1254 new_space->Shrink(); 1253 new_space->Shrink();
1255 new_capacity = new_space->Capacity(); 1254 new_capacity = new_space->Capacity();
1256 ASSERT_EQ(old_capacity, 2 * new_capacity); 1255 ASSERT_EQ(old_capacity, 2 * new_capacity);
1257 1256
1258 // Consecutive shrinking should not affect space capacity. 1257 // Consecutive shrinking should not affect space capacity.
1259 old_capacity = new_space->Capacity(); 1258 old_capacity = new_space->Capacity();
1260 new_space->Shrink(); 1259 new_space->Shrink();
1261 new_space->Shrink(); 1260 new_space->Shrink();
1262 new_space->Shrink(); 1261 new_space->Shrink();
1263 new_capacity = new_space->Capacity(); 1262 new_capacity = new_space->Capacity();
1264 ASSERT_EQ(old_capacity, new_capacity); 1263 ASSERT_EQ(old_capacity, new_capacity);
1265 } 1264 }
1266
1267
1268 class HeapIteratorTestHelper {
1269 public:
1270 HeapIteratorTestHelper(Object* a, Object* b)
1271 : a_(a), b_(b), a_found_(false), b_found_(false) {}
1272 bool a_found() { return a_found_; }
1273 bool b_found() { return b_found_; }
1274 void IterateHeap() {
1275 HeapIterator iterator;
1276 for (HeapObject* obj = iterator.next();
1277 obj != NULL;
1278 obj = iterator.next()) {
1279 if (obj == a_)
1280 a_found_ = true;
1281 else if (obj == b_)
1282 b_found_ = true;
1283 }
1284 }
1285 private:
1286 Object* a_;
1287 Object* b_;
1288 bool a_found_;
1289 bool b_found_;
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