OLD | NEW |
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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 | 1224 |
1225 TEST(GrowAndShrinkNewSpace) { | 1225 TEST(GrowAndShrinkNewSpace) { |
1226 InitializeVM(); | 1226 InitializeVM(); |
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 intptr_t old_capacity, new_capacity; | 1230 intptr_t 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 CHECK_EQ(2 * old_capacity, new_capacity); | 1234 CHECK(2 * old_capacity == new_capacity); |
1235 | 1235 |
1236 // Fill up new space to the point that it is completely full. Make sure | 1236 // Fill up new space to the point that it is completely full. Make sure |
1237 // that the scavenger does not undo the filling. | 1237 // that the scavenger does not undo the filling. |
1238 old_capacity = new_space->Capacity(); | 1238 old_capacity = new_space->Capacity(); |
1239 { | 1239 { |
1240 v8::HandleScope scope; | 1240 v8::HandleScope scope; |
1241 AlwaysAllocateScope always_allocate; | 1241 AlwaysAllocateScope always_allocate; |
1242 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); | 1242 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); |
1243 intptr_t number_of_fillers = (available / FixedArray::SizeFor(1000)) - 10; | 1243 intptr_t number_of_fillers = (available / FixedArray::SizeFor(1000)) - 10; |
1244 for (intptr_t i = 0; i < number_of_fillers; i++) { | 1244 for (intptr_t i = 0; i < number_of_fillers; i++) { |
1245 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); | 1245 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); |
1246 } | 1246 } |
1247 } | 1247 } |
1248 new_capacity = new_space->Capacity(); | 1248 new_capacity = new_space->Capacity(); |
1249 CHECK_EQ(old_capacity, new_capacity); | 1249 CHECK(old_capacity == new_capacity); |
1250 | 1250 |
1251 // Explicitly shrinking should not affect space capacity. | 1251 // Explicitly shrinking should not affect space capacity. |
1252 old_capacity = new_space->Capacity(); | 1252 old_capacity = new_space->Capacity(); |
1253 new_space->Shrink(); | 1253 new_space->Shrink(); |
1254 new_capacity = new_space->Capacity(); | 1254 new_capacity = new_space->Capacity(); |
1255 CHECK_EQ(old_capacity, new_capacity); | 1255 CHECK(old_capacity == new_capacity); |
1256 | 1256 |
1257 // Let the scavenger empty the new space. | 1257 // Let the scavenger empty the new space. |
1258 HEAP->CollectGarbage(NEW_SPACE); | 1258 HEAP->CollectGarbage(NEW_SPACE); |
1259 CHECK_LE(new_space->Size(), old_capacity); | 1259 CHECK_LE(new_space->Size(), old_capacity); |
1260 | 1260 |
1261 // Explicitly shrinking should halve the space capacity. | 1261 // Explicitly shrinking should halve the space capacity. |
1262 old_capacity = new_space->Capacity(); | 1262 old_capacity = new_space->Capacity(); |
1263 new_space->Shrink(); | 1263 new_space->Shrink(); |
1264 new_capacity = new_space->Capacity(); | 1264 new_capacity = new_space->Capacity(); |
1265 CHECK_EQ(old_capacity, 2 * new_capacity); | 1265 CHECK(old_capacity == 2 * new_capacity); |
1266 | 1266 |
1267 // Consecutive shrinking should not affect space capacity. | 1267 // Consecutive shrinking should not affect space capacity. |
1268 old_capacity = new_space->Capacity(); | 1268 old_capacity = new_space->Capacity(); |
1269 new_space->Shrink(); | 1269 new_space->Shrink(); |
1270 new_space->Shrink(); | 1270 new_space->Shrink(); |
1271 new_space->Shrink(); | 1271 new_space->Shrink(); |
1272 new_capacity = new_space->Capacity(); | 1272 new_capacity = new_space->Capacity(); |
1273 CHECK_EQ(old_capacity, new_capacity); | 1273 CHECK(old_capacity == new_capacity); |
1274 } | 1274 } |
OLD | NEW |