diff options
Diffstat (limited to 'deps/v8/test/cctest/heap/test-spaces.cc')
-rw-r--r-- | deps/v8/test/cctest/heap/test-spaces.cc | 159 |
1 files changed, 80 insertions, 79 deletions
diff --git a/deps/v8/test/cctest/heap/test-spaces.cc b/deps/v8/test/cctest/heap/test-spaces.cc index 5eb1549e11..2328518f2a 100644 --- a/deps/v8/test/cctest/heap/test-spaces.cc +++ b/deps/v8/test/cctest/heap/test-spaces.cc @@ -32,7 +32,6 @@ #include "src/v8.h" #include "test/cctest/cctest.h" #include "test/cctest/heap/heap-tester.h" -#include "test/cctest/heap/utils-inl.h" namespace v8 { namespace internal { @@ -107,13 +106,12 @@ TEST(Page) { class TestMemoryAllocatorScope { public: TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator) - : isolate_(isolate), - old_allocator_(isolate->memory_allocator_) { - isolate->memory_allocator_ = allocator; + : isolate_(isolate), old_allocator_(isolate->heap()->memory_allocator()) { + isolate->heap()->memory_allocator_ = allocator; } ~TestMemoryAllocatorScope() { - isolate_->memory_allocator_ = old_allocator_; + isolate_->heap()->memory_allocator_ = old_allocator_; } private: @@ -129,12 +127,12 @@ class TestCodeRangeScope { public: TestCodeRangeScope(Isolate* isolate, CodeRange* code_range) : isolate_(isolate), - old_code_range_(isolate->code_range_) { - isolate->code_range_ = code_range; + old_code_range_(isolate->heap()->memory_allocator()->code_range()) { + isolate->heap()->memory_allocator()->code_range_ = code_range; } ~TestCodeRangeScope() { - isolate_->code_range_ = old_code_range_; + isolate_->heap()->memory_allocator()->code_range_ = old_code_range_; } private: @@ -153,50 +151,49 @@ static void VerifyMemoryChunk(Isolate* isolate, size_t second_commit_area_size, Executability executable) { MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); - CHECK(memory_allocator->SetUp(heap->MaxReserved(), - heap->MaxExecutableSize())); - TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); - TestCodeRangeScope test_code_range_scope(isolate, code_range); - - size_t header_size = (executable == EXECUTABLE) - ? MemoryAllocator::CodePageGuardStartOffset() - : MemoryChunk::kObjectStartOffset; - size_t guard_size = (executable == EXECUTABLE) - ? MemoryAllocator::CodePageGuardSize() - : 0; - - MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size, - commit_area_size, - executable, - NULL); - size_t alignment = code_range != NULL && code_range->valid() - ? MemoryChunk::kAlignment - : base::OS::CommitPageSize(); - size_t reserved_size = - ((executable == EXECUTABLE)) - ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, - alignment) - : RoundUp(header_size + reserve_area_size, - base::OS::CommitPageSize()); - CHECK(memory_chunk->size() == reserved_size); - CHECK(memory_chunk->area_start() < memory_chunk->address() + - memory_chunk->size()); - CHECK(memory_chunk->area_end() <= memory_chunk->address() + - memory_chunk->size()); - CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size); - - Address area_start = memory_chunk->area_start(); - - memory_chunk->CommitArea(second_commit_area_size); - CHECK(area_start == memory_chunk->area_start()); - CHECK(memory_chunk->area_start() < memory_chunk->address() + - memory_chunk->size()); - CHECK(memory_chunk->area_end() <= memory_chunk->address() + - memory_chunk->size()); - CHECK(static_cast<size_t>(memory_chunk->area_size()) == - second_commit_area_size); - - memory_allocator->Free(memory_chunk); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); + { + TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); + TestCodeRangeScope test_code_range_scope(isolate, code_range); + + size_t header_size = (executable == EXECUTABLE) + ? MemoryAllocator::CodePageGuardStartOffset() + : MemoryChunk::kObjectStartOffset; + size_t guard_size = + (executable == EXECUTABLE) ? MemoryAllocator::CodePageGuardSize() : 0; + + MemoryChunk* memory_chunk = memory_allocator->AllocateChunk( + reserve_area_size, commit_area_size, executable, NULL); + size_t alignment = code_range != NULL && code_range->valid() + ? MemoryChunk::kAlignment + : base::OS::CommitPageSize(); + size_t reserved_size = + ((executable == EXECUTABLE)) + ? RoundUp(header_size + guard_size + reserve_area_size + guard_size, + alignment) + : RoundUp(header_size + reserve_area_size, + base::OS::CommitPageSize()); + CHECK(memory_chunk->size() == reserved_size); + CHECK(memory_chunk->area_start() < + memory_chunk->address() + memory_chunk->size()); + CHECK(memory_chunk->area_end() <= + memory_chunk->address() + memory_chunk->size()); + CHECK(static_cast<size_t>(memory_chunk->area_size()) == commit_area_size); + + Address area_start = memory_chunk->area_start(); + + memory_chunk->CommitArea(second_commit_area_size); + CHECK(area_start == memory_chunk->area_start()); + CHECK(memory_chunk->area_start() < + memory_chunk->address() + memory_chunk->size()); + CHECK(memory_chunk->area_end() <= + memory_chunk->address() + memory_chunk->size()); + CHECK(static_cast<size_t>(memory_chunk->area_size()) == + second_commit_area_size); + + memory_allocator->Free<MemoryAllocator::kFull>(memory_chunk); + } memory_allocator->TearDown(); delete memory_allocator; } @@ -205,36 +202,32 @@ static void VerifyMemoryChunk(Isolate* isolate, TEST(Regress3540) { Isolate* isolate = CcTest::i_isolate(); Heap* heap = isolate->heap(); - const int pageSize = Page::kPageSize; MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); - CHECK( - memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize())); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator); CodeRange* code_range = new CodeRange(isolate); - const size_t code_range_size = 4 * pageSize; - if (!code_range->SetUp( - code_range_size + - RoundUp(v8::base::OS::CommitPageSize() * kReservedCodeRangePages, - MemoryChunk::kAlignment) + - v8::internal::MemoryAllocator::CodePageAreaSize())) { + size_t code_range_size = + kMinimumCodeRangeSize > 0 ? kMinimumCodeRangeSize : 3 * Page::kPageSize; + if (!code_range->SetUp(code_range_size)) { return; } Address address; size_t size; - size_t request_size = code_range_size - 2 * pageSize; + size_t request_size = code_range_size - Page::kPageSize; address = code_range->AllocateRawMemory( request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()), &size); - CHECK(address != NULL); + CHECK_NOT_NULL(address); Address null_address; size_t null_size; - request_size = code_range_size - pageSize; + request_size = code_range_size - Page::kPageSize; null_address = code_range->AllocateRawMemory( request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()), &null_size); - CHECK(null_address == NULL); + CHECK_NULL(null_address); code_range->FreeRawMemory(address, size); delete code_range; @@ -283,8 +276,8 @@ TEST(MemoryChunk) { NOT_EXECUTABLE); delete code_range; - // Without CodeRange. - code_range = NULL; + // Without a valid CodeRange, i.e., omitting SetUp. + code_range = new CodeRange(isolate); VerifyMemoryChunk(isolate, heap, code_range, @@ -300,6 +293,7 @@ TEST(MemoryChunk) { initial_commit_area_size, second_commit_area_size, NOT_EXECUTABLE); + delete code_range; } } @@ -310,14 +304,14 @@ TEST(MemoryAllocator) { MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); CHECK(memory_allocator != nullptr); - CHECK(memory_allocator->SetUp(heap->MaxReserved(), - heap->MaxExecutableSize())); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); TestMemoryAllocatorScope test_scope(isolate, memory_allocator); { int total_pages = 0; OldSpace faked_space(heap, OLD_SPACE, NOT_EXECUTABLE); - Page* first_page = memory_allocator->AllocatePage<Page>( + Page* first_page = memory_allocator->AllocatePage( faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space), NOT_EXECUTABLE); @@ -331,7 +325,7 @@ TEST(MemoryAllocator) { } // Again, we should get n or n - 1 pages. - Page* other = memory_allocator->AllocatePage<Page>( + Page* other = memory_allocator->AllocatePage( faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space), NOT_EXECUTABLE); CHECK(Page::IsValid(other)); @@ -358,8 +352,8 @@ TEST(NewSpace) { Isolate* isolate = CcTest::i_isolate(); Heap* heap = isolate->heap(); MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); - CHECK(memory_allocator->SetUp(heap->MaxReserved(), - heap->MaxExecutableSize())); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); TestMemoryAllocatorScope test_scope(isolate, memory_allocator); NewSpace new_space(heap); @@ -385,8 +379,8 @@ TEST(OldSpace) { Isolate* isolate = CcTest::i_isolate(); Heap* heap = isolate->heap(); MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); - CHECK(memory_allocator->SetUp(heap->MaxReserved(), - heap->MaxExecutableSize())); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); TestMemoryAllocatorScope test_scope(isolate, memory_allocator); OldSpace* s = new OldSpace(heap, OLD_SPACE, NOT_EXECUTABLE); @@ -409,8 +403,8 @@ TEST(CompactionSpace) { Heap* heap = isolate->heap(); MemoryAllocator* memory_allocator = new MemoryAllocator(isolate); CHECK(memory_allocator != nullptr); - CHECK( - memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize())); + CHECK(memory_allocator->SetUp(heap->MaxReserved(), heap->MaxExecutableSize(), + 0)); TestMemoryAllocatorScope test_scope(isolate, memory_allocator); CompactionSpace* compaction_space = @@ -491,7 +485,15 @@ TEST(SizeOfFirstPageIsLargeEnough) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); if (!isolate->snapshot_available()) return; - if (Snapshot::EmbedsScript(isolate)) return; + HandleScope scope(isolate); + v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); + // Skip this test on the custom snapshot builder. + if (!CcTest::global() + ->Get(context, v8_str("assertEquals")) + .ToLocalChecked() + ->IsUndefined()) { + return; + } // If this test fails due to enabling experimental natives that are not part // of the snapshot, we may need to adjust CalculateFirstPageSizes. @@ -504,7 +506,6 @@ TEST(SizeOfFirstPageIsLargeEnough) { } // Executing the empty script gets by with one page per space. - HandleScope scope(isolate); CompileRun("/*empty*/"); for (int i = FIRST_PAGED_SPACE; i <= LAST_PAGED_SPACE; i++) { // Debug code can be very large, so skip CODE_SPACE if we are generating it. |