OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 PrintF("Heap::SizeOfObjects: %" V8PRIdPTR | 2349 PrintF("Heap::SizeOfObjects: %" V8PRIdPTR |
2350 ", " | 2350 ", " |
2351 "Iterator: %" V8PRIdPTR | 2351 "Iterator: %" V8PRIdPTR |
2352 ", " | 2352 ", " |
2353 "delta: %" V8PRIdPTR "\n", | 2353 "delta: %" V8PRIdPTR "\n", |
2354 size_of_objects_1, size_of_objects_2, delta); | 2354 size_of_objects_1, size_of_objects_2, delta); |
2355 CHECK_GT(size_of_objects_2 / 20, delta); | 2355 CHECK_GT(size_of_objects_2 / 20, delta); |
2356 } | 2356 } |
2357 } | 2357 } |
2358 | 2358 |
2359 | |
2360 static void FillUpNewSpace(NewSpace* new_space) { | |
2361 // Fill up new space to the point that it is completely full. Make sure | |
2362 // that the scavenger does not undo the filling. | |
2363 Heap* heap = new_space->heap(); | |
2364 Isolate* isolate = heap->isolate(); | |
2365 Factory* factory = isolate->factory(); | |
2366 HandleScope scope(isolate); | |
2367 AlwaysAllocateScope always_allocate(isolate); | |
2368 intptr_t available = new_space->Capacity() - new_space->Size(); | |
2369 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; | |
2370 for (intptr_t i = 0; i < number_of_fillers; i++) { | |
2371 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED))); | |
2372 } | |
2373 } | |
2374 | |
2375 | |
2376 TEST(GrowAndShrinkNewSpace) { | 2359 TEST(GrowAndShrinkNewSpace) { |
2377 // Avoid shrinking new space in GC epilogue. This can happen if allocation | 2360 // Avoid shrinking new space in GC epilogue. This can happen if allocation |
2378 // throughput samples have been taken while executing the benchmark. | 2361 // throughput samples have been taken while executing the benchmark. |
2379 FLAG_predictable = true; | 2362 FLAG_predictable = true; |
2380 | 2363 |
2381 CcTest::InitializeVM(); | 2364 CcTest::InitializeVM(); |
2382 Heap* heap = CcTest::heap(); | 2365 Heap* heap = CcTest::heap(); |
2383 NewSpace* new_space = heap->new_space(); | 2366 NewSpace* new_space = heap->new_space(); |
2384 | 2367 |
2385 if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { | 2368 if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { |
2386 return; | 2369 return; |
2387 } | 2370 } |
2388 | 2371 |
2389 // Explicitly growing should double the space capacity. | 2372 // Explicitly growing should double the space capacity. |
2390 intptr_t old_capacity, new_capacity; | 2373 intptr_t old_capacity, new_capacity; |
2391 old_capacity = new_space->TotalCapacity(); | 2374 old_capacity = new_space->TotalCapacity(); |
2392 new_space->Grow(); | 2375 new_space->Grow(); |
2393 new_capacity = new_space->TotalCapacity(); | 2376 new_capacity = new_space->TotalCapacity(); |
2394 CHECK(2 * old_capacity == new_capacity); | 2377 CHECK_EQ(2 * old_capacity, new_capacity); |
2395 | 2378 |
2396 old_capacity = new_space->TotalCapacity(); | 2379 old_capacity = new_space->TotalCapacity(); |
2397 FillUpNewSpace(new_space); | 2380 { |
| 2381 v8::HandleScope temporary_scope(CcTest::isolate()); |
| 2382 heap::SimulateFullSpace(new_space); |
| 2383 } |
2398 new_capacity = new_space->TotalCapacity(); | 2384 new_capacity = new_space->TotalCapacity(); |
2399 CHECK(old_capacity == new_capacity); | 2385 CHECK_EQ(old_capacity, new_capacity); |
2400 | 2386 |
2401 // Explicitly shrinking should not affect space capacity. | 2387 // Explicitly shrinking should not affect space capacity. |
2402 old_capacity = new_space->TotalCapacity(); | 2388 old_capacity = new_space->TotalCapacity(); |
2403 new_space->Shrink(); | 2389 new_space->Shrink(); |
2404 new_capacity = new_space->TotalCapacity(); | 2390 new_capacity = new_space->TotalCapacity(); |
2405 CHECK(old_capacity == new_capacity); | 2391 CHECK_EQ(old_capacity, new_capacity); |
2406 | 2392 |
2407 // Let the scavenger empty the new space. | 2393 // Let the scavenger empty the new space. |
2408 CcTest::CollectGarbage(NEW_SPACE); | 2394 CcTest::CollectGarbage(NEW_SPACE); |
2409 CHECK_LE(new_space->Size(), old_capacity); | 2395 CHECK_LE(new_space->Size(), old_capacity); |
2410 | 2396 |
2411 // Explicitly shrinking should halve the space capacity. | 2397 // Explicitly shrinking should halve the space capacity. |
2412 old_capacity = new_space->TotalCapacity(); | 2398 old_capacity = new_space->TotalCapacity(); |
2413 new_space->Shrink(); | 2399 new_space->Shrink(); |
2414 new_capacity = new_space->TotalCapacity(); | 2400 new_capacity = new_space->TotalCapacity(); |
2415 CHECK(old_capacity == 2 * new_capacity); | 2401 CHECK_EQ(old_capacity, 2 * new_capacity); |
2416 | 2402 |
2417 // Consecutive shrinking should not affect space capacity. | 2403 // Consecutive shrinking should not affect space capacity. |
2418 old_capacity = new_space->TotalCapacity(); | 2404 old_capacity = new_space->TotalCapacity(); |
2419 new_space->Shrink(); | 2405 new_space->Shrink(); |
2420 new_space->Shrink(); | 2406 new_space->Shrink(); |
2421 new_space->Shrink(); | 2407 new_space->Shrink(); |
2422 new_capacity = new_space->TotalCapacity(); | 2408 new_capacity = new_space->TotalCapacity(); |
2423 CHECK(old_capacity == new_capacity); | 2409 CHECK_EQ(old_capacity, new_capacity); |
2424 } | 2410 } |
2425 | 2411 |
2426 | |
2427 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { | 2412 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { |
2428 CcTest::InitializeVM(); | 2413 CcTest::InitializeVM(); |
2429 Heap* heap = CcTest::heap(); | 2414 Heap* heap = CcTest::heap(); |
2430 if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { | 2415 if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { |
2431 return; | 2416 return; |
2432 } | 2417 } |
2433 | 2418 |
2434 v8::HandleScope scope(CcTest::isolate()); | 2419 v8::HandleScope scope(CcTest::isolate()); |
2435 NewSpace* new_space = heap->new_space(); | 2420 NewSpace* new_space = heap->new_space(); |
2436 intptr_t old_capacity, new_capacity; | 2421 intptr_t old_capacity, new_capacity; |
2437 old_capacity = new_space->TotalCapacity(); | 2422 old_capacity = new_space->TotalCapacity(); |
2438 new_space->Grow(); | 2423 new_space->Grow(); |
2439 new_capacity = new_space->TotalCapacity(); | 2424 new_capacity = new_space->TotalCapacity(); |
2440 CHECK(2 * old_capacity == new_capacity); | 2425 CHECK_EQ(2 * old_capacity, new_capacity); |
2441 FillUpNewSpace(new_space); | 2426 { |
| 2427 v8::HandleScope temporary_scope(CcTest::isolate()); |
| 2428 heap::SimulateFullSpace(new_space); |
| 2429 } |
2442 CcTest::CollectAllAvailableGarbage(); | 2430 CcTest::CollectAllAvailableGarbage(); |
2443 new_capacity = new_space->TotalCapacity(); | 2431 new_capacity = new_space->TotalCapacity(); |
2444 CHECK(old_capacity == new_capacity); | 2432 CHECK_EQ(old_capacity, new_capacity); |
2445 } | 2433 } |
2446 | 2434 |
2447 | |
2448 static int NumberOfGlobalObjects() { | 2435 static int NumberOfGlobalObjects() { |
2449 int count = 0; | 2436 int count = 0; |
2450 HeapIterator iterator(CcTest::heap()); | 2437 HeapIterator iterator(CcTest::heap()); |
2451 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2438 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2452 if (obj->IsJSGlobalObject()) count++; | 2439 if (obj->IsJSGlobalObject()) count++; |
2453 } | 2440 } |
2454 return count; | 2441 return count; |
2455 } | 2442 } |
2456 | 2443 |
2457 | 2444 |
(...skipping 4660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7118 chunk, chunk->area_end() - kPointerSize, chunk->area_end()); | 7105 chunk, chunk->area_end() - kPointerSize, chunk->area_end()); |
7119 slots[chunk->area_end() - kPointerSize] = false; | 7106 slots[chunk->area_end() - kPointerSize] = false; |
7120 RememberedSet<OLD_TO_NEW>::Iterate(chunk, [&slots](Address addr) { | 7107 RememberedSet<OLD_TO_NEW>::Iterate(chunk, [&slots](Address addr) { |
7121 CHECK(slots[addr]); | 7108 CHECK(slots[addr]); |
7122 return KEEP_SLOT; | 7109 return KEEP_SLOT; |
7123 }); | 7110 }); |
7124 } | 7111 } |
7125 | 7112 |
7126 } // namespace internal | 7113 } // namespace internal |
7127 } // namespace v8 | 7114 } // namespace v8 |
OLD | NEW |