2016-06-20 13:19:25 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/factory.h"
|
2016-06-20 13:19:25 +00:00
|
|
|
#include "src/heap/array-buffer-tracker.h"
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/heap/spaces-inl.h"
|
|
|
|
#include "src/isolate.h"
|
|
|
|
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
|
|
|
|
// (disallowed) include: src/factory.h -> src/objects-inl.h
|
|
|
|
#include "src/objects-inl.h"
|
|
|
|
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
|
2017-02-07 14:05:02 +00:00
|
|
|
// (disallowed) include: src/feedback-vector.h ->
|
|
|
|
// src/feedback-vector-inl.h
|
|
|
|
#include "src/feedback-vector-inl.h"
|
2016-06-20 13:19:25 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2016-10-25 15:33:56 +00:00
|
|
|
#include "test/cctest/heap/heap-tester.h"
|
2016-06-20 13:19:25 +00:00
|
|
|
#include "test/cctest/heap/heap-utils.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-10-25 15:33:56 +00:00
|
|
|
v8::Isolate* NewIsolateForPagePromotion(int min_semi_space_size = 8,
|
|
|
|
int max_semi_space_size = 8) {
|
2016-06-20 13:19:25 +00:00
|
|
|
i::FLAG_page_promotion = true;
|
|
|
|
i::FLAG_page_promotion_threshold = 0; // %
|
2016-10-25 15:33:56 +00:00
|
|
|
i::FLAG_min_semi_space_size = min_semi_space_size;
|
2016-06-20 13:19:25 +00:00
|
|
|
// We cannot optimize for size as we require a new space with more than one
|
|
|
|
// page.
|
|
|
|
i::FLAG_optimize_for_size = false;
|
|
|
|
// Set max_semi_space_size because it could've been initialized by an
|
|
|
|
// implication of optimize_for_size.
|
2016-10-25 15:33:56 +00:00
|
|
|
i::FLAG_max_semi_space_size = max_semi_space_size;
|
2016-06-20 13:19:25 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
return isolate;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(PagePromotion_NewToOld) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!i::FLAG_incremental_marking) return;
|
2016-06-20 13:19:25 +00:00
|
|
|
v8::Isolate* isolate = NewIsolateForPagePromotion();
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
|
|
|
|
std::vector<Handle<FixedArray>> handles;
|
|
|
|
heap::SimulateFullSpace(heap->new_space(), &handles);
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting);
|
2016-06-20 13:19:25 +00:00
|
|
|
CHECK_GT(handles.size(), 0u);
|
|
|
|
// First object in handle should be on the first page.
|
|
|
|
Handle<FixedArray> first_object = handles.front();
|
|
|
|
Page* first_page = Page::FromAddress(first_object->address());
|
|
|
|
// To perform a sanity check on live bytes we need to mark the heap.
|
|
|
|
heap::SimulateIncrementalMarking(heap, true);
|
|
|
|
// Sanity check that the page meets the requirements for promotion.
|
|
|
|
const int threshold_bytes =
|
|
|
|
FLAG_page_promotion_threshold * Page::kAllocatableMemory / 100;
|
|
|
|
CHECK_GE(first_page->LiveBytes(), threshold_bytes);
|
|
|
|
|
|
|
|
// Actual checks: The page is in new space first, but is moved to old space
|
|
|
|
// during a full GC.
|
|
|
|
CHECK(heap->new_space()->ContainsSlow(first_page->address()));
|
|
|
|
CHECK(!heap->old_space()->ContainsSlow(first_page->address()));
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
CHECK(!heap->new_space()->ContainsSlow(first_page->address()));
|
|
|
|
CHECK(heap->old_space()->ContainsSlow(first_page->address()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(PagePromotion_NewToNew) {
|
|
|
|
v8::Isolate* isolate = NewIsolateForPagePromotion();
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
|
|
|
|
std::vector<Handle<FixedArray>> handles;
|
|
|
|
heap::SimulateFullSpace(heap->new_space(), &handles);
|
|
|
|
CHECK_GT(handles.size(), 0u);
|
|
|
|
// Last object in handles should definitely be on the last page which does
|
|
|
|
// not contain the age mark.
|
|
|
|
Handle<FixedArray> last_object = handles.back();
|
|
|
|
Page* to_be_promoted_page = Page::FromAddress(last_object->address());
|
|
|
|
CHECK(to_be_promoted_page->Contains(last_object->address()));
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
|
|
|
|
CHECK(to_be_promoted_page->Contains(last_object->address()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(PagePromotion_NewToNewJSArrayBuffer) {
|
|
|
|
// Test makes sure JSArrayBuffer backing stores are still tracked after
|
|
|
|
// new-to-new promotion.
|
|
|
|
v8::Isolate* isolate = NewIsolateForPagePromotion();
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
|
|
|
|
// Fill the current page which potentially contains the age mark.
|
|
|
|
heap::FillCurrentPage(heap->new_space());
|
|
|
|
// Allocate a buffer we would like to check against.
|
|
|
|
Handle<JSArrayBuffer> buffer =
|
|
|
|
i_isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared);
|
2017-01-19 16:23:07 +00:00
|
|
|
CHECK(JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, 100));
|
2016-06-20 13:19:25 +00:00
|
|
|
std::vector<Handle<FixedArray>> handles;
|
|
|
|
// Simulate a full space, filling the interesting page with live objects.
|
|
|
|
heap::SimulateFullSpace(heap->new_space(), &handles);
|
|
|
|
CHECK_GT(handles.size(), 0u);
|
|
|
|
// Last object in handles should definitely be on the last page which does
|
|
|
|
// not contain the age mark.
|
|
|
|
Handle<FixedArray> first_object = handles.front();
|
|
|
|
Page* to_be_promoted_page = Page::FromAddress(first_object->address());
|
|
|
|
CHECK(to_be_promoted_page->Contains(first_object->address()));
|
|
|
|
CHECK(to_be_promoted_page->Contains(buffer->address()));
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address()));
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address()));
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(first_object->address()));
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(buffer->address()));
|
|
|
|
CHECK(to_be_promoted_page->Contains(first_object->address()));
|
|
|
|
CHECK(to_be_promoted_page->Contains(buffer->address()));
|
|
|
|
CHECK(ArrayBufferTracker::IsTracked(*buffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-25 15:33:56 +00:00
|
|
|
UNINITIALIZED_HEAP_TEST(Regress658718) {
|
|
|
|
v8::Isolate* isolate = NewIsolateForPagePromotion(4, 8);
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
heap->delay_sweeper_tasks_for_testing_ = true;
|
|
|
|
heap->new_space()->Grow();
|
|
|
|
{
|
|
|
|
v8::HandleScope inner_handle_scope(isolate);
|
|
|
|
std::vector<Handle<FixedArray>> handles;
|
|
|
|
heap::SimulateFullSpace(heap->new_space(), &handles);
|
|
|
|
CHECK_GT(handles.size(), 0u);
|
|
|
|
// Last object in handles should definitely be on the last page which does
|
|
|
|
// not contain the age mark.
|
|
|
|
Handle<FixedArray> last_object = handles.back();
|
|
|
|
Page* to_be_promoted_page = Page::FromAddress(last_object->address());
|
|
|
|
CHECK(to_be_promoted_page->Contains(last_object->address()));
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
|
|
|
|
heap->CollectGarbage(OLD_SPACE, i::GarbageCollectionReason::kTesting);
|
|
|
|
CHECK(heap->new_space()->ToSpaceContainsSlow(last_object->address()));
|
|
|
|
CHECK(to_be_promoted_page->Contains(last_object->address()));
|
|
|
|
}
|
|
|
|
heap->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting);
|
|
|
|
heap->new_space()->Shrink();
|
|
|
|
heap->memory_allocator()->unmapper()->WaitUntilCompleted();
|
|
|
|
heap->mark_compact_collector()->sweeper().StartSweeperTasks();
|
|
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:19:25 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|