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>
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
|
|
|
#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,
|
|
|
|
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
|
|
|
|
|
|
|
ConcurrentMarking::MarkingWorklist shared, bailout, on_hold;
|
2017-08-11 08:37:26 +00:00
|
|
|
WeakObjects weak_objects;
|
2017-06-26 14:47:36 +00:00
|
|
|
ConcurrentMarking* concurrent_marking =
|
2017-10-10 10:45:54 +00:00
|
|
|
new ConcurrentMarking(heap, &shared, &bailout, &on_hold, &weak_objects);
|
2017-07-17 11:00:33 +00:00
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
|
|
|
concurrent_marking->ScheduleTasks();
|
2017-10-09 15:13:41 +00:00
|
|
|
concurrent_marking->WaitForTasks();
|
2017-07-17 11:00:33 +00:00
|
|
|
concurrent_marking->EnsureCompleted();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-10-10 10:45:54 +00:00
|
|
|
ConcurrentMarking::MarkingWorklist shared, bailout, on_hold;
|
2017-08-11 08:37:26 +00:00
|
|
|
WeakObjects weak_objects;
|
2017-07-17 11:00:33 +00:00
|
|
|
ConcurrentMarking* concurrent_marking =
|
2017-10-10 10:45:54 +00:00
|
|
|
new ConcurrentMarking(heap, &shared, &bailout, &on_hold, &weak_objects);
|
2017-07-17 11:00:33 +00:00
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
|
|
|
concurrent_marking->ScheduleTasks();
|
2017-10-09 15:13:41 +00:00
|
|
|
concurrent_marking->WaitForTasks();
|
2017-07-17 11:00:33 +00:00
|
|
|
concurrent_marking->EnsureCompleted();
|
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
|
|
|
concurrent_marking->RescheduleTasksIfNeeded();
|
2017-10-09 15:13:41 +00:00
|
|
|
concurrent_marking->WaitForTasks();
|
2017-07-13 13:03:04 +00:00
|
|
|
concurrent_marking->EnsureCompleted();
|
|
|
|
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);
|
2017-10-09 15:13:41 +00:00
|
|
|
heap->concurrent_marking()->WaitForTasks();
|
2017-10-09 11:23:59 +00:00
|
|
|
heap->concurrent_marking()->EnsureCompleted();
|
|
|
|
CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size());
|
|
|
|
}
|
|
|
|
|
2017-08-11 10:04:47 +00:00
|
|
|
} // namespace heap
|
2017-03-06 15:19:36 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|