diff options
Diffstat (limited to 'deps/v8/test/cctest/heap/test-spaces.cc')
-rw-r--r-- | deps/v8/test/cctest/heap/test-spaces.cc | 120 |
1 files changed, 77 insertions, 43 deletions
diff --git a/deps/v8/test/cctest/heap/test-spaces.cc b/deps/v8/test/cctest/heap/test-spaces.cc index e03d8229b3..8219c1487d 100644 --- a/deps/v8/test/cctest/heap/test-spaces.cc +++ b/deps/v8/test/cctest/heap/test-spaces.cc @@ -32,6 +32,7 @@ #include "src/heap/factory.h" #include "src/heap/spaces-inl.h" #include "src/objects-inl.h" +#include "src/objects/free-space.h" #include "src/snapshot/snapshot.h" #include "test/cctest/cctest.h" #include "test/cctest/heap/heap-tester.h" @@ -98,19 +99,19 @@ static void VerifyMemoryChunk(Isolate* isolate, Heap* heap, v8::PageAllocator* page_allocator = memory_allocator->page_allocator(executable); - size_t header_size = (executable == EXECUTABLE) - ? MemoryAllocator::CodePageGuardStartOffset() - : MemoryChunk::kObjectStartOffset; + size_t allocatable_memory_area_offset = + MemoryChunkLayout::ObjectStartOffsetInMemoryChunk(space->identity()); size_t guard_size = - (executable == EXECUTABLE) ? MemoryAllocator::CodePageGuardSize() : 0; + (executable == EXECUTABLE) ? MemoryChunkLayout::CodePageGuardSize() : 0; MemoryChunk* memory_chunk = memory_allocator->AllocateChunk( reserve_area_size, commit_area_size, executable, space); size_t reserved_size = ((executable == EXECUTABLE)) - ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, - page_allocator->CommitPageSize()) - : RoundUp(header_size + reserve_area_size, + ? allocatable_memory_area_offset + + RoundUp(reserve_area_size, page_allocator->CommitPageSize()) + + guard_size + : RoundUp(allocatable_memory_area_offset + reserve_area_size, page_allocator->CommitPageSize()); CHECK(memory_chunk->size() == reserved_size); CHECK(memory_chunk->area_start() < @@ -213,6 +214,44 @@ TEST(MemoryAllocator) { delete memory_allocator; } +TEST(ComputeDiscardMemoryAreas) { + base::AddressRegion memory_area; + size_t page_size = MemoryAllocator::GetCommitPageSize(); + size_t free_header_size = FreeSpace::kSize; + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea(0, 0); + CHECK_EQ(memory_area.begin(), 0); + CHECK_EQ(memory_area.size(), 0); + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea( + 0, page_size + free_header_size); + CHECK_EQ(memory_area.begin(), 0); + CHECK_EQ(memory_area.size(), 0); + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea( + page_size - free_header_size, page_size + free_header_size); + CHECK_EQ(memory_area.begin(), page_size); + CHECK_EQ(memory_area.size(), page_size); + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea(page_size, page_size); + CHECK_EQ(memory_area.begin(), 0); + CHECK_EQ(memory_area.size(), 0); + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea( + page_size / 2, page_size + page_size / 2); + CHECK_EQ(memory_area.begin(), page_size); + CHECK_EQ(memory_area.size(), page_size); + + memory_area = MemoryAllocator::ComputeDiscardMemoryArea( + page_size / 2, page_size + page_size / 4); + CHECK_EQ(memory_area.begin(), 0); + CHECK_EQ(memory_area.size(), 0); + + memory_area = + MemoryAllocator::ComputeDiscardMemoryArea(page_size / 2, page_size * 3); + CHECK_EQ(memory_area.begin(), page_size); + CHECK_EQ(memory_area.size(), page_size * 2); +} TEST(NewSpace) { Isolate* isolate = CcTest::i_isolate(); @@ -269,10 +308,10 @@ TEST(LargeObjectSpace) { int lo_size = Page::kPageSize; - Object* obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE).ToObjectChecked(); + Object obj = lo->AllocateRaw(lo_size).ToObjectChecked(); CHECK(obj->IsHeapObject()); - HeapObject* ho = HeapObject::cast(obj); + HeapObject ho = HeapObject::cast(obj); CHECK(lo->Contains(HeapObject::cast(obj))); @@ -281,18 +320,15 @@ TEST(LargeObjectSpace) { CHECK(lo->Contains(ho)); while (true) { - size_t available = lo->Available(); - { AllocationResult allocation = lo->AllocateRaw(lo_size, NOT_EXECUTABLE); + { + AllocationResult allocation = lo->AllocateRaw(lo_size); if (allocation.IsRetry()) break; } - // The available value is conservative such that it may report - // zero prior to heap exhaustion. - CHECK(lo->Available() < available || available == 0); } CHECK(!lo->IsEmpty()); - CHECK(lo->AllocateRaw(lo_size, NOT_EXECUTABLE).IsRetry()); + CHECK(lo->AllocateRaw(lo_size).IsRetry()); } #ifndef DEBUG @@ -359,30 +395,30 @@ TEST(SizeOfInitialHeap) { } #endif // DEBUG -static HeapObject* AllocateUnaligned(NewSpace* space, int size) { +static HeapObject AllocateUnaligned(NewSpace* space, int size) { AllocationResult allocation = space->AllocateRawUnaligned(size); CHECK(!allocation.IsRetry()); - HeapObject* filler = nullptr; + HeapObject filler; CHECK(allocation.To(&filler)); space->heap()->CreateFillerObjectAt(filler->address(), size, ClearRecordedSlots::kNo); return filler; } -static HeapObject* AllocateUnaligned(PagedSpace* space, int size) { +static HeapObject AllocateUnaligned(PagedSpace* space, int size) { AllocationResult allocation = space->AllocateRaw(size, kDoubleUnaligned); CHECK(!allocation.IsRetry()); - HeapObject* filler = nullptr; + HeapObject filler; CHECK(allocation.To(&filler)); space->heap()->CreateFillerObjectAt(filler->address(), size, ClearRecordedSlots::kNo); return filler; } -static HeapObject* AllocateUnaligned(LargeObjectSpace* space, int size) { - AllocationResult allocation = space->AllocateRaw(size, EXECUTABLE); +static HeapObject AllocateUnaligned(LargeObjectSpace* space, int size) { + AllocationResult allocation = space->AllocateRaw(size); CHECK(!allocation.IsRetry()); - HeapObject* filler = nullptr; + HeapObject filler; CHECK(allocation.To(&filler)); return filler; } @@ -544,7 +580,7 @@ HEAP_TEST(Regress777177) { AlwaysAllocateScope always_allocate(isolate); heap::SimulateFullSpace(old_space); AllocationResult result = old_space->AllocateRaw(filler_size, kWordAligned); - HeapObject* obj = result.ToObjectChecked(); + HeapObject obj = result.ToObjectChecked(); heap->CreateFillerObjectAt(obj->address(), filler_size, ClearRecordedSlots::kNo); } @@ -554,7 +590,7 @@ HEAP_TEST(Regress777177) { // top_on_previous_step_ to the next page. AllocationResult result = old_space->AllocateRaw(max_object_size, kWordAligned); - HeapObject* obj = result.ToObjectChecked(); + HeapObject obj = result.ToObjectChecked(); // Simulate allocation folding moving the top pointer back. old_space->SetTopAndLimit(obj->address(), old_space->limit()); } @@ -562,7 +598,7 @@ HEAP_TEST(Regress777177) { { // This triggers assert in crbug.com/777177. AllocationResult result = old_space->AllocateRaw(filler_size, kWordAligned); - HeapObject* obj = result.ToObjectChecked(); + HeapObject obj = result.ToObjectChecked(); heap->CreateFillerObjectAt(obj->address(), filler_size, ClearRecordedSlots::kNo); } @@ -581,7 +617,7 @@ HEAP_TEST(Regress791582) { int until_page_end = static_cast<int>(new_space->limit() - new_space->top()); - if (until_page_end % kPointerSize != 0) { + if (!IsAligned(until_page_end, kTaggedSize)) { // The test works if the size of allocation area size is a multiple of // pointer size. This is usually the case unless some allocation observer // is already active (e.g. incremental marking observer). @@ -594,7 +630,7 @@ HEAP_TEST(Regress791582) { { AllocationResult result = new_space->AllocateRaw(until_page_end, kWordAligned); - HeapObject* obj = result.ToObjectChecked(); + HeapObject obj = result.ToObjectChecked(); heap->CreateFillerObjectAt(obj->address(), until_page_end, ClearRecordedSlots::kNo); // Simulate allocation folding moving the top pointer back. @@ -604,7 +640,7 @@ HEAP_TEST(Regress791582) { { // This triggers assert in crbug.com/791582 AllocationResult result = new_space->AllocateRaw(256, kWordAligned); - HeapObject* obj = result.ToObjectChecked(); + HeapObject obj = result.ToObjectChecked(); heap->CreateFillerObjectAt(obj->address(), 256, ClearRecordedSlots::kNo); } new_space->RemoveAllocationObserver(&observer); @@ -621,20 +657,20 @@ TEST(ShrinkPageToHighWaterMarkFreeSpaceEnd) { // Prepare page that only contains a single object and a trailing FreeSpace // filler. Handle<FixedArray> array = isolate->factory()->NewFixedArray(128, TENURED); - Page* page = Page::FromAddress(array->address()); + Page* page = Page::FromHeapObject(*array); // Reset space so high water mark is consistent. PagedSpace* old_space = CcTest::heap()->old_space(); old_space->FreeLinearAllocationArea(); old_space->ResetFreeList(); - HeapObject* filler = - HeapObject::FromAddress(array->address() + array->Size()); + HeapObject filler = HeapObject::FromAddress(array->address() + array->Size()); CHECK(filler->IsFreeSpace()); size_t shrunk = old_space->ShrinkPageToHighWaterMark(page); - size_t should_have_shrunk = - RoundDown(static_cast<size_t>(Page::kAllocatableMemory - array->Size()), - CommitPageSize()); + size_t should_have_shrunk = RoundDown( + static_cast<size_t>(MemoryChunkLayout::AllocatableMemoryInDataPage() - + array->Size()), + CommitPageSize()); CHECK_EQ(should_have_shrunk, shrunk); } @@ -648,7 +684,7 @@ TEST(ShrinkPageToHighWaterMarkNoFiller) { std::vector<Handle<FixedArray>> arrays = heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize); Handle<FixedArray> array = arrays.back(); - Page* page = Page::FromAddress(array->address()); + Page* page = Page::FromHeapObject(*array); CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize); // Reset space so high water mark and fillers are consistent. @@ -667,11 +703,11 @@ TEST(ShrinkPageToHighWaterMarkOneWordFiller) { heap::SealCurrentObjects(CcTest::heap()); - const int kFillerSize = kPointerSize; + const int kFillerSize = kTaggedSize; std::vector<Handle<FixedArray>> arrays = heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize); Handle<FixedArray> array = arrays.back(); - Page* page = Page::FromAddress(array->address()); + Page* page = Page::FromHeapObject(*array); CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize); // Reset space so high water mark and fillers are consistent. @@ -679,8 +715,7 @@ TEST(ShrinkPageToHighWaterMarkOneWordFiller) { old_space->FreeLinearAllocationArea(); old_space->ResetFreeList(); - HeapObject* filler = - HeapObject::FromAddress(array->address() + array->Size()); + HeapObject filler = HeapObject::FromAddress(array->address() + array->Size()); CHECK_EQ(filler->map(), ReadOnlyRoots(CcTest::heap()).one_pointer_filler_map()); @@ -695,11 +730,11 @@ TEST(ShrinkPageToHighWaterMarkTwoWordFiller) { heap::SealCurrentObjects(CcTest::heap()); - const int kFillerSize = 2 * kPointerSize; + const int kFillerSize = 2 * kTaggedSize; std::vector<Handle<FixedArray>> arrays = heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize); Handle<FixedArray> array = arrays.back(); - Page* page = Page::FromAddress(array->address()); + Page* page = Page::FromHeapObject(*array); CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize); // Reset space so high water mark and fillers are consistent. @@ -707,8 +742,7 @@ TEST(ShrinkPageToHighWaterMarkTwoWordFiller) { old_space->FreeLinearAllocationArea(); old_space->ResetFreeList(); - HeapObject* filler = - HeapObject::FromAddress(array->address() + array->Size()); + HeapObject filler = HeapObject::FromAddress(array->address() + array->Size()); CHECK_EQ(filler->map(), ReadOnlyRoots(CcTest::heap()).two_pointer_filler_map()); |