| Index: test/cctest/test-heap.cc
|
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
|
| index 72079dc2ae8180ccd29cdb385485436296892967..54d56b9d7f85e2d174b67b594642041894674833 100644
|
| --- a/test/cctest/test-heap.cc
|
| +++ b/test/cctest/test-heap.cc
|
| @@ -1735,3 +1735,42 @@ TEST(OptimizedAllocationAlwaysInNewSpace) {
|
|
|
| CHECK(HEAP->InNewSpace(*o));
|
| }
|
| +
|
| +
|
| +// 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 half of the pages
|
| + // 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());
|
| +}
|
|
|