Commit 755f1417 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[test]: Fix platform lifetime in IncrementalMarkingUsingTasks.

Currently MockPlatform has shorter lifetime than the isolate that uses
it. Creating isolate before MockPlatform leads to races in concurrent
tasks that were scheduled before the MockPlatform replaced the default
TestPlatform. This caused issues after landing
https://chromium-review.googlesource.com/c/v8/v8/+/2561198

This CL ensures that MockPlatform is valid throughout the whole
lifetime of the isolate

Bug: v8:11198
Change-Id: I79f82712165d1f1fbe0fe9af68aedf126e54b241
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2562121Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71443}
parent 59a6b7d4
......@@ -71,9 +71,18 @@ class MockPlatform : public TestPlatform {
task_ = std::move(task);
}
void PostNonNestableTask(std::unique_ptr<Task> task) override {
PostTask(std::move(task));
}
void PostDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) override {
task_ = std::move(task);
PostTask(std::move(task));
}
void PostNonNestableDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) override {
PostTask(std::move(task));
}
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
......@@ -81,6 +90,8 @@ class MockPlatform : public TestPlatform {
}
bool IdleTasksEnabled() override { return false; }
bool NonNestableTasksEnabled() const override { return true; }
bool NonNestableDelayedTasksEnabled() const override { return true; }
bool PendingTask() { return task_ != nullptr; }
......@@ -98,24 +109,35 @@ class MockPlatform : public TestPlatform {
v8::Platform* old_platform_;
};
TEST(IncrementalMarkingUsingTasks) {
UNINITIALIZED_TEST(IncrementalMarkingUsingTasks) {
if (!i::FLAG_incremental_marking) return;
FLAG_stress_concurrent_allocation = false; // For SimulateFullSpace.
FLAG_stress_incremental_marking = false;
CcTest::InitializeVM();
MockPlatform platform;
i::heap::SimulateFullSpace(CcTest::heap()->old_space());
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
marking->Stop();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
SafepointScope scope(CcTest::heap());
marking->Start(i::GarbageCollectionReason::kTesting);
}
CHECK(platform.PendingTask());
while (platform.PendingTask()) {
platform.PerformTask();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = CcTest::NewContext(isolate);
v8::Context::Scope context_scope(context);
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
Heap* heap = i_isolate->heap();
i::heap::SimulateFullSpace(heap->old_space());
i::IncrementalMarking* marking = heap->incremental_marking();
marking->Stop();
{
SafepointScope scope(heap);
marking->Start(i::GarbageCollectionReason::kTesting);
}
CHECK(platform.PendingTask());
while (platform.PendingTask()) {
platform.PerformTask();
}
CHECK(marking->IsStopped());
}
CHECK(marking->IsStopped());
isolate->Dispose();
}
} // namespace heap
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment