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-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-07-13 13:03:04 +00:00
|
|
|
|
|
|
|
void PublishSegment(ConcurrentMarking::MarkingWorklist* worklist,
|
|
|
|
HeapObject* object) {
|
|
|
|
for (int i = 0; i <= ConcurrentMarking::MarkingWorklist::kSegmentCapacity;
|
|
|
|
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-07-04 08:50:55 +00:00
|
|
|
ConcurrentMarking::MarkingWorklist shared, bailout;
|
2017-06-26 14:47:36 +00:00
|
|
|
ConcurrentMarking* concurrent_marking =
|
|
|
|
new ConcurrentMarking(heap, &shared, &bailout);
|
2017-07-13 13:03:04 +00:00
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
2017-07-10 09:49:45 +00:00
|
|
|
concurrent_marking->Start();
|
|
|
|
concurrent_marking->EnsureCompleted();
|
2017-03-06 15:19:36 +00:00
|
|
|
delete concurrent_marking;
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:03:04 +00:00
|
|
|
TEST(ConcurrentMarkingWaiting) {
|
|
|
|
if (!i::FLAG_concurrent_marking) return;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
ConcurrentMarking::MarkingWorklist shared, bailout;
|
|
|
|
ConcurrentMarking* concurrent_marking =
|
|
|
|
new ConcurrentMarking(heap, &shared, &bailout);
|
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
|
|
|
concurrent_marking->Start();
|
|
|
|
while (!concurrent_marking->AllTasksWaitingForTesting()) {
|
|
|
|
// Busy wait.
|
|
|
|
}
|
|
|
|
PublishSegment(&shared, heap->undefined_value());
|
|
|
|
concurrent_marking->NotifyWaitingTasks();
|
|
|
|
concurrent_marking->EnsureCompleted();
|
|
|
|
delete concurrent_marking;
|
|
|
|
}
|
|
|
|
|
2017-03-06 15:19:36 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|