2017-03-06 15:19:36 +00:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2017-03-06 15:19:36 +00:00
|
|
|
|
|
|
|
#include "src/heap/concurrent-marking.h"
|
|
|
|
#include "src/heap/heap-inl.h"
|
|
|
|
#include "src/heap/heap.h"
|
2017-08-11 08:37:26 +00:00
|
|
|
#include "src/heap/mark-compact.h"
|
2017-06-26 14:47:36 +00:00
|
|
|
#include "src/heap/worklist.h"
|
2017-03-06 15:19:36 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/heap/heap-utils.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-08-11 10:04:47 +00:00
|
|
|
namespace heap {
|
2017-07-17 11:00:33 +00:00
|
|
|
|
|
|
|
void PublishSegment(ConcurrentMarking::MarkingWorklist* worklist,
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject object) {
|
2017-08-24 17:44:18 +00:00
|
|
|
for (size_t i = 0; i <= ConcurrentMarking::MarkingWorklist::kSegmentCapacity;
|
2017-07-17 11:00:33 +00:00
|
|
|
i++) {
|
|
|
|
worklist->Push(0, object);
|
|
|
|
}
|
|
|
|
CHECK(worklist->Pop(0, &object));
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:19:36 +00:00
|
|
|
TEST(ConcurrentMarking) {
|
2017-04-10 14:22:31 +00:00
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
2017-03-06 15:19:36 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
2017-10-05 14:16:30 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
if (!heap->incremental_marking()->IsStopped()) return;
|
2017-10-09 12:33:53 +00:00
|
|
|
MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
2017-10-10 10:45:54 +00:00
|
|
|
|
2019-01-17 16:03:15 +00:00
|
|
|
ConcurrentMarking::MarkingWorklist shared, on_hold;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
|
2017-08-11 08:37:26 +00:00
|
|
|
WeakObjects weak_objects;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
|
2019-01-17 16:03:15 +00:00
|
|
|
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
|
2018-07-04 09:10:05 +00:00
|
|
|
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
|
2017-07-17 11:00:33 +00:00
|
|
|
concurrent_marking->ScheduleTasks();
|
2018-02-19 10:03:12 +00:00
|
|
|
concurrent_marking->Stop(
|
|
|
|
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
|
2017-07-17 11:00:33 +00:00
|
|
|
delete concurrent_marking;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConcurrentMarkingReschedule) {
|
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
2017-10-05 14:16:30 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
if (!heap->incremental_marking()->IsStopped()) return;
|
2017-10-09 12:33:53 +00:00
|
|
|
MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
|
2019-01-17 16:03:15 +00:00
|
|
|
ConcurrentMarking::MarkingWorklist shared, on_hold;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
|
2017-08-11 08:37:26 +00:00
|
|
|
WeakObjects weak_objects;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
|
2019-01-17 16:03:15 +00:00
|
|
|
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
|
2018-07-04 09:10:05 +00:00
|
|
|
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
|
2017-07-17 11:00:33 +00:00
|
|
|
concurrent_marking->ScheduleTasks();
|
2018-02-19 10:03:12 +00:00
|
|
|
concurrent_marking->Stop(
|
|
|
|
ConcurrentMarking::StopRequest::COMPLETE_ONGOING_TASKS);
|
2018-07-04 09:10:05 +00:00
|
|
|
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
|
2017-07-17 11:00:33 +00:00
|
|
|
concurrent_marking->RescheduleTasksIfNeeded();
|
2018-02-19 10:03:12 +00:00
|
|
|
concurrent_marking->Stop(
|
|
|
|
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
|
|
|
|
delete concurrent_marking;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConcurrentMarkingPreemptAndReschedule) {
|
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
if (!heap->incremental_marking()->IsStopped()) return;
|
|
|
|
MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
|
2019-01-17 16:03:15 +00:00
|
|
|
ConcurrentMarking::MarkingWorklist shared, on_hold;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
|
2018-02-19 10:03:12 +00:00
|
|
|
WeakObjects weak_objects;
|
2018-09-19 11:42:55 +00:00
|
|
|
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
|
2019-01-17 16:03:15 +00:00
|
|
|
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
|
2018-02-19 10:03:12 +00:00
|
|
|
for (int i = 0; i < 5000; i++)
|
2018-07-04 09:10:05 +00:00
|
|
|
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
|
2018-02-19 10:03:12 +00:00
|
|
|
concurrent_marking->ScheduleTasks();
|
|
|
|
concurrent_marking->Stop(ConcurrentMarking::StopRequest::PREEMPT_TASKS);
|
|
|
|
for (int i = 0; i < 5000; i++)
|
2018-07-04 09:10:05 +00:00
|
|
|
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
|
2018-02-19 10:03:12 +00:00
|
|
|
concurrent_marking->RescheduleTasksIfNeeded();
|
|
|
|
concurrent_marking->Stop(
|
|
|
|
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
|
2017-07-13 13:03:04 +00:00
|
|
|
delete concurrent_marking;
|
|
|
|
}
|
|
|
|
|
2017-10-09 11:23:59 +00:00
|
|
|
TEST(ConcurrentMarkingMarkedBytes) {
|
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
HandleScope sc(isolate);
|
|
|
|
Handle<FixedArray> root = isolate->factory()->NewFixedArray(1000000);
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
if (!heap->incremental_marking()->IsStopped()) return;
|
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
2018-02-19 10:03:12 +00:00
|
|
|
heap->concurrent_marking()->Stop(
|
|
|
|
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
|
2017-10-09 11:23:59 +00:00
|
|
|
CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size());
|
|
|
|
}
|
|
|
|
|
2018-06-13 14:38:59 +00:00
|
|
|
UNINITIALIZED_TEST(ConcurrentMarkingStoppedOnTeardown) {
|
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
|
|
|
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
|
|
|
|
{
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
Factory* factory = i_isolate->factory();
|
|
|
|
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
|
|
|
|
for (int i = 0; i < 10000; i++) {
|
|
|
|
factory->NewJSWeakMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:04:47 +00:00
|
|
|
} // namespace heap
|
2017-03-06 15:19:36 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|