diff options
Diffstat (limited to 'deps/v8/test/cctest/heap/test-spaces.cc')
-rw-r--r-- | deps/v8/test/cctest/heap/test-spaces.cc | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/deps/v8/test/cctest/heap/test-spaces.cc b/deps/v8/test/cctest/heap/test-spaces.cc index b930361eb9..e03d8229b3 100644 --- a/deps/v8/test/cctest/heap/test-spaces.cc +++ b/deps/v8/test/cctest/heap/test-spaces.cc @@ -27,6 +27,7 @@ #include <stdlib.h> +#include "src/base/bounded-page-allocator.h" #include "src/base/platform/platform.h" #include "src/heap/factory.h" #include "src/heap/spaces-inl.h" @@ -59,36 +60,43 @@ class TestMemoryAllocatorScope { DISALLOW_COPY_AND_ASSIGN(TestMemoryAllocatorScope); }; - -// Temporarily sets a given code range in an isolate. -class TestCodeRangeScope { +// Temporarily sets a given code page allocator in an isolate. +class TestCodePageAllocatorScope { public: - TestCodeRangeScope(Isolate* isolate, CodeRange* code_range) + TestCodePageAllocatorScope(Isolate* isolate, + v8::PageAllocator* code_page_allocator) : isolate_(isolate), - old_code_range_(isolate->heap()->memory_allocator()->code_range()) { - isolate->heap()->memory_allocator()->code_range_ = code_range; + old_code_page_allocator_( + isolate->heap()->memory_allocator()->code_page_allocator()) { + isolate->heap()->memory_allocator()->code_page_allocator_ = + code_page_allocator; } - ~TestCodeRangeScope() { - isolate_->heap()->memory_allocator()->code_range_ = old_code_range_; + ~TestCodePageAllocatorScope() { + isolate_->heap()->memory_allocator()->code_page_allocator_ = + old_code_page_allocator_; } private: Isolate* isolate_; - CodeRange* old_code_range_; + v8::PageAllocator* old_code_page_allocator_; - DISALLOW_COPY_AND_ASSIGN(TestCodeRangeScope); + DISALLOW_COPY_AND_ASSIGN(TestCodePageAllocatorScope); }; static void VerifyMemoryChunk(Isolate* isolate, Heap* heap, - CodeRange* code_range, size_t reserve_area_size, - size_t commit_area_size, Executability executable, - Space* space) { + v8::PageAllocator* code_page_allocator, + size_t reserve_area_size, size_t commit_area_size, + Executability executable, Space* space) { MemoryAllocator* memory_allocator = new MemoryAllocator(isolate, heap->MaxReserved(), 0); { TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); - TestCodeRangeScope test_code_range_scope(isolate, code_range); + TestCodePageAllocatorScope test_code_page_allocator_scope( + isolate, code_page_allocator); + + v8::PageAllocator* page_allocator = + memory_allocator->page_allocator(executable); size_t header_size = (executable == EXECUTABLE) ? MemoryAllocator::CodePageGuardStartOffset() @@ -98,14 +106,12 @@ static void VerifyMemoryChunk(Isolate* isolate, Heap* heap, MemoryChunk* memory_chunk = memory_allocator->AllocateChunk( reserve_area_size, commit_area_size, executable, space); - size_t alignment = code_range != nullptr && code_range->valid() - ? MemoryChunk::kAlignment - : CommitPageSize(); size_t reserved_size = ((executable == EXECUTABLE)) ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, - alignment) - : RoundUp(header_size + reserve_area_size, CommitPageSize()); + page_allocator->CommitPageSize()) + : RoundUp(header_size + reserve_area_size, + page_allocator->CommitPageSize()); CHECK(memory_chunk->size() == reserved_size); CHECK(memory_chunk->area_start() < memory_chunk->address() + memory_chunk->size()); @@ -119,38 +125,6 @@ static void VerifyMemoryChunk(Isolate* isolate, Heap* heap, delete memory_allocator; } -TEST(Regress3540) { - Isolate* isolate = CcTest::i_isolate(); - Heap* heap = isolate->heap(); - MemoryAllocator* memory_allocator = - new MemoryAllocator(isolate, heap->MaxReserved(), 0); - TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); - size_t code_range_size = - kMinimumCodeRangeSize > 0 ? kMinimumCodeRangeSize : 3 * Page::kPageSize; - CodeRange* code_range = new CodeRange(isolate, code_range_size); - - Address address; - size_t size; - size_t request_size = code_range_size - Page::kPageSize; - address = code_range->AllocateRawMemory( - request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()), - &size); - CHECK_NE(address, kNullAddress); - - Address null_address; - size_t null_size; - request_size = code_range_size - Page::kPageSize; - null_address = code_range->AllocateRawMemory( - request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()), - &null_size); - CHECK_EQ(null_address, kNullAddress); - - code_range->FreeRawMemory(address, size); - delete code_range; - memory_allocator->TearDown(); - delete memory_allocator; -} - static unsigned int PseudorandomAreaSize() { static uint32_t lo = 2345; lo = 18273 * (lo & 0xFFFFF) + (lo >> 16); @@ -162,24 +136,31 @@ TEST(MemoryChunk) { Isolate* isolate = CcTest::i_isolate(); Heap* heap = isolate->heap(); + v8::PageAllocator* page_allocator = GetPlatformPageAllocator(); + size_t reserve_area_size = 1 * MB; size_t initial_commit_area_size; for (int i = 0; i < 100; i++) { initial_commit_area_size = - RoundUp(PseudorandomAreaSize(), CommitPageSize()); + RoundUp(PseudorandomAreaSize(), page_allocator->CommitPageSize()); // With CodeRange. const size_t code_range_size = 32 * MB; - CodeRange* code_range = new CodeRange(isolate, code_range_size); + VirtualMemory code_range_reservation(page_allocator, code_range_size, + nullptr, MemoryChunk::kAlignment); + CHECK(code_range_reservation.IsReserved()); + + base::BoundedPageAllocator code_page_allocator( + page_allocator, code_range_reservation.address(), + code_range_reservation.size(), MemoryChunk::kAlignment); - VerifyMemoryChunk(isolate, heap, code_range, reserve_area_size, + VerifyMemoryChunk(isolate, heap, &code_page_allocator, reserve_area_size, initial_commit_area_size, EXECUTABLE, heap->code_space()); - VerifyMemoryChunk(isolate, heap, code_range, reserve_area_size, + VerifyMemoryChunk(isolate, heap, &code_page_allocator, reserve_area_size, initial_commit_area_size, NOT_EXECUTABLE, heap->old_space()); - delete code_range; } } @@ -240,7 +221,8 @@ TEST(NewSpace) { new MemoryAllocator(isolate, heap->MaxReserved(), 0); TestMemoryAllocatorScope test_scope(isolate, memory_allocator); - NewSpace new_space(heap, CcTest::heap()->InitialSemiSpaceSize(), + NewSpace new_space(heap, memory_allocator->data_page_allocator(), + CcTest::heap()->InitialSemiSpaceSize(), CcTest::heap()->InitialSemiSpaceSize()); CHECK(new_space.MaximumCapacity()); @@ -522,9 +504,7 @@ UNINITIALIZED_TEST(InlineAllocationObserverCadence) { // Clear out any pre-existing garbage to make the test consistent // across snapshot/no-snapshot builds. - i_isolate->heap()->CollectAllGarbage( - i::Heap::kFinalizeIncrementalMarkingMask, - i::GarbageCollectionReason::kTesting); + CcTest::CollectAllGarbage(i_isolate); NewSpace* new_space = i_isolate->heap()->new_space(); |