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-10-01 11:54:47 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/heap/spaces-inl.h"
|
|
|
|
#include "src/objects-inl.h"
|
2015-03-27 15:28:55 +00:00
|
|
|
#include "src/snapshot/snapshot.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2015-12-09 11:25:26 +00:00
|
|
|
#include "test/cctest/heap/heap-tester.h"
|
2016-09-06 11:02:21 +00:00
|
|
|
#include "test/cctest/heap/heap-utils.h"
|
2014-07-01 11:54:57 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-08-11 10:04:47 +00:00
|
|
|
namespace heap {
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-08-04 15:18:18 +00:00
|
|
|
// Temporarily sets a given allocator in an isolate.
|
|
|
|
class TestMemoryAllocatorScope {
|
|
|
|
public:
|
|
|
|
TestMemoryAllocatorScope(Isolate* isolate, MemoryAllocator* allocator)
|
2016-04-06 11:38:31 +00:00
|
|
|
: isolate_(isolate), old_allocator_(isolate->heap()->memory_allocator()) {
|
|
|
|
isolate->heap()->memory_allocator_ = allocator;
|
2011-08-04 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~TestMemoryAllocatorScope() {
|
2016-04-06 11:38:31 +00:00
|
|
|
isolate_->heap()->memory_allocator_ = old_allocator_;
|
2011-08-04 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2016-04-06 11:38:31 +00:00
|
|
|
old_code_range_(isolate->heap()->memory_allocator()->code_range()) {
|
|
|
|
isolate->heap()->memory_allocator()->code_range_ = code_range;
|
2013-01-29 09:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~TestCodeRangeScope() {
|
2016-04-06 11:38:31 +00:00
|
|
|
isolate_->heap()->memory_allocator()->code_range_ = old_code_range_;
|
2013-01-29 09:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
CodeRange* old_code_range_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestCodeRangeScope);
|
|
|
|
};
|
|
|
|
|
2018-02-27 14:59:03 +00:00
|
|
|
static void VerifyMemoryChunk(Isolate* isolate, Heap* heap,
|
|
|
|
CodeRange* code_range, size_t reserve_area_size,
|
|
|
|
size_t commit_area_size, Executability executable,
|
|
|
|
Space* space) {
|
2018-06-11 17:33:32 +00:00
|
|
|
MemoryAllocator* memory_allocator =
|
|
|
|
new MemoryAllocator(isolate, heap->MaxReserved(), 0);
|
2016-04-06 11:38:31 +00:00
|
|
|
{
|
|
|
|
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(
|
2018-02-27 14:59:03 +00:00
|
|
|
reserve_area_size, commit_area_size, executable, space);
|
2017-10-13 16:33:03 +00:00
|
|
|
size_t alignment = code_range != nullptr && code_range->valid()
|
2016-04-06 11:38:31 +00:00
|
|
|
? MemoryChunk::kAlignment
|
2017-12-15 17:59:57 +00:00
|
|
|
: CommitPageSize();
|
2016-04-06 11:38:31 +00:00
|
|
|
size_t reserved_size =
|
|
|
|
((executable == EXECUTABLE))
|
|
|
|
? RoundUp(header_size + guard_size + reserve_area_size + guard_size,
|
|
|
|
alignment)
|
2017-12-15 17:59:57 +00:00
|
|
|
: RoundUp(header_size + reserve_area_size, CommitPageSize());
|
2016-04-06 11:38:31 +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);
|
|
|
|
|
2016-04-29 14:27:41 +00:00
|
|
|
memory_allocator->Free<MemoryAllocator::kFull>(memory_chunk);
|
2016-04-06 11:38:31 +00:00
|
|
|
}
|
2013-01-29 09:09:55 +00:00
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
|
|
|
}
|
|
|
|
|
2014-08-26 13:14:46 +00:00
|
|
|
TEST(Regress3540) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
2018-06-11 17:33:32 +00:00
|
|
|
MemoryAllocator* memory_allocator =
|
|
|
|
new MemoryAllocator(isolate, heap->MaxReserved(), 0);
|
2014-08-26 13:14:46 +00:00
|
|
|
TestMemoryAllocatorScope test_allocator_scope(isolate, memory_allocator);
|
2016-05-20 13:30:22 +00:00
|
|
|
size_t code_range_size =
|
2016-08-08 15:56:26 +00:00
|
|
|
kMinimumCodeRangeSize > 0 ? kMinimumCodeRangeSize : 3 * Page::kPageSize;
|
2018-06-11 17:33:32 +00:00
|
|
|
CodeRange* code_range = new CodeRange(isolate, code_range_size);
|
2015-09-01 18:39:13 +00:00
|
|
|
|
2014-08-26 14:35:54 +00:00
|
|
|
Address address;
|
|
|
|
size_t size;
|
2016-05-20 13:30:22 +00:00
|
|
|
size_t request_size = code_range_size - Page::kPageSize;
|
2015-02-24 19:05:21 +00:00
|
|
|
address = code_range->AllocateRawMemory(
|
2015-09-01 18:39:13 +00:00
|
|
|
request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
|
|
|
|
&size);
|
2018-04-13 22:28:05 +00:00
|
|
|
CHECK_NE(address, kNullAddress);
|
2015-09-01 18:39:13 +00:00
|
|
|
|
2014-08-26 14:35:54 +00:00
|
|
|
Address null_address;
|
|
|
|
size_t null_size;
|
2016-05-19 17:53:56 +00:00
|
|
|
request_size = code_range_size - Page::kPageSize;
|
2014-08-26 14:35:54 +00:00
|
|
|
null_address = code_range->AllocateRawMemory(
|
2015-09-01 18:39:13 +00:00
|
|
|
request_size, request_size - (2 * MemoryAllocator::CodePageGuardSize()),
|
|
|
|
&null_size);
|
2018-04-13 22:28:05 +00:00
|
|
|
CHECK_EQ(null_address, kNullAddress);
|
2015-09-01 18:39:13 +00:00
|
|
|
|
2014-08-26 14:35:54 +00:00
|
|
|
code_range->FreeRawMemory(address, size);
|
|
|
|
delete code_range;
|
|
|
|
memory_allocator->TearDown();
|
|
|
|
delete memory_allocator;
|
2014-08-26 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 12:39:53 +00:00
|
|
|
static unsigned int PseudorandomAreaSize() {
|
2013-01-29 09:09:55 +00:00
|
|
|
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
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
|
|
|
|
size_t reserve_area_size = 1 * MB;
|
2017-11-08 15:57:53 +00:00
|
|
|
size_t initial_commit_area_size;
|
2013-01-29 09:09:55 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
2017-10-26 12:39:53 +00:00
|
|
|
initial_commit_area_size = PseudorandomAreaSize();
|
2013-01-29 09:09:55 +00:00
|
|
|
|
|
|
|
// With CodeRange.
|
2014-06-13 11:06:42 +00:00
|
|
|
const size_t code_range_size = 32 * MB;
|
2018-06-11 17:33:32 +00:00
|
|
|
CodeRange* code_range = new CodeRange(isolate, code_range_size);
|
2013-01-29 09:09:55 +00:00
|
|
|
|
2018-02-27 14:59:03 +00:00
|
|
|
VerifyMemoryChunk(isolate, heap, code_range, reserve_area_size,
|
|
|
|
initial_commit_area_size, EXECUTABLE, heap->code_space());
|
|
|
|
|
|
|
|
VerifyMemoryChunk(isolate, heap, code_range, reserve_area_size,
|
|
|
|
initial_commit_area_size, NOT_EXECUTABLE,
|
|
|
|
heap->old_space());
|
2016-05-19 17:53:56 +00:00
|
|
|
delete code_range;
|
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
|
|
|
Heap* heap = isolate->heap();
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2018-06-11 17:33:32 +00:00
|
|
|
MemoryAllocator* memory_allocator =
|
|
|
|
new MemoryAllocator(isolate, heap->MaxReserved(), 0);
|
2017-09-19 13:08:15 +00:00
|
|
|
CHECK_NOT_NULL(memory_allocator);
|
2015-08-27 12:16:00 +00:00
|
|
|
TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
|
2011-08-04 15:18:18 +00:00
|
|
|
|
2015-08-27 12:16:00 +00:00
|
|
|
{
|
|
|
|
int total_pages = 0;
|
2018-05-07 13:36:00 +00:00
|
|
|
OldSpace faked_space(heap);
|
2018-05-22 16:58:12 +00:00
|
|
|
CHECK(!faked_space.first_page());
|
|
|
|
CHECK(!faked_space.last_page());
|
2016-04-25 14:52:30 +00:00
|
|
|
Page* first_page = memory_allocator->AllocatePage(
|
2016-04-05 13:11:47 +00:00
|
|
|
faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space),
|
|
|
|
NOT_EXECUTABLE);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2018-05-22 16:58:12 +00:00
|
|
|
faked_space.memory_chunk_list().PushBack(first_page);
|
|
|
|
CHECK(first_page->next_page() == nullptr);
|
2015-08-27 12:16:00 +00:00
|
|
|
total_pages++;
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-05-22 16:58:12 +00:00
|
|
|
for (Page* p = first_page; p != nullptr; p = p->next_page()) {
|
2015-08-27 12:16:00 +00:00
|
|
|
CHECK(p->owner() == &faked_space);
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-08-27 12:16:00 +00:00
|
|
|
// Again, we should get n or n - 1 pages.
|
2016-04-25 14:52:30 +00:00
|
|
|
Page* other = memory_allocator->AllocatePage(
|
2016-04-05 13:11:47 +00:00
|
|
|
faked_space.AreaSize(), static_cast<PagedSpace*>(&faked_space),
|
|
|
|
NOT_EXECUTABLE);
|
2015-08-27 12:16:00 +00:00
|
|
|
total_pages++;
|
2018-05-22 16:58:12 +00:00
|
|
|
faked_space.memory_chunk_list().PushBack(other);
|
2015-08-27 12:16:00 +00:00
|
|
|
int page_count = 0;
|
2018-05-22 16:58:12 +00:00
|
|
|
for (Page* p = first_page; p != nullptr; p = p->next_page()) {
|
2015-08-27 12:16:00 +00:00
|
|
|
CHECK(p->owner() == &faked_space);
|
|
|
|
page_count++;
|
|
|
|
}
|
|
|
|
CHECK(total_pages == page_count);
|
|
|
|
|
|
|
|
Page* second_page = first_page->next_page();
|
2018-01-12 12:06:06 +00:00
|
|
|
CHECK_NOT_NULL(second_page);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-08-27 12:16:00 +00:00
|
|
|
// OldSpace's destructor will tear down the space and free up all pages.
|
|
|
|
}
|
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
|
|
|
Heap* heap = isolate->heap();
|
2018-06-11 17:33:32 +00:00
|
|
|
MemoryAllocator* memory_allocator =
|
|
|
|
new MemoryAllocator(isolate, heap->MaxReserved(), 0);
|
2011-08-04 15:18:18 +00:00
|
|
|
TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-11 17:33:32 +00:00
|
|
|
NewSpace new_space(heap, CcTest::heap()->InitialSemiSpaceSize(),
|
|
|
|
CcTest::heap()->InitialSemiSpaceSize());
|
2018-06-06 19:10:19 +00:00
|
|
|
CHECK(new_space.MaximumCapacity());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2016-09-06 12:58:59 +00:00
|
|
|
while (new_space.Available() >= kMaxRegularHeapObjectSize) {
|
2016-09-30 11:13:38 +00:00
|
|
|
CHECK(new_space.Contains(
|
|
|
|
new_space.AllocateRawUnaligned(kMaxRegularHeapObjectSize)
|
|
|
|
.ToObjectChecked()));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2008-10-17 09:13:27 +00:00
|
|
|
new_space.TearDown();
|
2018-04-19 15:34:13 +00:00
|
|
|
memory_allocator->unmapper()->EnsureUnmappingCompleted();
|
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
|
|
|
Heap* heap = isolate->heap();
|
2018-06-11 17:33:32 +00:00
|
|
|
MemoryAllocator* memory_allocator =
|
|
|
|
new MemoryAllocator(isolate, heap->MaxReserved(), 0);
|
2011-08-04 15:18:18 +00:00
|
|
|
TestMemoryAllocatorScope test_scope(isolate, memory_allocator);
|
|
|
|
|
2018-05-07 13:36:00 +00:00
|
|
|
OldSpace* s = new OldSpace(heap);
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_NOT_NULL(s);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
while (s->Available() > 0) {
|
2016-09-06 12:58:59 +00:00
|
|
|
s->AllocateRawUnaligned(kMaxRegularHeapObjectSize).ToObjectChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2016-09-12 11:46:14 +00:00
|
|
|
// This test does not initialize allocated objects, which confuses the
|
|
|
|
// incremental marker.
|
|
|
|
FLAG_incremental_marking = false;
|
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();
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_NOT_NULL(lo);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
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) {
|
2016-11-14 16:46:42 +00:00
|
|
|
size_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
|
|
|
}
|
2015-02-24 19:05:21 +00:00
|
|
|
// The available value is conservative such that it may report
|
|
|
|
// zero prior to heap exhaustion.
|
|
|
|
CHECK(lo->Available() < available || available == 0);
|
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
|
|
|
|
2017-08-24 08:38:28 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
// The test verifies that committed size of a space is less then some threshold.
|
|
|
|
// Debug builds pull in all sorts of additional instrumentation that increases
|
|
|
|
// heap sizes. E.g. CSA_ASSERT creates on-heap strings for error messages. These
|
|
|
|
// messages are also not stable if files are moved and modified during the build
|
|
|
|
// process (jumbo builds).
|
2016-09-06 11:02:21 +00:00
|
|
|
TEST(SizeOfInitialHeap) {
|
2013-09-20 12:18:17 +00:00
|
|
|
if (i::FLAG_always_opt) return;
|
2014-07-01 11:54:57 +00:00
|
|
|
// Bootstrapping without a snapshot causes more allocations.
|
2013-09-20 12:18:17 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2015-02-25 11:14:40 +00:00
|
|
|
if (!isolate->snapshot_available()) return;
|
2016-06-08 07:48:40 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-10-05 19:47:11 +00:00
|
|
|
// Initial size of LO_SPACE
|
|
|
|
size_t initial_lo_space = isolate->heap()->lo_space()->Size();
|
2013-09-20 12:18:17 +00:00
|
|
|
|
2016-11-25 19:37:52 +00:00
|
|
|
// The limit for each space for an empty isolate containing just the
|
|
|
|
// snapshot.
|
|
|
|
// In PPC the page size is 64K, causing more internal fragmentation
|
|
|
|
// hence requiring a larger limit.
|
|
|
|
#if V8_OS_LINUX && V8_HOST_ARCH_PPC
|
|
|
|
const size_t kMaxInitialSizePerSpace = 3 * MB;
|
|
|
|
#else
|
2016-09-06 11:02:21 +00:00
|
|
|
const size_t kMaxInitialSizePerSpace = 2 * MB;
|
2016-11-25 19:37:52 +00:00
|
|
|
#endif
|
2015-06-30 07:48:23 +00:00
|
|
|
|
2016-09-06 11:02:21 +00:00
|
|
|
// Freshly initialized VM gets by with the snapshot size (which is below
|
|
|
|
// kMaxInitialSizePerSpace per space).
|
|
|
|
Heap* heap = isolate->heap();
|
2018-03-23 11:42:41 +00:00
|
|
|
int page_count[LAST_GROWABLE_PAGED_SPACE + 1] = {0, 0, 0, 0};
|
|
|
|
for (int i = FIRST_GROWABLE_PAGED_SPACE; i <= LAST_GROWABLE_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;
|
2016-09-06 11:02:21 +00:00
|
|
|
|
|
|
|
page_count[i] = heap->paged_space(i)->CountTotalPages();
|
|
|
|
// Check that the initial heap is also below the limit.
|
2017-05-03 21:31:06 +00:00
|
|
|
CHECK_LE(heap->paged_space(i)->CommittedMemory(), kMaxInitialSizePerSpace);
|
2013-09-20 12:18:17 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 11:02:21 +00:00
|
|
|
// Executing the empty script gets by with the same number of pages, i.e.,
|
|
|
|
// requires no extra space.
|
2013-09-20 12:18:17 +00:00
|
|
|
CompileRun("/*empty*/");
|
2018-03-23 11:42:41 +00:00
|
|
|
for (int i = FIRST_GROWABLE_PAGED_SPACE; i <= LAST_GROWABLE_PAGED_SPACE;
|
|
|
|
i++) {
|
2017-03-13 20:59:15 +00:00
|
|
|
// Skip CODE_SPACE, since we had to generate code even for an empty script.
|
|
|
|
if (i == CODE_SPACE) continue;
|
2016-09-06 11:02:21 +00:00
|
|
|
CHECK_EQ(page_count[i], isolate->heap()->paged_space(i)->CountTotalPages());
|
2013-09-20 12:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No large objects required to perform the above steps.
|
2016-11-10 10:16:21 +00:00
|
|
|
CHECK_EQ(initial_lo_space,
|
|
|
|
static_cast<size_t>(isolate->heap()->lo_space()->Size()));
|
2013-09-20 12:18:17 +00:00
|
|
|
}
|
2017-08-24 08:38:28 +00:00
|
|
|
#endif // DEBUG
|
2014-10-22 06:58:38 +00:00
|
|
|
|
2015-11-05 04:45:19 +00:00
|
|
|
static HeapObject* AllocateUnaligned(NewSpace* space, int size) {
|
|
|
|
AllocationResult allocation = space->AllocateRawUnaligned(size);
|
|
|
|
CHECK(!allocation.IsRetry());
|
2017-10-13 16:33:03 +00:00
|
|
|
HeapObject* filler = nullptr;
|
2015-11-05 04:45:19 +00:00
|
|
|
CHECK(allocation.To(&filler));
|
2016-02-25 14:36:13 +00:00
|
|
|
space->heap()->CreateFillerObjectAt(filler->address(), size,
|
|
|
|
ClearRecordedSlots::kNo);
|
2015-11-05 04:45:19 +00:00
|
|
|
return filler;
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
static HeapObject* AllocateUnaligned(PagedSpace* space, int size) {
|
|
|
|
AllocationResult allocation = space->AllocateRaw(size, kDoubleUnaligned);
|
|
|
|
CHECK(!allocation.IsRetry());
|
2017-10-13 16:33:03 +00:00
|
|
|
HeapObject* filler = nullptr;
|
2016-02-12 19:50:04 +00:00
|
|
|
CHECK(allocation.To(&filler));
|
2016-02-25 14:36:13 +00:00
|
|
|
space->heap()->CreateFillerObjectAt(filler->address(), size,
|
|
|
|
ClearRecordedSlots::kNo);
|
2016-02-12 19:50:04 +00:00
|
|
|
return filler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HeapObject* AllocateUnaligned(LargeObjectSpace* space, int size) {
|
|
|
|
AllocationResult allocation = space->AllocateRaw(size, EXECUTABLE);
|
|
|
|
CHECK(!allocation.IsRetry());
|
2017-10-13 16:33:03 +00:00
|
|
|
HeapObject* filler = nullptr;
|
2016-02-12 19:50:04 +00:00
|
|
|
CHECK(allocation.To(&filler));
|
|
|
|
return filler;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Observer : public AllocationObserver {
|
2015-11-05 04:45:19 +00:00
|
|
|
public:
|
|
|
|
explicit Observer(intptr_t step_size)
|
2016-02-12 19:50:04 +00:00
|
|
|
: AllocationObserver(step_size), count_(0) {}
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2017-12-06 09:21:19 +00:00
|
|
|
void Step(int bytes_allocated, Address addr, size_t) override { count_++; }
|
2015-11-05 04:45:19 +00:00
|
|
|
|
|
|
|
int count() const { return count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int count_;
|
|
|
|
};
|
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
template <typename T>
|
|
|
|
void testAllocationObserver(Isolate* i_isolate, T* space) {
|
|
|
|
Observer observer1(128);
|
|
|
|
space->AddAllocationObserver(&observer1);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// The observer should not get notified if we have only allocated less than
|
|
|
|
// 128 bytes.
|
|
|
|
AllocateUnaligned(space, 64);
|
|
|
|
CHECK_EQ(observer1.count(), 0);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// The observer should get called when we have allocated exactly 128 bytes.
|
|
|
|
AllocateUnaligned(space, 64);
|
|
|
|
CHECK_EQ(observer1.count(), 1);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Another >128 bytes should get another notification.
|
|
|
|
AllocateUnaligned(space, 136);
|
|
|
|
CHECK_EQ(observer1.count(), 2);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Allocating a large object should get only one notification.
|
|
|
|
AllocateUnaligned(space, 1024);
|
|
|
|
CHECK_EQ(observer1.count(), 3);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Allocating another 2048 bytes in small objects should get 16
|
|
|
|
// notifications.
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
AllocateUnaligned(space, 32);
|
|
|
|
}
|
|
|
|
CHECK_EQ(observer1.count(), 19);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Multiple observers should work.
|
|
|
|
Observer observer2(96);
|
|
|
|
space->AddAllocationObserver(&observer2);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
AllocateUnaligned(space, 2048);
|
|
|
|
CHECK_EQ(observer1.count(), 20);
|
|
|
|
CHECK_EQ(observer2.count(), 1);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
AllocateUnaligned(space, 104);
|
|
|
|
CHECK_EQ(observer1.count(), 20);
|
|
|
|
CHECK_EQ(observer2.count(), 2);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Callback should stop getting called after an observer is removed.
|
|
|
|
space->RemoveAllocationObserver(&observer1);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
AllocateUnaligned(space, 384);
|
|
|
|
CHECK_EQ(observer1.count(), 20); // no more notifications.
|
|
|
|
CHECK_EQ(observer2.count(), 3); // this one is still active.
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
// Ensure that PauseInlineAllocationObserversScope work correctly.
|
|
|
|
AllocateUnaligned(space, 48);
|
|
|
|
CHECK_EQ(observer2.count(), 3);
|
|
|
|
{
|
|
|
|
PauseAllocationObserversScope pause_observers(i_isolate->heap());
|
|
|
|
CHECK_EQ(observer2.count(), 3);
|
|
|
|
AllocateUnaligned(space, 384);
|
|
|
|
CHECK_EQ(observer2.count(), 3);
|
|
|
|
}
|
|
|
|
CHECK_EQ(observer2.count(), 3);
|
|
|
|
// Coupled with the 48 bytes allocated before the pause, another 48 bytes
|
|
|
|
// allocated here should trigger a notification.
|
|
|
|
AllocateUnaligned(space, 48);
|
|
|
|
CHECK_EQ(observer2.count(), 4);
|
|
|
|
|
|
|
|
space->RemoveAllocationObserver(&observer2);
|
|
|
|
AllocateUnaligned(space, 384);
|
|
|
|
CHECK_EQ(observer1.count(), 20);
|
|
|
|
CHECK_EQ(observer2.count(), 4);
|
|
|
|
}
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
UNINITIALIZED_TEST(AllocationObserver) {
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
2015-11-05 04:45:19 +00:00
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
testAllocationObserver<NewSpace>(i_isolate, i_isolate->heap()->new_space());
|
|
|
|
// Old space is used but the code path is shared for all
|
|
|
|
// classes inheriting from PagedSpace.
|
|
|
|
testAllocationObserver<PagedSpace>(i_isolate,
|
|
|
|
i_isolate->heap()->old_space());
|
|
|
|
testAllocationObserver<LargeObjectSpace>(i_isolate,
|
|
|
|
i_isolate->heap()->lo_space());
|
2015-11-05 04:45:19 +00:00
|
|
|
}
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
2015-11-09 19:48:08 +00:00
|
|
|
|
2015-11-11 20:55:19 +00:00
|
|
|
UNINITIALIZED_TEST(InlineAllocationObserverCadence) {
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
|
2017-04-25 00:13:18 +00:00
|
|
|
// 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);
|
|
|
|
|
2015-11-11 20:55:19 +00:00
|
|
|
NewSpace* new_space = i_isolate->heap()->new_space();
|
|
|
|
|
|
|
|
Observer observer1(512);
|
2016-02-12 19:50:04 +00:00
|
|
|
new_space->AddAllocationObserver(&observer1);
|
2015-11-11 20:55:19 +00:00
|
|
|
Observer observer2(576);
|
2016-02-12 19:50:04 +00:00
|
|
|
new_space->AddAllocationObserver(&observer2);
|
2015-11-11 20:55:19 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 512; ++i) {
|
|
|
|
AllocateUnaligned(new_space, 32);
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:50:04 +00:00
|
|
|
new_space->RemoveAllocationObserver(&observer1);
|
|
|
|
new_space->RemoveAllocationObserver(&observer2);
|
2015-11-11 20:55:19 +00:00
|
|
|
|
2015-11-18 15:54:25 +00:00
|
|
|
CHECK_EQ(observer1.count(), 32);
|
|
|
|
CHECK_EQ(observer2.count(), 28);
|
2015-11-11 20:55:19 +00:00
|
|
|
}
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
|
|
|
|
2017-10-26 10:40:48 +00:00
|
|
|
HEAP_TEST(Regress777177) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
PagedSpace* old_space = heap->old_space();
|
|
|
|
Observer observer(128);
|
|
|
|
old_space->AddAllocationObserver(&observer);
|
|
|
|
|
|
|
|
int area_size = old_space->AreaSize();
|
|
|
|
int max_object_size = kMaxRegularHeapObjectSize;
|
|
|
|
int filler_size = area_size - max_object_size;
|
|
|
|
|
|
|
|
{
|
|
|
|
// Ensure a new linear allocation area on a fresh page.
|
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
|
|
|
heap::SimulateFullSpace(old_space);
|
|
|
|
AllocationResult result = old_space->AllocateRaw(filler_size, kWordAligned);
|
|
|
|
HeapObject* obj = result.ToObjectChecked();
|
|
|
|
heap->CreateFillerObjectAt(obj->address(), filler_size,
|
|
|
|
ClearRecordedSlots::kNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Allocate all bytes of the linear allocation area. This moves top_ and
|
|
|
|
// top_on_previous_step_ to the next page.
|
|
|
|
AllocationResult result =
|
|
|
|
old_space->AllocateRaw(max_object_size, kWordAligned);
|
|
|
|
HeapObject* obj = result.ToObjectChecked();
|
|
|
|
// Simulate allocation folding moving the top pointer back.
|
|
|
|
old_space->SetTopAndLimit(obj->address(), old_space->limit());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// This triggers assert in crbug.com/777177.
|
|
|
|
AllocationResult result = old_space->AllocateRaw(filler_size, kWordAligned);
|
|
|
|
HeapObject* obj = result.ToObjectChecked();
|
|
|
|
heap->CreateFillerObjectAt(obj->address(), filler_size,
|
|
|
|
ClearRecordedSlots::kNo);
|
|
|
|
}
|
|
|
|
old_space->RemoveAllocationObserver(&observer);
|
|
|
|
}
|
|
|
|
|
2017-12-06 09:21:19 +00:00
|
|
|
HEAP_TEST(Regress791582) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
NewSpace* new_space = heap->new_space();
|
|
|
|
if (new_space->TotalCapacity() < new_space->MaximumCapacity()) {
|
|
|
|
new_space->Grow();
|
|
|
|
}
|
|
|
|
|
|
|
|
int until_page_end = static_cast<int>(new_space->limit() - new_space->top());
|
|
|
|
|
|
|
|
if (until_page_end % kPointerSize != 0) {
|
|
|
|
// 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).
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Observer observer(128);
|
|
|
|
new_space->AddAllocationObserver(&observer);
|
|
|
|
|
|
|
|
{
|
|
|
|
AllocationResult result =
|
|
|
|
new_space->AllocateRaw(until_page_end, kWordAligned);
|
|
|
|
HeapObject* obj = result.ToObjectChecked();
|
|
|
|
heap->CreateFillerObjectAt(obj->address(), until_page_end,
|
|
|
|
ClearRecordedSlots::kNo);
|
|
|
|
// Simulate allocation folding moving the top pointer back.
|
|
|
|
*new_space->allocation_top_address() = obj->address();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// This triggers assert in crbug.com/791582
|
|
|
|
AllocationResult result = new_space->AllocateRaw(256, kWordAligned);
|
|
|
|
HeapObject* obj = result.ToObjectChecked();
|
|
|
|
heap->CreateFillerObjectAt(obj->address(), 256, ClearRecordedSlots::kNo);
|
|
|
|
}
|
|
|
|
new_space->RemoveAllocationObserver(&observer);
|
|
|
|
}
|
|
|
|
|
2016-09-06 11:02:21 +00:00
|
|
|
TEST(ShrinkPageToHighWaterMarkFreeSpaceEnd) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_incremental_marking = false;
|
2016-09-06 11:02:21 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
heap::SealCurrentObjects(CcTest::heap());
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
|
|
|
// Reset space so high water mark is consistent.
|
2017-08-17 17:38:43 +00:00
|
|
|
PagedSpace* old_space = CcTest::heap()->old_space();
|
2018-01-09 08:56:07 +00:00
|
|
|
old_space->FreeLinearAllocationArea();
|
2017-12-12 13:50:10 +00:00
|
|
|
old_space->ResetFreeList();
|
2016-09-06 11:02:21 +00:00
|
|
|
|
|
|
|
HeapObject* filler =
|
|
|
|
HeapObject::FromAddress(array->address() + array->Size());
|
|
|
|
CHECK(filler->IsFreeSpace());
|
2017-08-17 17:38:43 +00:00
|
|
|
size_t shrunk = old_space->ShrinkPageToHighWaterMark(page);
|
2017-08-02 08:23:36 +00:00
|
|
|
size_t should_have_shrunk =
|
2016-09-06 11:02:21 +00:00
|
|
|
RoundDown(static_cast<size_t>(Page::kAllocatableMemory - array->Size()),
|
2017-12-15 17:59:57 +00:00
|
|
|
CommitPageSize());
|
2017-08-02 08:23:36 +00:00
|
|
|
CHECK_EQ(should_have_shrunk, shrunk);
|
2016-09-06 11:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ShrinkPageToHighWaterMarkNoFiller) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
heap::SealCurrentObjects(CcTest::heap());
|
|
|
|
|
|
|
|
const int kFillerSize = 0;
|
|
|
|
std::vector<Handle<FixedArray>> arrays =
|
|
|
|
heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize);
|
|
|
|
Handle<FixedArray> array = arrays.back();
|
|
|
|
Page* page = Page::FromAddress(array->address());
|
|
|
|
CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize);
|
|
|
|
|
|
|
|
// Reset space so high water mark and fillers are consistent.
|
2017-08-17 17:38:43 +00:00
|
|
|
PagedSpace* old_space = CcTest::heap()->old_space();
|
|
|
|
old_space->ResetFreeList();
|
2018-01-09 08:56:07 +00:00
|
|
|
old_space->FreeLinearAllocationArea();
|
2016-09-06 11:02:21 +00:00
|
|
|
|
2017-08-17 17:38:43 +00:00
|
|
|
size_t shrunk = old_space->ShrinkPageToHighWaterMark(page);
|
2017-08-02 08:23:36 +00:00
|
|
|
CHECK_EQ(0u, shrunk);
|
2016-09-06 11:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ShrinkPageToHighWaterMarkOneWordFiller) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
heap::SealCurrentObjects(CcTest::heap());
|
|
|
|
|
|
|
|
const int kFillerSize = kPointerSize;
|
|
|
|
std::vector<Handle<FixedArray>> arrays =
|
|
|
|
heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize);
|
|
|
|
Handle<FixedArray> array = arrays.back();
|
|
|
|
Page* page = Page::FromAddress(array->address());
|
|
|
|
CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize);
|
|
|
|
|
|
|
|
// Reset space so high water mark and fillers are consistent.
|
2017-08-17 17:38:43 +00:00
|
|
|
PagedSpace* old_space = CcTest::heap()->old_space();
|
2018-01-09 08:56:07 +00:00
|
|
|
old_space->FreeLinearAllocationArea();
|
2017-12-12 13:50:10 +00:00
|
|
|
old_space->ResetFreeList();
|
2016-09-06 11:02:21 +00:00
|
|
|
|
|
|
|
HeapObject* filler =
|
|
|
|
HeapObject::FromAddress(array->address() + array->Size());
|
|
|
|
CHECK_EQ(filler->map(), CcTest::heap()->one_pointer_filler_map());
|
|
|
|
|
2017-08-17 17:38:43 +00:00
|
|
|
size_t shrunk = old_space->ShrinkPageToHighWaterMark(page);
|
2017-08-02 08:23:36 +00:00
|
|
|
CHECK_EQ(0u, shrunk);
|
2016-09-06 11:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ShrinkPageToHighWaterMarkTwoWordFiller) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
heap::SealCurrentObjects(CcTest::heap());
|
|
|
|
|
|
|
|
const int kFillerSize = 2 * kPointerSize;
|
|
|
|
std::vector<Handle<FixedArray>> arrays =
|
|
|
|
heap::FillOldSpacePageWithFixedArrays(CcTest::heap(), kFillerSize);
|
|
|
|
Handle<FixedArray> array = arrays.back();
|
|
|
|
Page* page = Page::FromAddress(array->address());
|
|
|
|
CHECK_EQ(page->area_end(), array->address() + array->Size() + kFillerSize);
|
|
|
|
|
|
|
|
// Reset space so high water mark and fillers are consistent.
|
2017-08-17 17:38:43 +00:00
|
|
|
PagedSpace* old_space = CcTest::heap()->old_space();
|
2018-01-09 08:56:07 +00:00
|
|
|
old_space->FreeLinearAllocationArea();
|
2017-12-12 13:50:10 +00:00
|
|
|
old_space->ResetFreeList();
|
2016-09-06 11:02:21 +00:00
|
|
|
|
|
|
|
HeapObject* filler =
|
|
|
|
HeapObject::FromAddress(array->address() + array->Size());
|
|
|
|
CHECK_EQ(filler->map(), CcTest::heap()->two_pointer_filler_map());
|
|
|
|
|
2017-08-17 17:38:43 +00:00
|
|
|
size_t shrunk = old_space->ShrinkPageToHighWaterMark(page);
|
2017-08-02 08:23:36 +00:00
|
|
|
CHECK_EQ(0u, shrunk);
|
2016-09-06 11:02:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 10:04:47 +00:00
|
|
|
} // namespace heap
|
2015-11-09 19:48:08 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|