v8/test/cctest/heap/test-concurrent-marking.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
5.2 KiB
C++
Raw Normal View History

// 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/init/v8.h"
#include "src/heap/concurrent-marking.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
#include "src/heap/mark-compact.h"
#include "src/heap/worklist.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"
namespace v8 {
namespace internal {
namespace heap {
void PublishSegment(ConcurrentMarking::MarkingWorklist* worklist,
HeapObject object) {
for (size_t i = 0; i <= ConcurrentMarking::MarkingWorklist::kSegmentCapacity;
i++) {
worklist->Push(0, object);
}
CHECK(worklist->Pop(0, &object));
}
TEST(ConcurrentMarking) {
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();
}
ConcurrentMarking::MarkingWorklist shared, on_hold;
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
WeakObjects weak_objects;
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
concurrent_marking->ScheduleTasks();
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
concurrent_marking->Stop(
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
delete concurrent_marking;
}
TEST(ConcurrentMarkingReschedule) {
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();
}
ConcurrentMarking::MarkingWorklist shared, on_hold;
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
WeakObjects weak_objects;
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
concurrent_marking->ScheduleTasks();
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
concurrent_marking->Stop(
ConcurrentMarking::StopRequest::COMPLETE_ONGOING_TASKS);
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
concurrent_marking->RescheduleTasksIfNeeded();
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
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();
}
ConcurrentMarking::MarkingWorklist shared, on_hold;
ConcurrentMarking::EmbedderTracingWorklist embedder_objects;
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
WeakObjects weak_objects;
ConcurrentMarking* concurrent_marking = new ConcurrentMarking(
heap, &shared, &on_hold, &weak_objects, &embedder_objects);
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
for (int i = 0; i < 5000; i++)
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
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++)
PublishSegment(&shared, ReadOnlyRoots(heap).undefined_value());
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
concurrent_marking->RescheduleTasksIfNeeded();
concurrent_marking->Stop(
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
delete concurrent_marking;
}
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);
Reland "Introduce ConcurrentMarking::StopRequest API." This is a reland of f4b4109936400c57b79ad015fdcb1fcac979999f. Not expected to be the culprit of the 4 CL revert. Original change's description: > Introduce ConcurrentMarking::StopRequest API. > > This was extracted from https://chromium-review.googlesource.com/c/v8/v8/+/924073/10 > after it became clear that using COMPLETE_TASKS/PREEMPT_TASKS where > it should make sense to doesn't work in practice for now. > > Experimental CLs which led to the above conclusion: > - https://chromium-review.googlesource.com/c/v8/v8/+/924865 > (COMPLETE or CANCEL -- still broken) > - https://chromium-review.googlesource.com/c/v8/v8/+/924866 > (CANCEL only, as before, works) > - https://chromium-review.googlesource.com/c/v8/v8/+/924028 > (CANCEL and PREEMPT -- broken as well) > > Introducing this unittested API allows to reduce the size > of the CLs causing hard-to-diagnose bots-only failures > and fix them individually follow-ups @ > > 1) https://chromium-review.googlesource.com/c/v8/v8/+/924029 > 2) https://chromium-review.googlesource.com/c/v8/v8/+/924031 > 3) https://chromium-review.googlesource.com/c/v8/v8/+/924030 > > Bug: chromium:812178 > Change-Id: Icdac456e9f7874b0c4b321ccdb8898297dad7d73 > Reviewed-on: https://chromium-review.googlesource.com/924867 > Commit-Queue: Gabriel Charette <gab@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#51353} Bug: chromium:812178 Change-Id: Iaa32f9cc6b2fa7004c7fae1f79aa4b00f5f8f34c Reviewed-on: https://chromium-review.googlesource.com/924006 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#51371}
2018-02-19 10:03:12 +00:00
heap->concurrent_marking()->Stop(
ConcurrentMarking::StopRequest::COMPLETE_TASKS_FOR_TESTING);
CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size());
}
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();
}
} // namespace heap
} // namespace internal
} // namespace v8