Commit d5c23fda authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Make TestPlatform atomic for TSAN

Change TestPlatform's old_platform_ field to an atomic, so that its
write in the constructor and subsequent reads (that can be cross thread)
are race-free.

Hopefully this fixes the TSAN flakes we've been seeing.

Bug: v8:9054
Change-Id: Ib2b6edd21508ffa18debd6326dd7a100266125f7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3506505
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79385}
parent f29ae51c
...@@ -710,55 +710,56 @@ class TestPlatform : public v8::Platform { ...@@ -710,55 +710,56 @@ class TestPlatform : public v8::Platform {
// v8::Platform implementation. // v8::Platform implementation.
v8::PageAllocator* GetPageAllocator() override { v8::PageAllocator* GetPageAllocator() override {
return old_platform_->GetPageAllocator(); return old_platform()->GetPageAllocator();
} }
void OnCriticalMemoryPressure() override { void OnCriticalMemoryPressure() override {
old_platform_->OnCriticalMemoryPressure(); old_platform()->OnCriticalMemoryPressure();
} }
bool OnCriticalMemoryPressure(size_t length) override { bool OnCriticalMemoryPressure(size_t length) override {
return old_platform_->OnCriticalMemoryPressure(length); return old_platform()->OnCriticalMemoryPressure(length);
} }
int NumberOfWorkerThreads() override { int NumberOfWorkerThreads() override {
return old_platform_->NumberOfWorkerThreads(); return old_platform()->NumberOfWorkerThreads();
} }
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner( std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override { v8::Isolate* isolate) override {
return old_platform_->GetForegroundTaskRunner(isolate); return old_platform()->GetForegroundTaskRunner(isolate);
} }
void CallOnWorkerThread(std::unique_ptr<v8::Task> task) override { void CallOnWorkerThread(std::unique_ptr<v8::Task> task) override {
old_platform_->CallOnWorkerThread(std::move(task)); old_platform()->CallOnWorkerThread(std::move(task));
} }
void CallDelayedOnWorkerThread(std::unique_ptr<v8::Task> task, void CallDelayedOnWorkerThread(std::unique_ptr<v8::Task> task,
double delay_in_seconds) override { double delay_in_seconds) override {
old_platform_->CallDelayedOnWorkerThread(std::move(task), delay_in_seconds); old_platform()->CallDelayedOnWorkerThread(std::move(task),
delay_in_seconds);
} }
std::unique_ptr<v8::JobHandle> PostJob( std::unique_ptr<v8::JobHandle> PostJob(
v8::TaskPriority priority, v8::TaskPriority priority,
std::unique_ptr<v8::JobTask> job_task) override { std::unique_ptr<v8::JobTask> job_task) override {
return old_platform_->PostJob(priority, std::move(job_task)); return old_platform()->PostJob(priority, std::move(job_task));
} }
double MonotonicallyIncreasingTime() override { double MonotonicallyIncreasingTime() override {
return old_platform_->MonotonicallyIncreasingTime(); return old_platform()->MonotonicallyIncreasingTime();
} }
double CurrentClockTimeMillis() override { double CurrentClockTimeMillis() override {
return old_platform_->CurrentClockTimeMillis(); return old_platform()->CurrentClockTimeMillis();
} }
bool IdleTasksEnabled(v8::Isolate* isolate) override { bool IdleTasksEnabled(v8::Isolate* isolate) override {
return old_platform_->IdleTasksEnabled(isolate); return old_platform()->IdleTasksEnabled(isolate);
} }
v8::TracingController* GetTracingController() override { v8::TracingController* GetTracingController() override {
return old_platform_->GetTracingController(); return old_platform()->GetTracingController();
} }
protected: protected:
...@@ -768,7 +769,7 @@ class TestPlatform : public v8::Platform { ...@@ -768,7 +769,7 @@ class TestPlatform : public v8::Platform {
v8::Platform* old_platform() const { return old_platform_; } v8::Platform* old_platform() const { return old_platform_; }
private: private:
v8::Platform* old_platform_; std::atomic<v8::Platform*> old_platform_;
}; };
#if defined(USE_SIMULATOR) #if defined(USE_SIMULATOR)
......
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