From e947712e2c48b35972da887a5c4300147403aa85 Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Mon, 6 Dec 2021 14:13:57 +0100 Subject: [PATCH] [compiler] Also make PrepareInstall deterministic Like https://crrev.com/c/3283074; iterating the unordered set is not deterministic, so sort compile deps before iterating if --predictable is set. Bug: v8:12465,v8:12397 Change-Id: Ia0cc299b197e9c84f4fd3fbc70d592656cf4bd43 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3310911 Auto-Submit: Jakob Gruber Reviewed-by: Leszek Swirski Commit-Queue: Jakob Gruber Cr-Commit-Position: refs/heads/main@{#78249} --- src/compiler/compilation-dependencies.cc | 49 +++++++++++++++++++----- src/compiler/compilation-dependencies.h | 3 ++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/compiler/compilation-dependencies.cc b/src/compiler/compilation-dependencies.cc index 17e5599320..ddd2ad807d 100644 --- a/src/compiler/compilation-dependencies.cc +++ b/src/compiler/compilation-dependencies.cc @@ -1140,16 +1140,7 @@ V8_INLINE void TraceInvalidCompilationDependency( } bool CompilationDependencies::Commit(Handle code) { - for (auto dep : dependencies_) { - if (!dep->IsValid()) { - if (FLAG_trace_compilation_dependencies) { - TraceInvalidCompilationDependency(dep); - } - dependencies_.clear(); - return false; - } - dep->PrepareInstall(); - } + if (!PrepareInstall()) return false; { PendingDependencies pending_deps(zone_); @@ -1200,6 +1191,44 @@ bool CompilationDependencies::Commit(Handle code) { return true; } +bool CompilationDependencies::PrepareInstall() { + if (V8_UNLIKELY(FLAG_predictable)) { + return PrepareInstallPredictable(); + } + + for (auto dep : dependencies_) { + if (!dep->IsValid()) { + if (FLAG_trace_compilation_dependencies) { + TraceInvalidCompilationDependency(dep); + } + dependencies_.clear(); + return false; + } + dep->PrepareInstall(); + } + return true; +} + +bool CompilationDependencies::PrepareInstallPredictable() { + CHECK(FLAG_predictable); + + std::vector deps(dependencies_.begin(), + dependencies_.end()); + std::sort(deps.begin(), deps.end()); + + for (auto dep : deps) { + if (!dep->IsValid()) { + if (FLAG_trace_compilation_dependencies) { + TraceInvalidCompilationDependency(dep); + } + dependencies_.clear(); + return false; + } + dep->PrepareInstall(); + } + return true; +} + namespace { // This function expects to never see a JSProxy. diff --git a/src/compiler/compilation-dependencies.h b/src/compiler/compilation-dependencies.h index 51a1bc4370..aa8ff7b82a 100644 --- a/src/compiler/compilation-dependencies.h +++ b/src/compiler/compilation-dependencies.h @@ -168,6 +168,9 @@ class V8_EXPORT_PRIVATE CompilationDependencies : public ZoneObject { }; private: + bool PrepareInstall(); + bool PrepareInstallPredictable(); + using CompilationDependencySet = ZoneUnorderedSet;