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 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 "Iterator: %" V8_PTR_PREFIX "d, " | 1217 "Iterator: %" V8_PTR_PREFIX "d, " |
1218 "delta: %" V8_PTR_PREFIX "d\n", | 1218 "delta: %" V8_PTR_PREFIX "d\n", |
1219 size_of_objects_1, size_of_objects_2, delta); | 1219 size_of_objects_1, size_of_objects_2, delta); |
1220 CHECK_GT(size_of_objects_2 / 20, delta); | 1220 CHECK_GT(size_of_objects_2 / 20, delta); |
1221 } | 1221 } |
1222 } | 1222 } |
1223 | 1223 |
1224 | 1224 |
1225 TEST(GrowAndShrinkNewSpace) { | 1225 TEST(GrowAndShrinkNewSpace) { |
1226 InitializeVM(); | 1226 InitializeVM(); |
1227 v8::HandleScope scope; | |
1228 NewSpace* new_space = HEAP->new_space(); | 1227 NewSpace* new_space = HEAP->new_space(); |
1229 | 1228 |
1230 // Explicitly growing should double the space capacity. | 1229 // Explicitly growing should double the space capacity. |
1231 int old_capacity, new_capacity; | 1230 intptr_t old_capacity, new_capacity; |
1232 old_capacity = new_space->Capacity(); | 1231 old_capacity = new_space->Capacity(); |
1233 new_space->Grow(); | 1232 new_space->Grow(); |
1234 new_capacity = new_space->Capacity(); | 1233 new_capacity = new_space->Capacity(); |
1235 ASSERT_EQ(2 * old_capacity, new_capacity); | 1234 CHECK_EQ(2 * old_capacity, new_capacity); |
1236 | 1235 |
1237 // Fill up new space to the point that it is almost full. | 1236 // Fill up new space to the point that it is completely full. Make sure |
1238 while (new_space->SizeAsInt() + FixedArray::SizeFor(1000) < new_capacity) { | 1237 // that the scavenger does not undo the filling. |
1239 ASSERT(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); | 1238 old_capacity = new_space->Capacity(); |
| 1239 { |
| 1240 v8::HandleScope scope; |
| 1241 AlwaysAllocateScope always_allocate; |
| 1242 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); |
| 1243 intptr_t number_of_fillers = (available / FixedArray::SizeFor(1000)) - 10; |
| 1244 for (intptr_t i = 0; i < number_of_fillers; i++) { |
| 1245 CHECK(HEAP->InNewSpace(*FACTORY->NewFixedArray(1000, NOT_TENURED))); |
| 1246 } |
1240 } | 1247 } |
| 1248 new_capacity = new_space->Capacity(); |
| 1249 CHECK_EQ(old_capacity, new_capacity); |
1241 | 1250 |
1242 // Explicitly shrinking should not affect space capacity. | 1251 // Explicitly shrinking should not affect space capacity. |
1243 old_capacity = new_space->Capacity(); | 1252 old_capacity = new_space->Capacity(); |
1244 new_space->Shrink(); | 1253 new_space->Shrink(); |
1245 new_capacity = new_space->Capacity(); | 1254 new_capacity = new_space->Capacity(); |
1246 ASSERT_EQ(old_capacity, new_capacity); | 1255 CHECK_EQ(old_capacity, new_capacity); |
1247 | 1256 |
1248 // Perform scavenge to empty the new space. | 1257 // Let the scavenger empty the new space. |
1249 HEAP->CollectGarbage(NEW_SPACE); | 1258 HEAP->CollectGarbage(NEW_SPACE); |
1250 ASSERT_LE(new_space->SizeAsInt(), old_capacity); | 1259 CHECK_LE(new_space->Size(), old_capacity); |
1251 | 1260 |
1252 // Explicitly shrinking should halve the space capacity. | 1261 // Explicitly shrinking should halve the space capacity. |
1253 old_capacity = new_space->Capacity(); | 1262 old_capacity = new_space->Capacity(); |
1254 new_space->Shrink(); | 1263 new_space->Shrink(); |
1255 new_capacity = new_space->Capacity(); | 1264 new_capacity = new_space->Capacity(); |
1256 ASSERT_EQ(old_capacity, 2 * new_capacity); | 1265 CHECK_EQ(old_capacity, 2 * new_capacity); |
1257 | 1266 |
1258 // Consecutive shrinking should not affect space capacity. | 1267 // Consecutive shrinking should not affect space capacity. |
1259 old_capacity = new_space->Capacity(); | 1268 old_capacity = new_space->Capacity(); |
1260 new_space->Shrink(); | 1269 new_space->Shrink(); |
1261 new_space->Shrink(); | 1270 new_space->Shrink(); |
1262 new_space->Shrink(); | 1271 new_space->Shrink(); |
1263 new_capacity = new_space->Capacity(); | 1272 new_capacity = new_space->Capacity(); |
1264 ASSERT_EQ(old_capacity, new_capacity); | 1273 CHECK_EQ(old_capacity, new_capacity); |
1265 } | 1274 } |
OLD | NEW |