2011-09-19 18:36:47 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2008-08-22 13:33:59 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-07-01 11:54:57 +00:00
|
|
|
#include "src/snapshot.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-07-01 11:54:57 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
using namespace v8::internal;
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
#if 0
|
2010-05-27 12:30:45 +00:00
|
|
|
static void VerifyRegionMarking(Address page_start) {
|
2011-09-19 18:36:47 +00:00
|
|
|
#ifdef ENABLE_CARDMARKING_WRITE_BARRIER
|
2008-08-22 13:33:59 +00:00
|
|
|
Page* p = Page::FromAddress(page_start);
|
|
|
|
|
2010-05-27 12:30:45 +00:00
|
|
|
p->SetRegionMarks(Page::kAllRegionsCleanMarks);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
for (Address addr = p->ObjectAreaStart();
|
|
|
|
addr < p->ObjectAreaEnd();
|
|
|
|
addr += kPointerSize) {
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK(!Page::FromAddress(addr)->IsRegionDirty(addr));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (Address addr = p->ObjectAreaStart();
|
|
|
|
addr < p->ObjectAreaEnd();
|
|
|
|
addr += kPointerSize) {
|
2010-05-27 12:30:45 +00:00
|
|
|
Page::FromAddress(addr)->MarkRegionDirty(addr);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (Address addr = p->ObjectAreaStart();
|
|
|
|
addr < p->ObjectAreaEnd();
|
|
|
|
addr += kPointerSize) {
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK(Page::FromAddress(addr)->IsRegionDirty(addr));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
#endif
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
#endif
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// TODO(gc) you can no longer allocate pages like this. Details are hidden.
|
|
|
|
#if 0
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(Page) {
|
|
|
|
byte* mem = NewArray<byte>(2*Page::kPageSize);
|
|
|
|
CHECK(mem != NULL);
|
|
|
|
|
|
|
|
Address start = reinterpret_cast<Address>(mem);
|
|
|
|
Address page_start = RoundUp(start, Page::kPageSize);
|
|
|
|
|
|
|
|
Page* p = Page::FromAddress(page_start);
|
2011-03-18 20:35:07 +00:00
|
|
|
// Initialized Page has heap pointer, normally set by memory_allocator.
|
2013-09-19 09:46:15 +00:00
|
|
|
p->heap_ = CcTest::heap();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(p->address() == page_start);
|
|
|
|
CHECK(p->is_valid());
|
|
|
|
|
|
|
|
p->opaque_header = 0;
|
2010-04-22 14:42:21 +00:00
|
|
|
p->SetIsLargeObjectPage(false);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(!p->next_page()->is_valid());
|
|
|
|
|
|
|
|
CHECK(p->ObjectAreaStart() == page_start + Page::kObjectStartOffset);
|
|
|
|
CHECK(p->ObjectAreaEnd() == page_start + Page::kPageSize);
|
|
|
|
|
|
|
|
CHECK(p->Offset(page_start + Page::kObjectStartOffset) ==
|
|
|
|
Page::kObjectStartOffset);
|
|
|
|
CHECK(p->Offset(page_start + Page::kPageSize) == Page::kPageSize);
|
|
|
|
|
|
|
|
CHECK(p->OffsetToAddress(Page::kObjectStartOffset) == p->ObjectAreaStart());
|
|
|
|
CHECK(p->OffsetToAddress(Page::kPageSize) == p->ObjectAreaEnd());
|
|
|
|
|
2010-05-27 12:30:45 +00:00
|
|
|
// test region marking
|
|
|
|
VerifyRegionMarking(page_start);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
DeleteArray(mem);
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
#endif
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// Temporarily sets a given allocator in an isolate.
|
|
|
|
class TestMemoryAllocatorScope {
|
|
|
|
public:
|
|
|
|
TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator)
|
|
|
|
: isolate_(isolate),
|
|
|
|
old_allocator_(isolate->memory_allocator_) {
|
|
|
|
isolate->memory_allocator_ = allocator;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestMemoryAllocatorScope() {
|
|
|
|
isolate_->memory_allocator_ = old_allocator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
MemoryAllocator* old_allocator_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestMemoryAllocatorScope);
|
|
|
|
};
|
|
|
|
|
2013-01-29 09:09:55 +00:00
|
|
|
|
|
|
|
// Temporarily sets a given code range in an isolate.
|
|
|
|
class TestCodeRangeScope {
|
|
|
|
public:
|
|
|
|
TestCodeRangeScope(Isolate* isolate, CodeRange* code_range)
|
|
|
|
: isolate_(isolate),
|
|
|
|
old_code_range_(isolate->code_range_) {
|
|
|
|
isolate->code_range_ = code_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestCodeRangeScope() {
|
|
|
|
isolate_->code_range_ = old_code_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
CodeRange* old_code_range_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestCodeRangeScope);
|
|
|
|
};
|
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
|
2013-01-29 09:09:55 +00:00
|
|
|
static void VerifyMemoryChunk(Isolate* isolate,
|
|
|
|
Heap* heap,
|
|
|
|
CodeRange* code_range,
|
|
|
|
size_t reserve_area_size,
|
|
|
|
size_t commit_area_size,
|
|
|
|
size_t second_commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
Executability executable) {
|
2013-01-29 09:09:55 +00:00
|
|
|
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);
|
|
|
|
|
2013-09-11 18:30:01 +00:00
|
|
|
size_t header_size = (executable == EXECUTABLE)
|
2013-01-29 09:09:55 +00:00
|
|
|
? MemoryAllocator::CodePageGuardStartOffset()
|
|
|
|
: MemoryChunk::kObjectStartOffset;
|
2013-09-11 18:30:01 +00:00
|
|
|
size_t guard_size = (executable == EXECUTABLE)
|
2013-01-29 09:09:55 +00:00
|
|
|
? MemoryAllocator::CodePageGuardSize()
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
MemoryChunk* memory_chunk = memory_allocator->AllocateChunk(reserve_area_size,
|
|
|
|
commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
executable,
|
2013-01-29 09:09:55 +00:00
|
|
|
NULL);
|
2014-06-12 12:01:01 +00:00
|
|
|
size_t alignment = code_range != NULL && code_range->valid() ?
|
2014-06-30 13:25:46 +00:00
|
|
|
MemoryChunk::kAlignment : v8::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,
|
|
|
|
v8::base::OS::CommitPageSize());
|
2013-01-29 09:09:55 +00:00
|
|
|
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);
|
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned int Pseudorandom() {
|
|
|
|
static uint32_t lo = 2345;
|
|
|
|
lo = 18273 * (lo & 0xFFFFF) + (lo >> 16);
|
|
|
|
return lo & 0xFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MemoryChunk) {
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-01-29 09:09:55 +00:00
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
CHECK(heap->ConfigureHeapDefault());
|
|
|
|
|
|
|
|
size_t reserve_area_size = 1 * MB;
|
|
|
|
size_t initial_commit_area_size, second_commit_area_size;
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
initial_commit_area_size = Pseudorandom();
|
|
|
|
second_commit_area_size = Pseudorandom();
|
|
|
|
|
|
|
|
// With CodeRange.
|
|
|
|
CodeRange* code_range = new CodeRange(isolate);
|
2014-06-13 11:06:42 +00:00
|
|
|
const size_t code_range_size = 32 * MB;
|
2013-01-29 09:09:55 +00:00
|
|
|
if (!code_range->SetUp(code_range_size)) return;
|
|
|
|
|
|
|
|
VerifyMemoryChunk(isolate,
|
|
|
|
heap,
|
|
|
|
code_range,
|
|
|
|
reserve_area_size,
|
|
|
|
initial_commit_area_size,
|
|
|
|
second_commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
EXECUTABLE);
|
2013-01-29 09:09:55 +00:00
|
|
|
|
|
|
|
VerifyMemoryChunk(isolate,
|
|
|
|
heap,
|
|
|
|
code_range,
|
|
|
|
reserve_area_size,
|
|
|
|
initial_commit_area_size,
|
|
|
|
second_commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
NOT_EXECUTABLE);
|
2013-01-29 09:09:55 +00:00
|
|
|
delete code_range;
|
|
|
|
|
|
|
|
// Without CodeRange.
|
|
|
|
code_range = NULL;
|
|
|
|
VerifyMemoryChunk(isolate,
|
|
|
|
heap,
|
|
|
|
code_range,
|
|
|
|
reserve_area_size,
|
|
|
|
initial_commit_area_size,
|
|
|
|
second_commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
EXECUTABLE);
|
2013-01-29 09:09:55 +00:00
|
|
|
|
|
|
|
VerifyMemoryChunk(isolate,
|
|
|
|
heap,
|
|
|
|
code_range,
|
|
|
|
reserve_area_size,
|
|
|
|
initial_commit_area_size,
|
|
|
|
second_commit_area_size,
|
2013-09-11 18:30:01 +00:00
|
|
|
NOT_EXECUTABLE);
|
2013-01-29 09:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(MemoryAllocator) {
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2011-08-04 15:18:18 +00:00
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
Heap* heap = isolate->heap();
|
2011-09-19 18:36:47 +00:00
|
|
|
CHECK(isolate->heap()->ConfigureHeapDefault());
|
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
|
2012-01-13 13:09:52 +00:00
|
|
|
CHECK(memory_allocator->SetUp(heap->MaxReserved(),
|
2011-08-04 15:18:18 +00:00
|
|
|
heap->MaxExecutableSize()));
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
int total_pages = 0;
|
2011-08-04 15:18:18 +00:00
|
|
|
OldSpace faked_space(heap,
|
|
|
|
heap->MaxReserved(),
|
2011-03-18 20:35:07 +00:00
|
|
|
OLD_POINTER_SPACE,
|
2013-09-11 18:30:01 +00:00
|
|
|
NOT_EXECUTABLE);
|
2012-04-02 08:32:31 +00:00
|
|
|
Page* first_page = memory_allocator->AllocatePage(
|
2013-09-11 18:30:01 +00:00
|
|
|
faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
first_page->InsertAfter(faked_space.anchor()->prev_page());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(first_page->is_valid());
|
2011-09-19 18:36:47 +00:00
|
|
|
CHECK(first_page->next_page() == faked_space.anchor());
|
|
|
|
total_pages++;
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) {
|
|
|
|
CHECK(p->owner() == &faked_space);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Again, we should get n or n - 1 pages.
|
2012-04-02 08:32:31 +00:00
|
|
|
Page* other = memory_allocator->AllocatePage(
|
2013-09-11 18:30:01 +00:00
|
|
|
faked_space.AreaSize(), &faked_space, NOT_EXECUTABLE);
|
2011-09-19 18:36:47 +00:00
|
|
|
CHECK(other->is_valid());
|
|
|
|
total_pages++;
|
|
|
|
other->InsertAfter(first_page);
|
2008-08-22 13:33:59 +00:00
|
|
|
int page_count = 0;
|
2011-09-19 18:36:47 +00:00
|
|
|
for (Page* p = first_page; p != faked_space.anchor(); p = p->next_page()) {
|
|
|
|
CHECK(p->owner() == &faked_space);
|
2008-08-22 13:33:59 +00:00
|
|
|
page_count++;
|
|
|
|
}
|
|
|
|
CHECK(total_pages == page_count);
|
|
|
|
|
|
|
|
Page* second_page = first_page->next_page();
|
|
|
|
CHECK(second_page->is_valid());
|
2011-09-19 18:36:47 +00:00
|
|
|
memory_allocator->Free(first_page);
|
|
|
|
memory_allocator->Free(second_page);
|
2011-08-04 15:18:18 +00:00
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NewSpace) {
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2011-08-04 15:18:18 +00:00
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
CHECK(heap->ConfigureHeapDefault());
|
|
|
|
MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
|
2012-01-13 13:09:52 +00:00
|
|
|
CHECK(memory_allocator->SetUp(heap->MaxReserved(),
|
2011-08-04 15:18:18 +00:00
|
|
|
heap->MaxExecutableSize()));
|
|
|
|
TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
NewSpace new_space(heap);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK(new_space.SetUp(CcTest::heap()->ReservedSemiSpaceSize(),
|
|
|
|
CcTest::heap()->ReservedSemiSpaceSize()));
|
2012-01-13 13:09:52 +00:00
|
|
|
CHECK(new_space.HasBeenSetUp());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-01-23 13:02:27 +00:00
|
|
|
while (new_space.Available() >= Page::kMaxRegularHeapObjectSize) {
|
2014-04-30 12:25:18 +00:00
|
|
|
Object* obj = new_space.AllocateRaw(
|
|
|
|
Page::kMaxRegularHeapObjectSize).ToObjectChecked();
|
2008-10-17 09:13:27 +00:00
|
|
|
CHECK(new_space.Contains(HeapObject::cast(obj)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2008-10-17 09:13:27 +00:00
|
|
|
new_space.TearDown();
|
2011-08-04 15:18:18 +00:00
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OldSpace) {
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2011-08-04 15:18:18 +00:00
|
|
|
isolate->InitializeLoggingAndCounters();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
CHECK(heap->ConfigureHeapDefault());
|
|
|
|
MemoryAllocator* memory_allocator = new MemoryAllocator(isolate);
|
2012-01-13 13:09:52 +00:00
|
|
|
CHECK(memory_allocator->SetUp(heap->MaxReserved(),
|
2011-08-04 15:18:18 +00:00
|
|
|
heap->MaxExecutableSize()));
|
|
|
|
TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
|
|
|
|
|
|
|
|
OldSpace* s = new OldSpace(heap,
|
|
|
|
heap->MaxOldGenerationSize(),
|
2008-09-05 12:34:09 +00:00
|
|
|
OLD_POINTER_SPACE,
|
2013-09-11 18:30:01 +00:00
|
|
|
NOT_EXECUTABLE);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(s != NULL);
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
CHECK(s->SetUp());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
while (s->Available() > 0) {
|
2014-04-30 12:25:18 +00:00
|
|
|
s->AllocateRaw(Page::kMaxRegularHeapObjectSize).ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s->TearDown();
|
|
|
|
delete s;
|
2011-08-04 15:18:18 +00:00
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LargeObjectSpace) {
|
2011-08-04 15:18:18 +00:00
|
|
|
v8::V8::Initialize();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
LargeObjectSpace* lo = CcTest::heap()->lo_space();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(lo != NULL);
|
|
|
|
|
|
|
|
int lo_size = Page::kPageSize;
|
|
|
|
|
2014-04-30 12:25:18 +00:00
|
|
|
Object* obj = lo->AllocateRaw(lo_size, NOT_EXECUTABLE).ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(obj->IsHeapObject());
|
|
|
|
|
|
|
|
HeapObject* ho = HeapObject::cast(obj);
|
|
|
|
|
|
|
|
CHECK(lo->Contains(HeapObject::cast(obj)));
|
|
|
|
|
|
|
|
CHECK(lo->FindObject(ho->address()) == obj);
|
|
|
|
|
|
|
|
CHECK(lo->Contains(ho));
|
|
|
|
|
|
|
|
while (true) {
|
2010-09-30 07:22:53 +00:00
|
|
|
intptr_t available = lo->Available();
|
2014-04-30 12:25:18 +00:00
|
|
|
{ AllocationResult allocation = lo->AllocateRaw(lo_size, NOT_EXECUTABLE);
|
|
|
|
if (allocation.IsRetry()) break;
|
2010-10-25 15:22:03 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(lo->Available() < available);
|
2014-05-09 12:59:24 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK(!lo->IsEmpty());
|
|
|
|
|
2014-04-30 12:25:18 +00:00
|
|
|
CHECK(lo->AllocateRaw(lo_size, NOT_EXECUTABLE).IsRetry());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2013-09-20 12:18:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(SizeOfFirstPageIsLargeEnough) {
|
|
|
|
if (i::FLAG_always_opt) return;
|
2014-07-01 11:54:57 +00:00
|
|
|
// Bootstrapping without a snapshot causes more allocations.
|
|
|
|
if (!i::Snapshot::HaveASnapshotToStartFrom()) return;
|
2013-09-20 12:18:17 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
|
|
|
// Freshly initialized VM gets by with one page per space.
|
|
|
|
for (int i = FIRST_PAGED_SPACE; i <= LAST_PAGED_SPACE; i++) {
|
2014-05-09 12:51:52 +00:00
|
|
|
// Debug code can be very large, so skip CODE_SPACE if we are generating it.
|
|
|
|
if (i == CODE_SPACE && i::FLAG_debug_code) continue;
|
2013-09-20 12:18:17 +00:00
|
|
|
CHECK_EQ(1, isolate->heap()->paged_space(i)->CountTotalPages());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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++) {
|
2014-05-09 12:51:52 +00:00
|
|
|
// Debug code can be very large, so skip CODE_SPACE if we are generating it.
|
|
|
|
if (i == CODE_SPACE && i::FLAG_debug_code) continue;
|
2013-09-20 12:18:17 +00:00
|
|
|
CHECK_EQ(1, isolate->heap()->paged_space(i)->CountTotalPages());
|
|
|
|
}
|
|
|
|
|
|
|
|
// No large objects required to perform the above steps.
|
|
|
|
CHECK(isolate->heap()->lo_space()->IsEmpty());
|
|
|
|
}
|