Chromium Code Reviews| Index: test/cctest/test-heap.cc |
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc |
| index 179ca1c63cd1f2add33dfeeaf10fe8081cc89e80..410e52b118b926714557cdfed711a6538e91ffd6 100644 |
| --- a/test/cctest/test-heap.cc |
| +++ b/test/cctest/test-heap.cc |
| @@ -1899,3 +1899,42 @@ TEST(Regress2143b) { |
| CHECK(root->IsJSObject()); |
| CHECK(root->map()->IsMap()); |
| } |
| + |
| + |
| +// Implemented in the test-alloc.cc test suite. |
| +void SimulateFullSpace(PagedSpace* space); |
| + |
| + |
| +TEST(ReleaseOverReservedPages) { |
| + i::FLAG_trace_gc = true; |
| + InitializeVM(); |
| + v8::HandleScope scope; |
| + static const int number_of_test_pages = 20; |
| + |
| + // Prepare many pages with low live-bytes count. |
| + PagedSpace* old_pointer_space = HEAP->old_pointer_space(); |
| + CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
| + for (int i = 0; i < number_of_test_pages; i++) { |
| + AlwaysAllocateScope always_allocate; |
| + SimulateFullSpace(old_pointer_space); |
| + FACTORY->NewFixedArray(1, TENURED); |
| + } |
| + CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); |
| + |
| + // Triggering one GC will cause a lot of garbage to be discovered but |
| + // even spread across all allocated pages. |
| + HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); |
| + CHECK_EQ(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); |
| + |
| + // Triggering subsequent GCs should cause at least halve of the pages |
|
Erik Corry
2012/06/22 08:52:54
halve -> half
Michael Starzinger
2012/06/22 09:14:23
Done.
|
| + // to be released to the OS after at most two cycles. |
| + HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 1"); |
| + CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages()); |
| + HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered by test 2"); |
| + CHECK_GE(number_of_test_pages + 1, old_pointer_space->CountTotalPages() * 2); |
| + |
| + // Triggering a last-resort GC should cause all pages to be released |
| + // to the OS so that other processes can seize the memory. |
| + HEAP->CollectAllAvailableGarbage("triggered really hard"); |
| + CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
| +} |